

The members of TwoWire class are private, not accessible by user. After a master requestFrom() I'd expect the number of actually requested and transmitted bytes in. There seem to exist two buffers, one in TwoWire::txBuffer and one as twi_txBuffer and both with. If somebody wants to write test programs for AVR controllers: Any reliable library documentation, analysis or test results? Then the slave could reset its data-available flag after every multi-byte transmission.Īll that seems to be library specific. What is returned from a slave.write()? If the number of requested bytes is returned then the slave could distinguish a one-byte "available" request from a multi-byte data transfer. It also makes sense as not leaving room for possibly time consuming data retrieval on the slave.

This suggests to me that only one call per transmission occurs. Is the callback function called once for each transmission or eventually repeatedly until all requested bytes have been sent?ĪFAIR the receive buffer is filled with garbage if the slave does not send enough bytes. What happens if the slave always provides the full-size record with the first byte containing the valid byte count, and the master only asks for one byte? Requesting a fixed size package of data is what the I2C bus is about.įor example if the Master does request the amount but not the data itself. That is not so bad, even though perhaps 1% CPU time is needed for Serial/UART communication. Doing that 10 times per second for 10 Slave boards might use 50% of the Master CPU time.

The simplest solution is to always request 32 bytes and put the amount in the first byte. To implement this on a basic Arduino board can go wrong in so many ways, but so does every other solution that I can think of. In a multitasking system, this would make sense with queues and mutex. For example if the Master does request the amount but not the data itself. This has of course many consequences and many things can go wrong. The loop() should also check if the nextIsData is true, because then it may not fill the buffer with new data. When the buffer is filled with new data in the loop(), the interrupts have to be turned off (for a very short time) to avoid disturbing this mechanism.

The Master does another request, the nextIsData is true, Slave returns the all the data, and sets nextIsData to false. The Master does a request, the nextIsData is false, Slave returns amount in a single bytes. I think a single bool variable is enough. The Slave sketch must deal with it, that means the Slave sketch must keep track of the requests.
