Teensy 3.1 and I2c pins 16 & 17

Status
Not open for further replies.

SmokingResistor

New member
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
 
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?
 
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:
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!
 
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/Adafrui...b/master/examples/lsm9doftest/lsm9doftest.ino

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

Regards
Arran
 
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.
 
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
//............
}
 
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.
 
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
 
Status
Not open for further replies.
Back
Top