1.1.1 Example: Random I2C NACKs
An I2C sensor randomly fails to communicate (NACK) with the microcontroller.
Some possible causes:
- The sensor to motherboard connection is damaged or not fully seated (Mechanical Layer)
- The bus capacitance is too high, or the pull-up resistors are too weak (Electrical Layer)
- The sensor is busy and is unable to respond (Application Layer)
Out of the possible causes listed, some of these can be eliminated by knowing the specifics of the application. For instance, if the sensor is soldered to the same Printed Circuit Board (PCB), it cannot be a connector issue. Additionally, since the behavior appears random, it is unlikely to be a soldering defect, which is expected to occur consistently - with except for temperature-dependent metal expansion/contraction.
For the Electrical Layer possibility, an oscilloscope can verify it. When properly implemented, I2C will have sharp fall times and relatively sharp rise times. If the waveforms appear very rounded, this suggests too much capacitance or the pull-ups are too weak, discussed further in Slew Rates chapter.
For the Application Layer possibility, eliminate this by seeing if the data sheet or errata specifies any timing delays during communication. It is also possible, albeit unlikely, that the original manufacturer has an undocumented device defect.