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

Thread: I2c communication issue between teensy 4.1 master and slave

  1. #1
    Junior Member
    Join Date
    Nov 2020
    Posts
    13

    I2c communication issue between teensy 4.1 master and slave

    Greetings,

    I am new to I2C communication but am trying to use a teensy 4.1 as a master device. The teensy would then communicate with another teensy 4.1 which would function as the slave device. They are both connected via pins 16 and 17. I have downloaded the Teensy4 I2C library from Richard Gemmell's github account. At this point I am simply trying to get his example codes to work (wire/master_reader uploaded to the master teensy4.1; and wire/slave_sender uploaded to the slave teensy4.1). Unfortunately, I am having no luck establishing any communication.

    In other devices, it looks like the SDA and SCL are connected to a Vcc through a resistor? I have not done this as I am getting conflicting information as to whether or not this is required on the teensy. Could this be my issue? Links to the example code are below. Thanks in advance for your help!

    https://github.com/Richard-Gemmell/t...ave_sender.ino
    https://github.com/Richard-Gemmell/t...ter_reader.ino

    Kind Regards,

    Kenneth D. Hoadley

  2. #2
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    1,094
    > They are both connected via pins 16 and 17

    Looks like the Master code expects 18 and 19. Or switch it to Wire1.

  3. #3
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    16,239
    ... someone double check - but not sure T_4.x i2c SLAVE mode yet been completed.

    Might confirm MASTER function with that code if there is a T_3.x or T_LC handy to act as slave.

  4. #4
    Junior Member
    Join Date
    Nov 2020
    Posts
    13
    Thanks for the replies! jonr, I did try pins 18 and 19 on the master as well, but no luck. defroster, I will try on a teensy 3.6 or arduino UNO next. For either of these, do I need to apply a vcc to the I2C cables or can I simply connect them directly from device to device? To better illustrate what I mean, I have attached this illustration from howtomechatronics.com which shows a 5v power supply to both the SDA and SCL lines. Is this required in my setup as well?

    Click image for larger version. 

Name:	How-I2C-Communication-Bus-Works.jpg 
Views:	70 
Size:	40.4 KB 
ID:	22343

  5. #5
    Junior Member
    Join Date
    Nov 2020
    Posts
    13
    Sorry defragster! Auto reply issues.

  6. #6
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    16,239
    RE post #4::

    All devices common to a T_4.1 should be at 3.3V for safety. And only ONE device needs to supply powered PullUps to the common SDA and SCL lines, and each device is individually powered but with common GND.

    defroster - no problem - Paul did it the other day too. I didn't realize typing that would be such a chore - and that I'd post so much when I joined here and picked that defragster name which is easy for me to type.

  7. #7
    Junior Member
    Join Date
    Dec 2020
    Posts
    8
    Quote Originally Posted by defragster View Post
    ... someone double check - but not sure T_4.x i2c SLAVE mode yet been completed.

    Might confirm MASTER function with that code if there is a T_3.x or T_LC handy to act as slave.
    Hi, I'm curious about this. Is it still uncertain if the Slaev functionality was completed?

    I am trying to send data from a Teensy 4.1 as am I2C slave. Here is an image from a logic analyzer of what I am sending to it:

    Click image for larger version. 

Name:	I2C_M4_logic.jpg 
Views:	27 
Size:	80.4 KB 
ID:	25683Click image for larger version. 

Name:	I2C_M4_logic.jpg 
Views:	27 
Size:	80.4 KB 
ID:	25683

    And I am using the basic example (just modifying the slave address):

    Code:
    #include <Arduino.h>
    #include <i2c_driver.h>
    #include <i2c_driver_wire.h>
    
    void requestEvent();
    
    int led = LED_BUILTIN;
    
    void setup()
    {
      pinMode(led, OUTPUT);
      Wire.begin(0x22);
      Wire.onRequest(requestEvent); // register event
    }
    
    void loop()
    {
      delay(100);
    }
    
    // function that executes whenever data is requested by master
    // this function is registered as an event, see setup()
    void requestEvent()
    {
      digitalWrite(led, HIGH);      // briefly flash the LED
      Wire.write(0xFF);
      digitalWrite(led, LOW);
    }
    I am using pins 16 and 17 as a slave I2C in the teensy. It seems that requestEvent() never kicks in though.

    Thanks!

  8. #8
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,713
    replace your 3 include's with just #include <Wire.h> and use T4.1 pins 18 and 19

Posting Permissions

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