| 
				打卡等级:初来乍到打卡总天数:4最近打卡:2025-07-12 08:20:18  已绑定手机注册会员 
 
 
	积分109 
 | 
 
| Start()是老的Ai8051U的I2C库函数 /////////////////////////////////////////////////////////////////////////
 void Start()
 {
 I2CMSCR = 0x01;                         //发送START命令
 Wait();
 }
 其中
 void Wait()
 {
 while (!(I2CMSST & 0x40));
 I2CMSST &= ~0x40;
 }
 /////////////////////////////////////////////////////////////////////
 I2C_MasterStart()是使用AiCube生成的库函数
 
 void I2C_MasterStart(void)
 {
 I2C_Start();                        //触发主机模式起始命令
 I2C_MasterWait();                   //等待命令完成
 }
 
 其中
 #define I2CCMD_START                    1
 #define BIT_LN                  0x0f
 #define I2CMSCR_MSCMD_MSK               (BIT_LN)
 #define MODIFY_REG(r, clr, set) ((r) = (((r) & ~(clr)) | ((set) & (clr))))
 #define I2C_SetMasterCommand(n)         MODIFY_REG(I2CMSCR, I2CMSCR_MSCMD_MSK, ((n) << 0))
 #define I2C_Start()                     I2C_SetMasterCommand(I2CCMD_START)
 所以I2C_Start()应该也是I2CMSCR = 0x01;
 ///////////////////////////////////////////////////////////////////////////////////
 而
 
 void I2C_MasterWait(void)
 {
 while (!I2C_CheckMasterFlag());     //等待完成标志
 I2C_ClearMasterFlag();              //清除完成标志
 I2C_Idle();                         //恢复IDLE状态
 }
 
 其实跟Wait()是一样的
 ////////////////////////////////////////////////////////////////////////////////
 用I2C_MasterStart()替换Start()后,其他都没变,编译结果都是 0 Error(s), 0 Warning(s). 但就是运行结果不正确。
 
 | 
 |