Undefined reference to `twi_writeTo'

Status
Not open for further replies.

georgiagallant

New member
Hi,
I am using an Adafruit multiplexer and a teensy 3.5 and I'm trying to run the below scanner program (taken from this Adafruit webpage where I bought the multiplexer: https://learn.adafruit.com/adafruit-tca9548a-1-to-8-i2c-multiplexer-breakout/wiring-and-test) to see whether it can report which I2C ports on the multiplexer are in use. However, when I run it I get this error: "undefined reference to `twi_writeTo' collect2: error: ld returned 1 exit status Error compiling for board Teensy 3.5." I hooked the multiplexer up to an Arduino Uno and uploaded the same code and it worked perfectly. What does this error mean and how can I avoid it?

Thanks!
Georgia
 
looks like, the code is in the Wire library under the directory\utility

The .c file in this directory has all of the code compiled under #if defined(__AVR__)
So the code will not currently compile on Teensy.

Not sure how hard it would be to convert the file to work on Teensy. Also if you are simply wanting an I2C Scanner program,
There is one example sketch already under the wire library (Scanner) that will do it.

Kurt
 
Try adding this to the example sketch.

Code:
// for compatibility with examples that directly call this AVR-specific function
// https://learn.adafruit.com/adafruit-tca9548a-1-to-8-i2c-multiplexer-breakout/wiring-and-test
extern "C"
uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait, uint8_t sendStop)
{
        if (!wait) return 4;
        Wire.beginTransmission(address);
        while (length) {
                Wire.write(*data++);
                length--;
        }
        return Wire.endTransmission(sendStop);
}
 
Status
Not open for further replies.
Back
Top