Page 1 of 1

Detect errors in I2C readings

Posted: Fri Aug 12, 2022 7:09 pm
by MauroDiam
Hi guys, is there a way to detect than there were errors when the method

Code: Select all

readfrom_mem()
from the class machine.SoftI2C is used with a ESP32 board. Does that method raise an exception if that occurs?

Re: Detect errors in I2C readings

Posted: Fri Aug 12, 2022 7:28 pm
by Roberthh
The I2C transport mechanisms has no error checks for the transmitted data. So if the target device does not implement some kind of error detection mechanism like CRC, you could at least at least try to check the data for plausibility.

Re: Detect errors in I2C readings

Posted: Fri Aug 12, 2022 8:00 pm
by MauroDiam
Hi @Roberthh, i'm reading the I2C protocol and now i see what you mean, so i'll have to study deeper the sensor datasheet to verify if it implements some errors correction code. But i still have a doubt, what happened if a NACK bit is transmitted by the master (esp32) during the execution of the method readfrom_mem()?

Re: Detect errors in I2C readings

Posted: Fri Aug 12, 2022 8:18 pm
by Roberthh
If a NAK bit is transmitted then the python gets and I/O error exception.
Edit: It depends.
If NAK is received after the address bit, then an MP_NODEV error is flagged.
If NAK is received after sending a data byte, the transmission is stopped.