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

就没问题了

相关推荐
jingshaoqi_ccc14 小时前
采用GD32F103C8T6开发板的硬件I2C通信实现ADS1115的模拟电压读取(附源码下载)
硬件i2c·i2c·ads1115·gd32f103c8t6
奶茶精Gaaa19 小时前
测试能力提升--Bug分析能力
bug
A星空1232 天前
一、Linux嵌入式的I2C驱动开发
linux·c++·驱动开发·i2c
LJianK12 天前
idea自带的数据库修改默认值有bug
bug
BBNbQKHXygfU4 天前
基于遗传算法优化BP神经网络的时间序列预测探索
mcu
这个软件需要设计一下4 天前
ninedata安装磁盘不足问题解决
运维·bug
想放学的刺客4 天前
单片机嵌入式试题(第30期)全局变量“满天飞“!!!局限性和影响有哪些,什么情况下才不得不使用?
单片机·嵌入式硬件·mcu·物联网·51单片机
热爱生活的五柒4 天前
cc-switch安装方法、介绍及遇到的bug
bug·cc-switch
Greenland_124 天前
Android 混淆与混淆后bug日志问题定位
android·bug
网易独家音乐人Mike Zhou4 天前
【RealMCU】瑞昱官方LOG信息保存及解析,DebugAnalyzer自动化接收脚本(不需要用到ROM.trace文件)
单片机·mcu·物联网·自动化·嵌入式·iot·瑞昱