Problems with I2C debugging

1. I2C can read data, but did not receive corresponding response

 Missing ACK/NCK, look closely at the waveform, the waveform changes in a short period of time as shown below:

 

 Searching for information did not find a solution, so record it first and modify it later.

The root cause: the response timing program is wrong, after writing the address, when SDA is high, set SDA to input mode at the same time!

code show as below:

Error demonstration:

i2cstart();
write_byte(0xa0);
SCL=1;
SDA=1;
delay(30);
SCL=0;
delay(30);
SDAC=1;//SDA设置输入模式
while((unsigned char)(SDA)!=0)
{
   i++;
   if(i>=5000)
   {
     return 0;


   }

}
SDAC=0;
SCL=0;

correct procedure

i2cstart();
write_byte(0xa0);
SCL=1;
SDA=1;
SDAC=1;//SDA设置输入模式
delay(30);
SCL=0;
delay(30);
while((unsigned char)(SDA)!=0)
{
   i++;
   if(i>=5000)
   {
     return 0;


   }

}
SDAC=0;
SCL=0;

After the modification, it was successfully resolved.

 

Guess you like

Origin blog.csdn.net/weixin_58125062/article/details/130068297