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

Thread: how to configure pins beyond the 64 on a custom board with the teensy library

  1. #1

    how to configure pins beyond the 64 on a custom board with the teensy library

    I am working on an embedded MCU board and I am using the Teensy 3.6 as a project development board. The teensy works great but now I need to use more of the digital pins than are available on the development board. I use several Teensy 3.6 boards during development. I also ordered some pre-loaded ML04 chips for each of the embeded boards. The roadblock I have now is getting those other pins configured. I seem to be able to use GPIOx_PDIR, GPIOx_PDOR, GPIOx_PSOR, GPIOx_PCOR and GPIOx_PTOR, but I can't seem to get the GPIOx_PDDR register to work even though I do not get a compile error.


    GPIOC_PDDR = 0X00000020; ( PTC5 as output )

    If I use pinMode( 13, OUTPUT ); it works fine.

    Is this a limitation of the header files and that they need to be modified or what??

    Thanks in advance

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Are you writing to the pin config register first? By default all the pins are "ALT0" which is their low power disable state. You have to configure the pin mux to ALT1 for the pin to become controlled by the GPIO. Details in chapters 11 & 12.

  3. #3
    After reading thru the library code found in the teensy3 directory and reading the K66 manual, I think maybe if you could give me an example of a direct register write and read I think I have the idea of what I need to do. Also, am I correct that once the pin mode Alt1 is set then the GPIOx_PDDR and so on will apply for all pins and all ports with Alt0 set?

  4. #4
    My assumptions turned out to be correct. For anyone who is planning on using all of the pins possible in the context of an embedded LQFP form factor K66 it is possible within the context of Paul's fine development tools. The registers you will find are your best friends are:


    The blink example looks like:
    ================================================== ================
    /* LED Blink, Teensyduino Tutorial #1 (modified by Steve Brown for control register example code )

    This example code is in the public domain.

    // Teensy 2.0 has the LED on pin 11
    // Teensy++ 2.0 has the LED on pin 6
    // Teensy 3.x / Teensy LC have the LED on pin 13
    const int ledPin = 13;

    // the setup() method runs once, when the sketch starts

    void setup()
    // initialize the digital pin as an output.
    // pinMode(ledPin, OUTPUT);
    PORTC_PCR5 = ( unsigned long )0X00000100;
    GPIOC_PDDR = ( unsigned long )0X00000020;

    // the loop() methor runs over and over again,
    // as long as the board has power

    void loop()
    // digitalWrite(ledPin, HIGH); // set the LED on
    GPIOC_PDOR = 0X20;
    delay(1000); // wait for a second
    // digitalWrite(ledPin, LOW); // set the LED off
    GPIOD_PCOR = 0X20;
    delay(1000); // wait for a second
    ================================================== ===============

    I am sure there is a cleaner or more elegant way but, this works just fine and I tested it on my new board at another PORT pin. If it wasn't for these open source and hardware projects development of new devices would cumbersome, expensive, and time consuming. I look forward to the next incarnation of the Teensy family.

    Thank you Paul for a great development tool ( Teensy 3.6 )

Posting Permissions

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