Skip to content
chuck todd edited this page Jan 20, 2019 · 6 revisions

Debugging I2C

With the release of Arduino-ESP32 V1.0.1 the I2C subsystem contains code to exhaustively report communication errors.

  • Basic debugging can be enable by setting the CORE DEBUG LEVEL at or above ERROR. All errors will be directed the the DEBUG OUTPUT normally connected to Serial().
  • Enhanced debugging can be used to generate specified information at specific positions during the i2c communication sequence. Increase CORE DEBUG LEVEL to DEBUG

Enable Debug Buffer

The Enhanced debug features are enabled by uncommenting the \\#define ENABLE_I2C_DEBUG_BUFFER at line 45 of esp32-hal-i2c.c.

  • When Arduino-Esp32 is installed in Windows with Arduino Boards Manager, esp32-hal-i2c.c can be found in: C:\Users\{user}\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.1\cores\esp32\
  • When Arduino-Esp32 Development version is installed from GitHub, esp32-hal-i2c.c can be found in: {arduino Sketch}\hardware\espressif\esp32\cores\esp32\
//#define ENABLE_I2C_DEBUG_BUFFER

Change it to:

#define ENABLE_I2C_DEBUG_BUFFER

and recompile/upload the resulting code to your ESP32.

Enabling this #define will consume an additional 2570 bytes of RAM and include a commensurate amount of code FLASH. If you see the message "Debug Buffer not Enabled" in your console log I would suggest you un-comment the line and regenerate the error. Additional information will be supplied on the log console.

Manually controlled Debugging

Manual logging of the i2c control data buffers can be accomplished by using the debug control function of Wire():

    uint32_t setDebugFlags( uint32_t setBits, uint32_t resetBits);

setBits, and resetBits manually cause output of the control structures to the log console. They are bit fields that enable/disable the reporting of individual control structures during specific phases of the i2c communications sequence. The 32bit values are divided into four 8bit fields. Currently only five bits are defined. If an error is detected during normal operations, the relevant control structure will bit added to the log irrespective of the current debug flags.

  • bit 0 causes DumpI2c to execute header information about current communications event, and the dataQueue elements showing the logical i2c transaction commands
  • bit 1 causes DumpInts to execute Actual sequence of interrupts handled during last communications event, cleared on entry into ProcQueue().
  • bit 2 causes DumpCmdqueue to execute The last block of commands to the i2c peripheral.
  • bit 3 causes DumpStatus to execute A descriptive display of the 32bit i2c peripheral status word.
  • bit 4 causes DumpFifo to execute A buffer listing the sequence of data added to the txFifo of the i2c peripheral.
Clone this wiki locally