AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
![]() ![]() So, what's the right way to do this? How do I handle/enqueue fast incoming i2c messages and process them all without dropping data?Īssume I can process messages faster than my rx buffer will fill up, messages will just come in bursts, so no need to care about overflows necessarily. or after requestFrom(address, numBytes) Wire has an internal rx buffer, so I'd have thought I could just call Wire.available() and Wire.read() from inside my loop, but the implementation of Wire.cpp states: // must be called in: Wire. So instead I can create a buffer, and push to it from inside the ISR, and then read from loop() but that's even more susceptible to race conditions - unless I disable interrupts whilst I take a local copy of the buffer - but with interrupts off I'll miss messages. No installation required This problem is trivial: if the code has a bug then why worry about a unwanted timeout anyway However, when the Wire.readBytes () would be used in the onReceive handler of a Target (Slave), then a timeout (caused by a bug in the sketch) is not harmless anymore. If I instead do: volatile byte message Īnd then set this from the ISR and read it inside loop(), I might not loop fast enough to read quickly incoming messages - thus losing messages. What should I do with message? I shouldn't process it in the ISR in order to keep the interrupt slim and fast. How do I properly resolve the below issues? I've got a stream of messages coming into an I2C slave from its master. ![]()
0 Comments
Read More
Leave a Reply. |