PDA

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



t3andy
11-20-2013, 03:18 PM
Many topics point no:(

Headroom
11-20-2013, 04:56 PM
On his site Nick Gammon describes how two Arduinos talk to each other.

i2c-summary - by Nick Gammon (http://gammon.com.au/i2c-summary)

t3andy
11-20-2013, 05:54 PM
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?

PaulStoffregen
11-20-2013, 09:19 PM
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.

Headroom
11-20-2013, 09:25 PM
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.

t3andy
11-21-2013, 02:50 AM
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?

PaulStoffregen
11-21-2013, 07:26 AM
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.