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

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

  1. #1

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

    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.

  2. #2
    Senior Member
    Join Date
    Apr 2014
    Location
    -
    Posts
    9,753
    Use
    void setSDA(uint8_t);
    void setSCL(uint8_t);

  3. #3
    hey sorry i've just added that bit off code and i still have the same error.

  4. #4
    Senior Member
    Join Date
    Apr 2014
    Location
    -
    Posts
    9,753
    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).

  5. #5
    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?

  6. #6
    Senior Member
    Join Date
    Apr 2014
    Location
    -
    Posts
    9,753
    Just use Wire1.begin() and Wire1.xyz.. in all other places..

  7. #7
    That still has not worked and I still get the same error.

  8. #8
    Senior Member
    Join Date
    Apr 2014
    Location
    -
    Posts
    9,753
    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..}

  9. #9
    yes i've tried this and im still getting the same error.

  10. #10
    Senior Member
    Join Date
    Apr 2014
    Location
    -
    Posts
    9,753
    how can you get the error "error: 'PORT_PCR_MUX' was not declared in this scope" when you don't use PORT_PCR_MUX?

  11. #11
    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?

  12. #12
    Senior Member
    Join Date
    Apr 2014
    Location
    -
    Posts
    9,753
    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.

  13. #13
    Senior Member+ mjs513's Avatar
    Join Date
    Jul 2014
    Location
    New York
    Posts
    8,475
    @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.

  14. #14
    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.

Posting Permissions

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