Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Issue with i2c_t3 interfering with wire declaration

  1. #1
    Junior Member
    Join Date
    Nov 2017
    Posts
    3

    Issue with i2c_t3 interfering with wire declaration

    This is my first post ever, so sorry if this isn't formatted correctly. I downloaded i2c_t3 from github and was trying to use it with my Teensy 3.6. I want to set up an I2C interface that has two slaves on the bus. When I compile it says that the declaration of Wire in i2c_t3 interferes with a declaration made in WireKinetis. This is the error that it's outputting:

    Compiling 'TeensyMotorControl' for 'Teensy 3.6'

    WireKinetis.cpp.o*: In function i2c0_isr
    WireKinetis.cpp:805: multiple definition of i2c0_isr

    Error linking for board Teensy 3.6
    i2c_t3.cpp.o*: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\i2c_t3 \i2c_t3.cpp:1317: first defined here
    Build failed for project 'TeensyMotorControl'
    ld.exe: Disabling relaxation: it will not work with multiple definitions

    WireKinetis.cpp.o*: In function Print::availableForWrite()
    WireKinetis.h:132: multiple definition of i2c1_isr
    i2c_t3.cpp.o*: C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\Pr int.h:61: first defined here

    WireKinetis.cpp.o*: In function Print::availableForWrite()
    WireKinetis.h:132: multiple definition of i2c2_isr
    i2c_t3.cpp.o*: C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\Pr int.h:61: first defined here

    WireKinetis.cpp.o*: In function Print::availableForWrite()
    WireKinetis.h:132: multiple definition of Wire2
    i2c_t3.cpp.o*: C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\Pr int.h:61: first defined here
    ld.exe: Warning: size of symbol Wire2 changed from 20 in C:\Users\Brandons pc\AppData\Local\Temp\VMBuilds\TeensyMotorControl\ teensy36\Debug\i2c_t3\i2c_t3.cpp.o to 108 in C:\Users\Brandons pc\AppData\Local\Temp\VMBuilds\TeensyMotorControl\ teensy36\Debug\Wire\WireKinetis.cpp.o

    WireKinetis.cpp.o*: In function Print::availableForWrite()
    WireKinetis.h:132: multiple definition of Wire1
    i2c_t3.cpp.o*: C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\Pr int.h:61: first defined here
    ld.exe: Warning: size of symbol Wire1 changed from 20 in C:\Users\Brandons pc\AppData\Local\Temp\VMBuilds\TeensyMotorControl\ teensy36\Debug\i2c_t3\i2c_t3.cpp.o to 108 in C:\Users\Brandons pc\AppData\Local\Temp\VMBuilds\TeensyMotorControl\ teensy36\Debug\Wire\WireKinetis.cpp.o

    WireKinetis.cpp.o*: In function Print::availableForWrite()
    WireKinetis.h:132: multiple definition of Wire
    i2c_t3.cpp.o*: C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3\Pr int.h:61: first defined here
    ld.exe: Warning: size of symbol Wire changed from 20 in C:\Users\Brandons pc\AppData\Local\Temp\VMBuilds\TeensyMotorControl\ teensy36\Debug\i2c_t3\i2c_t3.cpp.o to 108 in C:\Users\Brandons pc\AppData\Local\Temp\VMBuilds\TeensyMotorControl\ teensy36\Debug\Wire\WireKinetis.cpp.o

    collect2.exe*: error: ld returned 1 exit status

    This is the code that I'm running with (the file name is I2C.cpp, which is the I2C.h):
    //
    //
    //

    #include "I2C.h"
    #include<i2c_t3.h>

    const int ClockSpeed = 400000; //Max Clock Frequency is 400kHz
    const int Timeout = 200000; //200ms Timeout

    // Temperature Variable
    const int TemperatureAddress = 0x48;
    const int TemperatureLength = 2; //Temperature Data is 2 Bytes
    char TemperatureBuffer[TemperatureLength];
    const int TemperaturePointer = 0x00; //To Read Temperature

    //Pressure Variables
    const int PressureAddress = 0x77;
    const int PressureLength = 3; //Pressure Data is 3 Bytes Long
    char PressureBuffer[PressureLength];
    const int ResetPressure = 0x1E;
    const int InitPressureSequence = 0x48;
    const int ReadPressure = 0x00;

    void Init_I2C() { //Initialize I2C
    Wire.begin(I2C_MASTER, 0x00, I2C_PINS_3_4, I2C_PULLUP_EXT, ClockSpeed); //Set for Master Mode, Pins 3 & 4 400kHz Clock
    Wire.setDefaultTimeout(200000); // 200ms Timeout
    Wire.setOpMode(I2C_OP_MODE_ISR); //Set it to be an interrupt based operation
    SetTemperaturePointer();
    ResetPressureSensor();//This is done here in order to check if we can talk to the sensor

    }

    void SetTemperaturePointer() { //Set Pointer to temperature for temperature sensor. Only needs to be done on reset.
    Wire.beginTransmission(TemperatureAddress); // Write to the Teperature Sensor
    Wire.write(TemperaturePointer); // Write Pointer to the Temperature Sensor
    Wire.endTransmission(); // End Transmission
    if (Wire.getError()) {
    Serial.println("Temperature Sensor Failed to Initialize");
    }
    else {
    Serial.println("Temperature Sensor Successfully Initiliazed");
    }
    }

    void ResetPressureSensor() {
    Wire.beginTransmission(PressureAddress); //Write to Pressure Sensor
    Wire.write(ResetPressure); //Reset It
    Wire.endTransmission(); //End
    if (Wire.getError()) { //Was there an error?
    Serial.println("Pressure Sensor Failed to Initialize");
    }
    else {
    Serial.println("Pressure Sensor Successfully Initiliazed");
    }
    }

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    2,751
    remove i2c.h?

  3. #3
    Junior Member
    Join Date
    Nov 2017
    Posts
    3
    Quote Originally Posted by tonton81 View Post
    remove i2c.h?
    No that doesn't help. The source file I posted was not the main file of the project. The file I posted was named "I2C.cpp" with the header file as "I2C.h". I tried removing #include "I2C.h" and declare the functions inside the .cpp file, but the same errors remained. All I2C.h contains is the following:

    // I2C.h

    #ifndef _I2C_h
    #define _I2C_h

    #if defined(ARDUINO) && ARDUINO >= 100
    #include "wprogram.h"
    #else
    #include "WProgram.h"
    #endif


    #endif

    void Init_I2C();
    void ResetPressureSensor();
    void SetTemperaturePointer();

  4. #4
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    3,653
    Again the difficulty is we can not see your whole program. As mentioned at the top of every posting, please post complete code that duplicates your issue.

    For example what else is your program using? Does any of the files that you use include wire.h?

    if so they can not exist in the same program as they both define the same objects AND they use the same hardware resources.

    You have a few choices here.

    Change all of your program to use i2c_t3, including any libraries that you might include.

    Maybe hack up a version of wire library that you put into your <Arduino sketch folder>/libraries/wire, which tries to redirect everything to use i2c_t3.

    Or simply use the standard Wire library and use the Wire2 object, which defaults to pin 3 and 4... But you don't have some of the other features of i2c_t3

  5. #5
    Junior Member
    Join Date
    Nov 2017
    Posts
    3
    TeensyMotorControl.zipWire.zip

    I'm not using wire.h anywhere else. I tried changing wire and WireKinetis to include i2c_t3 and that led to a whole different slew of errors. I attached both my workspace, as well as the wire library that I'm using. How would I change the wire library in order to point to i2c_t3?

  6. #6
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    3,653
    You might want to mention that you are not building using the Arduino IDE... It has been awhile since I had visual studio setup,

    Hopefully someone else who uses it can find where the dependencies are for this. I would probably look for places where you are including libraries and the like into the link.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •