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

Thread: Using multiple I2C busses without i2c_t3? (Teensy 4.0)

  1. #1

    Using multiple I2C busses without i2c_t3? (Teensy 4.0)

    Hello,
    How would I use the additional I2C busses on the Teensy 4.0, without something like the i2c_t3 library I'd been using with the T3.6? I don't know how to avoid being limited to SCA/SDL 0. The T4.0 has several sets of I2C, is it possible to use them at this point?

    Worst case, I will have to try running everything off 1 I2C bus and use a multiplexer if I run into overlapping addresses. Was hoping not to though, I've got a couple of sensors that probably each utilize most of the bandwidth of a bus on their own and I've (foolishly) done a complete rebuild of a huge project using the 4.0... kicking myself for not having checked up on compatibility first, whoops...

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,061
    Typically Wire1 and Wire2 will initialize to using the next i2c bus pins. I expect that should work on Teensy 4 at this time.

    so instead of Wire.begin() it would be Wire1.begin() - the same for all other commands.

  3. #3
    Quote Originally Posted by sid8580 View Post
    I've (foolishly) done a complete rebuild of a huge project using the 4.0... kicking myself for not having checked up on compatibility first, whoops...
    Oh, i've run into the same trap. That is because a pre-beta system is marketed under a previously well reputated name.
    Unfortunately, it is not possible to program the T4 with the original IDE any more without running into problems, because the fuses have been burnt purposely for Teensyduino. I am about tossing the T4 and writing off the project.

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,061
    Quote Originally Posted by sid8580 View Post
    Hello,
    How would I use the additional I2C busses on the Teensy 4.0, without something like the i2c_t3 library I'd been using with the T3.6? I don't know how to avoid being limited to SCA/SDL 0. The T4.0 has several sets of I2C, is it possible to use them at this point?

    Worst case, I will have to try running everything off 1 I2C bus and use a multiplexer if I run into overlapping addresses. Was hoping not to though, I've got a couple of sensors that probably each utilize most of the bandwidth of a bus on their own and I've (foolishly) done a complete rebuild of a huge project using the 4.0... kicking myself for not having checked up on compatibility first, whoops...
    Glancing at the code for Wire indeed the T4 code shows support in \hardware\teensy\avr\libraries\Wire\WireIMXRT.h for:
    Code:
    extern TwoWire Wire;
    extern TwoWire Wire1;
    extern TwoWire Wire2;
    and in :: \hardware\teensy\avr\libraries\Wire\WireIMXRT.cpp
    Code:
    TwoWire Wire(&IMXRT_LPI2C1, TwoWire::i2c1_hardware);
    TwoWire Wire1(&IMXRT_LPI2C3, TwoWire::i2c3_hardware);
    TwoWire Wire2(&IMXRT_LPI2C4, TwoWire::i2c4_hardware);
    That is the normal convention for accessing alternate i2c ports.

  5. #5
    Defragster, thank you! This was one of those things I struggled with early on and found a way out of via i2c_t3, as a side effect it became the ONLY method I knew (at least for the extra busses). Maybe I haven't painted myself into a corner after all

  6. #6
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,357
    Quote Originally Posted by sid8580 View Post
    Defragster, thank you! This was one of those things I struggled with early on and found a way out of via i2c_t3, as a side effect it became the ONLY method I knew (at least for the extra busses). Maybe I haven't painted myself into a corner after all
    Originally i2c_t3 was the only way to do multiple I2C buses, but Paul did add support in Wire.h some time ago for multiple I2C buses.

    It is unfortunate that there is currently no Teensy 4 version of i2c_t3.

  7. #7
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,061

    Wire1 Works on T4

    Had to let a test run last night to SSD1306 i2c display - it is working at 3.3 MHz even with T4 at 912 MHz!

    Just now I modified that sketch with this SINGLE LINE after the #includes:
    Code:
    #define Wire Wire1
    That has the compiler change ALL Wire.xxx() refs to Wire1.xxx() with no other changes

    I moved i2c wires from #19 and #18 over to #16 and #17 and uploaded sketch is running Just fine at the same rates!

    The 3.3 MHz update takes a changed file @mjs513 posted on the T4_Beta thread - where current TD_1.48 max speed is 1 MHz.

Posting Permissions

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