问题
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