problem to catch I2C interrups when using MCP23017 and adafruit SSD1306

gomez9656
Posts: 18
Joined: Mon Mar 14, 2022 7:48 pm

problem to catch I2C interrups when using MCP23017 and adafruit SSD1306

Postby gomez9656 » Mon Jul 31, 2023 6:35 pm

Hello, there Espressif team!

I'm working with an ESP32 in Platformio with the Arduino framework and the project works very well and as intended.

The project uses 4 rotatory encoders KY040 connected to GPIO expander MCP23017 though I2C and these encoders control some variables that are printed in two adafruit SSD1306 displays.

This configuration works without problem if the user moves the encoder at an average speed. The problem appears when the user rotates REALLY fast the encoder. After some debugging, I noticed the MCP interrupts are not getting triggered because the i2c bus is blocked, because the displays are printing something at that moment.

The libraries we are using are https://github.com/maxgerhardt/rotary-e ... r-mcp23017 to control the encoders through MCP, and https://github.com/adafruit/Adafruit_SSD1306 for the displays.

I would like to be able to detect all the MCP interrupts. What should be the best approach for this?

Thanks a lot in advance :)

lbernstone
Posts: 792
Joined: Mon Jul 22, 2019 3:20 pm

Re: problem to catch I2C interrups when using MCP23017 and adafruit SSD1306

Postby lbernstone » Mon Jul 31, 2023 10:20 pm

The simplest way: put them on separate i2c buses.
A possible other simple way: Use 400KHz for your i2c frequency. Your devices should both work at this rate, but I can't guarantee you get the results you would hope for.
True fix: Decouple the interrupts from your processing. When you get an interrupt, you increment a counter, and then whatever you would do with that result is handled in a separate task, which happens at a realistic frequency. Refresh your screen at a realistic frequency; 0.25 seconds is quite adequate for human response.

gomez9656
Posts: 18
Joined: Mon Mar 14, 2022 7:48 pm

Re: problem to catch I2C interrups when using MCP23017 and adafruit SSD1306

Postby gomez9656 » Mon Jul 31, 2023 10:33 pm

Thanks for the quick reply!

Refresh the screen at a realistic frequency is something I can implement.

Unfortunately, the hardware is already done and they are on the same bus :(

I tested the I2C at 1MHz and that helped catch interrupts at a faster speed than before.

The interrupt is only used to increment a counter and update a flag. In the while loop, I check for the flag, if it is true, then I print the display. Can you give me an overview of how to trigger the task to print the display when that flag is true? I suppose FreeRTOS comes in place here?

Who is online

Users browsing this forum: Basalt and 93 guests