Arduino Wire.h doesn’t look like it will cut it :(

No cool images or videos today.  Tonight I wallow in the realization that I will probably need to roll my own I2C library to get any real reliable synch between the Pi and the Trinkets.

Basically, it comes down to this:

Wire.h has it’s own callbacks (read interrupt… apparently) for data arrived and data requested (a slave cannot send without the master requesting data from it).  By the time the callback is called, Wire.h already has everything stored in its own buffer.  I can request this 1 byte at a time, but if I were to do this and do any real processing with that byte – such as sending it to the speech board and waiting for that phoneme to be spoken – I either need to get back into the main loop or write everything for speaking inside the callback.  No other interrupt-based code can be called at this time, and so I instead need to copy everything out of the buffer and into a local buffer.  Once I do that, the callback function would return. Unfortunately, my processing could be much slower than the time it takes to get the next byte array from the master, and suddenly the Trinket is in a battle to keep up that the more data is sent and the better chance it will eventually run out of space and lose.

The flip side would be that I use the I2C protocol the way I believe it was intended to be used and keep the line data line pulled down until I am ready to process more data. Actually, the more I think about it, this probably won’t work either as it will prevent any of the other I2C slaves from being able to receive data during this time.  All I know at the moment is that it seems that whatever I want to do seems like I’m either duplicating the code in the Wire.h library as I roll my own buffers and try and skit the interrupt handling, or I need to access I2C on a lower level than Wire.h is prepared to allow me access to.  Either way, it’s not looking good for Wire.h…

Leave a Reply

Your email address will not be published. Required fields are marked *