(teensy 4.0) problem with changing primary i2c pins(18 and 19)

Status
Not open for further replies.
Hello, im Darren and im new to this community and teensy.

Im trying to switch the primary i2c pins(18 and 19) to (16 and 17) on my teensy 4.0 board because i didnt realize only one set of 12c can be used at a time. im trying to connect some 12c devices but the 18 and 19 pins are being used for something else for a project. ive searched through some threads and the code that people use to do this is this:

#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() {
}

However, when i compile on arduino IDE, it says:

Arduino: 1.8.9 (Windows 10), TD: 1.51, Board: "Teensy 4.0, Serial, 600 MHz, Faster, US English"

pinchange: In function 'void setup()':
pinchange:9: error: 'PORT_PCR_MUX' was not declared in this scope
CORE_PIN16_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;

^

pinchange:9: error: 'PORT_PCR_ODE' was not declared in this scope
CORE_PIN16_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;

^

pinchange:9: error: 'PORT_PCR_SRE' was not declared in this scope
CORE_PIN16_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;

^

pinchange:9: error: 'PORT_PCR_DSE' was not declared in this scope
CORE_PIN16_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_ODE|PORT_PCR_SRE|PORT_PCR_DSE;

^

'PORT_PCR_MUX' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Now this is where i need your help. Am i missing something? Do i need to define something or include some libraries specific to this code because ive never seen this before ever.
 
If you have the same error, you have not compiled it.

Sorry, Pins16&17 are an other I2C device - you need to use I2C1 (Wire1), I think - the functions I mentioned above will not work (my fault).
 
alright thats okay, but what is i2c1? is that suppose to be a library? im still new to this field sorry. whats should i do to include that?
 
Sorry, you CANT get the same error as in Post#1. Or are the wrong lines still there ? You need to delete them.
Code:
#include <Wire.h>

void setup() {
   Wire1.begin();
}
void loop() {..blah..}
 
how can you get the error "error: 'PORT_PCR_MUX' was not declared in this scope" when you don't use PORT_PCR_MUX?
 
thats why i asked whether i need to include something else or not. Secondly, i found this piece of code in this forum so it isn't mine. The thread where I got this code from also suffered from the same problem as me with changing the same pins but using a teensy 3.2. The code should work for teensy 4 but I'm getting compiling errors. okay, how would you redefine these pins properly then? is there another way?
 
The proper way is in post #8.
You can't get these error if the lines are not there.
I don't know what you are doing.

Please post your new sketch now.
 
@Saint Chablo
If all you are trying to do is use the alternate pins you don't need to do anything with configuring the pins or turning them off. All you need to do is what Frank had in post #8 to use Wire1. The core/compiler does the rest.

Code:
#include <Wire.h>

void setup() {
   Wire1.begin();
[ DO THE SETUP for what ever device you are using on pins 16 and 17]
}
void loop() {..blah.. DO what ever you need to do to read your device}

As Frank said once you specify Wire1 you are automatically using those pins. Other thing is make sure you have selected Teensy 4 in the dropdown menu of the IDE.
 
ohhh i get what you both mean thank you so much, sorry if i was too slow to understand. i just tested it and now i have access to the pins. Thank you both.
 
Status
Not open for further replies.
Back
Top