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
problem to catch I2C interrups when using MCP23017 and adafruit SSD1306
-
- Posts: 826
- Joined: Mon Jul 22, 2019 3:20 pm
Re: problem to catch I2C interrups when using MCP23017 and adafruit SSD1306
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.
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.
Re: problem to catch I2C interrups when using MCP23017 and adafruit SSD1306
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?
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: No registered users and 61 guests