0
\$\begingroup\$

How would one go about handling errors in AVR interfaces that do not specifically provide any acknowledgement scheme?

For example, I have an I2C temperature sensor which I poll every 1 hour. So every hour my AVR sends a TWI start condition to the sensor and gets the temperature at the end of it.Now tet's say for some reason the sensor does not respond. Maybe it's been taken out, burned out etc. So how can I check for such in my code and inform the user?

Right now I am using the polling method. Infinite loop till TWINT is set in the TWCR register

while ((TWCR & (1<<TWINT)) == 0){};
return TWDR;
\$\endgroup\$
1
  • 1
    \$\begingroup\$ well the I2C standard considers an acknowledge mechanism, check your AVR datasheet and see what the peripheral does about that. \$\endgroup\$ Aug 9, 2014 at 14:09

1 Answer 1

1
\$\begingroup\$

The I2C module provides a way to identify erros, once you send, let's say a START condition or whatever you have to verify the TWSR register (TWI Status register) and it should match the state you are expecting (e.g. Aknowledge from slave). There is a flow diagram for each working mode showcasing the different status values.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.