Direct Port Manipulation Problems Teensy 3.1

Status
Not open for further replies.
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
}
 
Try using pinMode() to configure pin 13 as an output in your setup instead of GPIOC_PDDR

Code:
     pinMode(13, OUTPUT);
 
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.
 
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
}
 
Status
Not open for further replies.
Back
Top