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

就没问题了

相关推荐
Direction_Wind8 小时前
Flinksql bug: Heartbeat of TaskManager with id container_XXX timed out.
大数据·flink·bug
不断提高1 天前
多种适用于 MCU 固件的 OTA 升级方案
单片机·mcu·ota升级·双分区升级
万花丛中一抹绿2 天前
服务器硬件电路设计之 I2C 问答(五):I2C 总线数据传输方向如何确定、信号线上的串联电阻有什么作用?
服务器·i2c·服务器硬件研发
AIBigModel3 天前
智能情趣设备、爆 bug:可被远程操控。。。
网络·安全·bug
Direction_Wind3 天前
flinksql bug: Received resultset tuples, but no field str
bug
远瞻。3 天前
【bug】diff-gaussian-rasterization Windows下编译 bug 解决
windows·bug
中草药z3 天前
【测试】Bug+设计测试用例
功能测试·测试工具·测试用例·bug·压力测试·测试
我又来搬代码了4 天前
【Android】【bug】Json解析错误Expected BEGIN_OBJECT but was STRING...
android·json·bug
葵野寺4 天前
【软件测试】BUG篇 — 详解
bug·测试
小林学习中5 天前
三子棋装置(电赛24E题)K230/STM32全开源
stm32·mcu