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

Thread: Direct Port Manipulation Problems Teensy 3.1

  1. #1
    Junior Member
    Join Date
    Nov 2015
    Posts
    17

    Direct Port Manipulation Problems Teensy 3.1

    Hi I am trying to get direct port manipulation working. I have looked at other threads on it and read through the documentation for the K20P64M72SF1RM. I have tried just to get the led on pin 13 blinking using the port manipulation but it is not working. I know that the port for pin 13 is port c and the 5th pin on it but it still doesn't work. Is there anything that is wrong in my code? Thanks for any help.

    Code:
    int led = 5;
    
    void setup() {
    
      GPIOC_PDDR = (1<<led);//configuring the pin as an output
    }
    
    void loop() {
    
    delay(1000);
    
      GPIOC_PSOR = (1<<led);//setting the pin high
    
    delay(1000);
    
    GPIOC_PCOR = (1<<led);//setting the pin low
    }

  2. #2
    Junior Member
    Join Date
    Jul 2015
    Posts
    5
    Try using pinMode() to configure pin 13 as an output in your setup instead of GPIOC_PDDR

    Code:
         pinMode(13, OUTPUT);

  3. #3
    Junior Member
    Join Date
    Nov 2015
    Posts
    17
    Thanks that worked! Now I am wondering why setting it with GPIOC_PDDR did not work, can you offer any explanation?

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,080
    You're on the right track, but missing the config register which configures the pin to GPIO mode. All pins default to disabled (or analog) to save power. To use GPIO, you have to configure the pin mux.

    Calling pinMode() will do that for you. But if you want to write all the registers yourself, you'll need to write to PORTC_PCR5.

  5. #5
    Junior Member
    Join Date
    Nov 2015
    Posts
    17
    It worked thank you so much!

    Code:
    int led = 5;
    
    void setup() {
      PORTC_PCR5 = (1<<8);//configuring the pin as GPIO
      GPIOC_PDDR = (1<<led);//configuring the pin as an output
    
     //pinMode(13, OUTPUT);
    }
    
    void loop() {
    
    delay(1000);
    
      GPIOC_PSOR = (1<<led);//setting the pin high
    
    delay(1000);
    
    GPIOC_PCOR = (1<<led);//setting the pin low
    }

Posting Permissions

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