Is it possible to have a Teensy 3 I2C slave with the standard release library?

Status
Not open for further replies.
Again ... I know that two Arduinos can talk I2C to each other BUT can a Teensy 3 become a I2C slave with the standard release library?
 
Yes. Wire on Teensy3 supports slave mode.

Early in Teensy3's history, I made several revisions to the Wire library port. The slave mode support was the last thing added, many months after Teensy3's initial release. In fact, as I recall, for a while one of the handlers was supported but the other wasn't. If you search old messages, there's probably a lot of conversation from those early days. Eventually, I did get both working. I have personally tested both, so I can confirm they do work.

I believe there is one minor quirk. On Teensy 2.0 and Arduino, the handler is called while the AVR still holds the I2C bus busy. The SDA and SCL lines are allowed to return high only after your handler function returns. On Teensy 3.0, your handler function gets called while the bus is idle, right after those lines return high. I'm not sure if that would ever really matter. But unfortunately, that behavior together with Wire's API that allows variable length reception (you don't have to tell Wire in advance how many bytes the other I2C master sends) just isn't possible on Teensy3.
 
If two devices on the I2C bus talk to each other, one to be the master and one has to be the slave. And I do believe that this is the functionality that is provided with the standard library.
 
On Teensy 3.0, your handler function gets called while the bus is idle, right after those lines return high. I'm not sure if that would ever really matter. But unfortunately, that behavior together with Wire's API that allows variable length reception (you don't have to tell Wire in advance how many bytes the other I2C master sends) just isn't possible on Teensy3.

@Paul ... What does this mean in other terms for T3 slave operation?
 
This minor difference, of exactly when your handler function gets called, probably makes zero difference in any real application.

What will your OnReceive function actually do? Usually people do things like use the just-arrived data to turn on LEDs, analogWrite(), send to a serial port, and so on. None of those depend on whether the function ran relative to the I2C bus being in one particular state or another. They probably also don't really matter if the handler is called a couple microseconds later, after both SDA and SCL return high.
 
Last edited:
Status
Not open for further replies.
Back
Top