【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;
}

就没问题了

相关推荐
Java知识库10 天前
MySQL RC隔离级别惊现间隙锁:是bug吗?
数据库·mysql·bug
安卓机器10 天前
rom定制系列------红米note11 5G版 MTK芯片强解bl锁修复bug 官方系统 面具root批量线刷版
5g·bug
剽悍一小兔10 天前
一个小BUG引发的对Mybatis-Plus的模糊查询的思考
bug·mybatis
CoreMaker-lab11 天前
RA4M2开发IOT(6)----涂鸦模组快速上云
mcu·物联网·ra4m2·e2studio·r7fa4m2ad3cfl·瑞萨ra·涂鸦cbu
Jason_zhao_MR12 天前
多协议物联网关的方案测试-基于米尔全志T536开发板
arm开发·嵌入式硬件·mcu·物联网·嵌入式
Gazer_S12 天前
【前端隐蔽 Bug 深度剖析:SVG 组件复用中的 ID 冲突陷阱】
前端·bug
dujunqiu13 天前
S32DS上进行S32K328的时钟配置,LPUART时钟配置步骤详解
单片机·mcu
今日待办13 天前
Arduino Nano 33 BLE Sense Rev 2开发板使用指南之【外设开发】
c语言·单片机·嵌入式硬件·mcu
电手13 天前
Win11用户尽快删除更新!微软6月又推Bug
microsoft·bug
穆易青14 天前
2025.06.17【BUG】|多样品VCF文件合并技巧及注意事项(以bcftools为例)
bug