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

Thread: Teensy 3.1 and I2c pins 16 & 17

Hybrid View

  1. #1

    Teensy 3.1 and I2c pins 16 & 17

    Hello All,

    I've recently started a GPS logger project that interfaces to the Teensy 3.1 and I'm having problems communicating with the i2c bus on pins 16 & 17. Are these valid i2c pins? If so, what is the trick to get them operational?

    Thanks,
    Kelly

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,735
    Those are grayed as if they should be usable when you can't use the primaries. Do you have ~4.7K pullups on the I2C lines? Good power and the right pins specified in software? Valid address to the I2C hardware?

    Can you temporarily use the primaries to test?

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,069
    By default, pins 18 and 19 will be used.

    EDIT: see message #6 below for correct code. This one has a mistake...


    To switch to the alternates, try this:

    Code:
    Wire.begin();
    CORE_PIN18_BIT = 0;  // turn off primary pins before enable alternates
    CORE_PIN19_BIT = 0;
    CORE_PIN16_BIT = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
    CORE_PIN17_BIT = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
    Also, remember that real pullup resistors are always required for I2C with Teensy 3.1.
    Last edited by PaulStoffregen; 01-15-2016 at 04:29 PM.

  4. #4
    Yup, I have pull-up resistors on both lines tied to 3.3V. I'm actually using 2.2k ohm. I'll try the code for switching to the alternate i2c pins. Thanks!

  5. #5
    Junior Member
    Join Date
    Oct 2015
    Posts
    2
    Quote Originally Posted by PaulStoffregen View Post
    By default, pins 18 and 19 will be used.

    To switch to the alternates, try this:

    Code:
    Wire.begin();
    CORE_PIN18_BIT = 0;  // turn off primary pins before enable alternates
    CORE_PIN19_BIT = 0;
    CORE_PIN16_BIT = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
    CORE_PIN17_BIT = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
    Also, remember that real pullup resistors are always required for I2C with Teensy 3.1.

    Hi Paul,

    I've tried this and it doesn't compile, I've tested this on Arduino 1.0.6 and Arduino 1.6.5 with teensyduino 1.25

    Are there any other methods I could try to change the i2c to 16 & 17 without using the alternative i2c library.

    The code I'm using is the adafruit libaray example file https://github.com/adafruit/Adafruit...sm9doftest.ino

    and I'm adding that additional bit of code to line 70 of this file https://github.com/adafruit/Adafruit...SM9DS0.cpp#L70

    Regards
    Arran

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,069
    Oh, opps, my mistake. Here's the right way:

    Code:
    #include <Wire.h>
    
    void setup() {
      Wire.begin();
      CORE_PIN18_CONFIG = 0;  // turn off primary pins before enable alternates
      CORE_PIN19_CONFIG = 0;
      CORE_PIN16_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
      CORE_PIN17_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
    }
    
    void loop() {
    }
    That should solve the "lvalue required" error.

  7. #7
    Member javiernicola's Avatar
    Join Date
    Apr 2018
    Location
    Madrid
    Posts
    20
    Quote Originally Posted by PaulStoffregen View Post
    Oh, opps, my mistake. Here's the right way:

    Code:
    #include <Wire.h>
    
    void setup() {
      Wire.begin();
      CORE_PIN18_CONFIG = 0;  // turn off primary pins before enable alternates
      CORE_PIN19_CONFIG = 0;
      CORE_PIN16_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
      CORE_PIN17_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;
    }
    
    void loop() {
    }
    That should solve the "lvalue required" error.
    Hello Paul, im trying this with a teensy 3.2(because pin18 SDA is burnt) .
    Is the same code for teensy 3.1 and teensy 3.2?

    So far i had no luck, could i have burned the periferic down if i still see a correct SCL signal?

    My setup:

    void setup() {
    Serial.begin(57600);
    delay(100);
    pinMode(LED_NARANJA_PIN, OUTPUT); digitalWrite(LED_NARANJA_PIN, HIGH);
    //
    Wire.begin(I2C_HARD_ADDR); // join i2c bus with address #I2C_HARD_ADDR
    CORE_PIN18_CONFIG = 0; // turn off primary pins before enable alternates
    CORE_PIN19_CONFIG = 0;
    CORE_PIN16_CONFIG = PORT_PCR_MUX(2) | PORT_PCR_ODE | PORT_PCR_SRE | PORT_PCR_DSE;
    CORE_PIN17_CONFIG = PORT_PCR_MUX(2) | PORT_PCR_ODE | PORT_PCR_SRE | PORT_PCR_DSE;
    //
    Wire.onRequest(hard_i2c_event); // register event
    //............
    }

  8. #8
    Senior Member
    Join Date
    Jan 2015
    Location
    SF Bay Area
    Posts
    255
    how do I use SCL1 and SDA1 on pins 29 and 30?

    or do I need to use the other i2c library to use it?

  9. #9
    Member javiernicola's Avatar
    Join Date
    Apr 2018
    Location
    Madrid
    Posts
    20

    It works for me

    Quote Originally Posted by doughboy View Post
    how do I use SCL1 and SDA1 on pins 29 and 30?

    or do I need to use the other i2c library to use it?
    Change every "Wire." for "Wire1."

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,069
    You need another library. The normal Wire library only accesses the main I2C port.

  11. #11
    Junior Member
    Join Date
    Oct 2015
    Posts
    2
    Thanks Paul that worked perfectly

  12. #12
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,591
    You could simply try with another Teensy. Such "oooops" moments where something get's shorted, burnt, or broken happen to every developer. That's why I strongly recommend to order Teensys in batches of 3, so that you have always one or two spares in the drawer to allow a differential diagnose.

  13. #13
    Member javiernicola's Avatar
    Join Date
    Apr 2018
    Location
    Madrid
    Posts
    20
    i did order 6, but sadly i need them all , i was trying to work around my BURNT SDA0 pin with no major changes in code.
    Im already using the alternative SDA1

Posting Permissions

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