Chat here about code rewrites, mods, etc... with respect to the github project

Moderator: igrr

User avatar
By bjoham
#61737 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.
User avatar
By Ian Sparkes
#61802 Nice work!

How to proceed? Well, if you have some code, why not make a pull request on the GitHub repo? It relates to issue I see you have already commented there.

If you're not ready to make a pull request to the main repo, you can publish a fork so that people can help you get to being ready. Having a look for your profile, I see you joined GitHub yesterday, so I guess you're already doing this... ;)

If you publish, others can start to look over the code and help improve it to increase the transfer rate and stability, and you'd give back something to the great ESP community...
User avatar
By bjoham
#61870 @Ian: I'll do some cleanup and publish a fork aiming for a pull request.

@judge: Yes, it does. I've done most of the tests using a Trinket Pro 5V as a "heat-pump simulator" (using a level shifter of course). Actually, I did some code changes. Don't remember if those are related to clock stretching. I'll do a pull request on those, I guess. Both the Adafruit and the vanilla trees (there are minute differences without reason in my opinion).