AVR I2C trouble

僤鯓⒐⒋嵵緔 提交于 2020-01-16 08:35:31

问题


I am trying to communicate using I2C with AT90CAN128, But it is not going further than following while loop:

while(!(TWCR & (1<<TWINT)));

It remains in the while loop. According to me, it is not able to set TWINT flag.

void TWI_start(void)
{
  TWCR= (1<<TWINT)|(1<<TWSTA)|(1<<TWEN); 
  while(!(TWCR & (1<<TWINT)));`enter code here`
  while((TWSR & 0xF8)!= 0x08); 
}

Any suggestions?


回答1:


Probably a hardware problem.

The TWI Master tries to assert SDA and SCL and checks if both SDA and SCL are at GND. Check the connections and the value of your pull-up resistors. If the controller fails to pull the lines down, the START condition never gets registered and TWINT will never get set.



来源:https://stackoverflow.com/questions/59653754/avr-i2c-trouble

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!