【MCU】CH591用软件 I2C 出现的 bug

计算问题

写软件 I2C 时不支持

c 复制代码
byte |= (0x80 >> i);

详细:

c 复制代码
/**
 * @brief Receive one byte using I2C
 * @param XACK
 * @retval Byte
 */
uint8_t SW_I2C_ReceiveByte(uint8_t XACK)
{
	SW_I2C_SDA_SetInput();
	uint8_t byte = 0x00;
	for (uint8_t i = 0; i < 8; i++)
	{
		SW_I2C_Delay();
		SW_I2C_SCL_WriteBit(1);
		if (SW_I2C_SDA_ReadBit() == 1)
		{
			byte |= (0x80 >> i);
		}
		SW_I2C_Delay();
		SW_I2C_SCL_WriteBit(0);
		SW_I2C_Delay();
	}
	SW_I2C_SDA_SetOutput();
	// transmit ACK
	SW_I2C_SDA_WriteBit(XACK);
	SW_I2C_Delay();
	SW_I2C_SCL_WriteBit(1);
	SW_I2C_Delay();
	SW_I2C_SCL_WriteBit(0);
	// release SDA
	SW_I2C_SDA_WriteBit(1);
	SW_I2C_Delay();
	return byte;
}

如果改成

c 复制代码
/**
 * @brief Receive one byte using I2C
 * @param XACK
 * @retval Byte
 */
uint8_t SW_I2C_ReceiveByte(uint8_t XACK)
{
	SW_I2C_SDA_SetInput();
	uint8_t byte = 0x00;
	for (uint8_t i = 0; i < 8; i++)
	{
		byte<<=1;
		SW_I2C_Delay();
		SW_I2C_SCL_WriteBit(1);
		if (SW_I2C_SDA_ReadBit() == 1)
		{
			byte |= 0x01;
		}
		SW_I2C_Delay();
		SW_I2C_SCL_WriteBit(0);
		SW_I2C_Delay();
	}
	SW_I2C_SDA_SetOutput();
	// transmit ACK
	SW_I2C_SDA_WriteBit(XACK);
	SW_I2C_Delay();
	SW_I2C_SCL_WriteBit(1);
	SW_I2C_Delay();
	SW_I2C_SCL_WriteBit(0);
	// release SDA
	SW_I2C_SDA_WriteBit(1);
	SW_I2C_Delay();
	return byte;
}

就没问题了

相关推荐
初圣魔门首席弟子1 天前
c++ bug 记录(merge函数调用时错误地传入了vector对象而非迭代器。)
java·c++·bug
Qiuner2 天前
历劫波,明真我——Debug Commune
ai·开源·bug·debug·信息差·信息·交流
OSS_ECAL2 天前
以下將介紹TLE493D-P2B6的概要,以及針對TLE493D-P2B6提供的OSS-ECAL
oss·嵌入式软件·i2c·电子元件·3d霍爾
蜀黍@猿2 天前
【GD32】软、硬件I2C对比
单片机·嵌入式硬件·mcu
蜀黍@猿2 天前
【GD32】MCU选型参考标准
arm开发·单片机·mcu
川石课堂软件测试3 天前
什么是BUG,你对BUG的了解有多少?
android·linux·服务器·python·功能测试·bug·安全性测试
蜀黍@猿3 天前
【GD32】软件I2C
单片机·嵌入式硬件·mcu
仰望星空的凡人4 天前
【BUG排查】基于RH850F1KMS1的主控出现系统中断错误,调试FEIC的值为0x11
单片机·bug·rh850·renesas
Vanranrr4 天前
Git Commit Message 最佳实践:从一次指针Bug说起
git·bug
R6bandito_4 天前
STM32中printf的重定向详解
开发语言·经验分享·stm32·单片机·嵌入式硬件·mcu