i2c slave support
Posted: Sun Jan 29, 2017 4:37 pm
Needing i2c slave support for my Wi-Fi/mqtt heat-pump project, I couldn't find it and now have it implemented. From my search efforts others seem to need it too. If so, how to proceed?
It is based on the Arduino twi.c code and simulates the Atmega 328p hw. I have not bothered about the existing master support but guess it still works as before.
The design is based on interrupts with the advantage of background processing. This is good when combining with mqtt and perhaps even OTA update support. The drawback is the exposure to the ESP's periodical interrupt delays.
To cope with the latter, it requires the master to support clock stretching. Also, a timeout is implemented to release a hung bus when the delays have forced the ESP out of sync. Still, when communicating with a Trinket Pro as a master, the bus may get hung by the master. I am for the moment hoping the bug is in the Adafruit implementation or the atmega hw. Long-term testing of the heat pump is in the works. Then we'll know.
To support Wire-library callbacks in flash, a prio-2 user task is used. I have done a file search and it seems to be free. Prio-0 doesn't work and prio-1 is taken by the loop task. If required, the task may be shared with other HALs.
The release-bus timeout is implemented using a one-shot timer.
I am running at around 14kHz. Due to the interrupt delays, 100kHz seems NOT achievable.
It is based on the Arduino twi.c code and simulates the Atmega 328p hw. I have not bothered about the existing master support but guess it still works as before.
The design is based on interrupts with the advantage of background processing. This is good when combining with mqtt and perhaps even OTA update support. The drawback is the exposure to the ESP's periodical interrupt delays.
To cope with the latter, it requires the master to support clock stretching. Also, a timeout is implemented to release a hung bus when the delays have forced the ESP out of sync. Still, when communicating with a Trinket Pro as a master, the bus may get hung by the master. I am for the moment hoping the bug is in the Adafruit implementation or the atmega hw. Long-term testing of the heat pump is in the works. Then we'll know.
To support Wire-library callbacks in flash, a prio-2 user task is used. I have done a file search and it seems to be free. Prio-0 doesn't work and prio-1 is taken by the loop task. If required, the task may be shared with other HALs.
The release-bus timeout is implemented using a one-shot timer.
I am running at around 14kHz. Due to the interrupt delays, 100kHz seems NOT achievable.