Wire.setSDA() and Wire.setSCL() and/or i2c_t3.h

Status
Not open for further replies.

Rob Gorbet

New member
Hey folks,

I'm trying to use Adafruit's AMG8833 GridEye with Teensy 3.2, and need to use SCL1/SDA1 (29/30). Because I want to use the Adafruit GridEye libraries, I want to make as few changes to other libraries and code as possible. So while I'm aware of i2c_t3, I'd rather stick with Wire if possible.

The web page https://www.pjrc.com/teensy/td_libs_Wire.html suggests that pins other than the default can be used, by calling Wire.setSCL() and Wire.setSDA(). The versions of wire.cpp and wire.h on my laptop don't appear to have those functions, so I was just going to download the latest from https://github.com/PaulStoffregen/Wire, but I see that the functions in question are actually empty there:

void TwoWire::setSDA(uint8_t pin)
{
}

void TwoWire::setSCL(uint8_t pin)
{
}

Have I missed something?

ALTERNATIVELY

I have also tried using i2c_t3.h instead of Wire.h. I commented out include wire.h and added include i2c_t3.h. Then I recompiled and confirmed that the code runs on SCL0/SDA0. Then I found the spot in Adafruit_AMG88xx.cpp where the I2C port is created, and replaced Wire.begin() with Wire.begin(I2C_MASTER,0x00,29,30)

The code compiles, and then correctly executes the Wire.begin and a few Wire.write calls, but hangs on the first call to Wire.endTransmission(), which never returns.

Thanks for any help folks can provide!
 
For WIRE.H There is this Teensy specific version that must link in somehow: ...\hardware\teensy\avr\libraries\Wire\WireKinetis.cpp

That is where the wire:set func()'s are defined.
 
For WIRE.H There is this Teensy specific version that must link in somehow: ...\hardware\teensy\avr\libraries\Wire\WireKinetis.cpp

That is where the wire:set func()'s are defined.

Thanks for this! I tried this as well but without success. Is there something else that I need to do other than:

Code:
#include <WireKinetis.h>

...

Wire.setSCL(29);
Wire.setSDA(30);
Wire.begin();

When I use 19/18 instead of 29/30 in the code above, I'm able to communicate with the GridEye on pins 19/18. When I use the code above, it doesn't respond as I expect it to.
 
Its not enough to change the pins with setSDA and setSCL. I2C1 is a different hardware instance than I2C0. Thus, you need to include a library like i2c_t3 which handles different hardware instances. To use pins 29 and 30, it would be Wire1.setSCL(29); Wire1.setSDA(30); Wire1.begin() instead of Wire.whatever() since the latter maps to I2C0/Wire0.
 
I keep wondering if we should try to make it work...

Not sure if we should try it with new api, or simply if scl and sad are mapped to different physical object internally use other object...

I do this with my ili9341_t3n library with which spi object to use.
 
Thank you! That was very clear, and worked. (In fact, no need to use setSCL and setSDA in that case since those are the defaults for Wire1).

I simply included wirekinetis.h rather than wire.h, and changed all calls from Wire.X to Wire1.X, and it just worked.

As a suggestion, it would have saved me a day of work to have a note on https://www.pjrc.com/teensy/td_libs_Wire.html

Thanks to everyone who helped, and to Paul for writing WireKinetis!
 
Status
Not open for further replies.
Back
Top