Teensy 4.0 GPIO pin toggle

sem0

Member
Hi,

i'd like to use Pin 14 as a output for specific pulses.
I'm able to get pin 12 and 13 to do this:

void setup() {

pinMode(13, OUTPUT);
pinMode(12, OUTPUT);

GPIO7_DR_SET = (1 << 1); // Set 12 to HIGH
GPIO7_DR_SET = (1 << 3); // Set pin 13 HIGH
}
void loop() {
GPIO7_DR_CLEAR = (1 << 1); // Set pin 12 LOW
GPIO7_DR_CLEAR = (1 << 3); //Set pin 13 HIGH
delay(10);
GPIO7_DR_SET = (1 << 1); // Set pin 12 HIGH
GPIO7_DR_SET = (1 << 3); // Set pin 13 HIGH
delay(10);
}

But any documentation on Pin 14 is wrong or does not work on my Teensy 4.0

Any idea?
BRs,
Sem0
 
Hi,

i'd like to use Pin 14 as a output for specific pulses.
I'm able to get pin 12 and 13 to do this:

void setup() {

pinMode(13, OUTPUT);
pinMode(12, OUTPUT);

GPIO7_DR_SET = (1 << 1); // Set 12 to HIGH
GPIO7_DR_SET = (1 << 3); // Set pin 13 HIGH
}
void loop() {
GPIO7_DR_CLEAR = (1 << 1); // Set pin 12 LOW
GPIO7_DR_CLEAR = (1 << 3); //Set pin 13 HIGH
delay(10);
GPIO7_DR_SET = (1 << 1); // Set pin 12 HIGH
GPIO7_DR_SET = (1 << 3); // Set pin 13 HIGH
delay(10);
}

But any documentation on Pin 14 is wrong or does not work on my Teensy 4.0

Any idea?
BRs,
Sem0

What have you tried for pin 14?
 
This is working:

void setup() {
pinMode(14, OUTPUT);
}
void loop() {
// Toggle pins
digitalWriteFast(14, LOW);
delay(10);

digitalWriteFast(14, HIGH);
delay(10);
}

But i do not know how get Pin 14 on low level... i can see it's on AD_B1_02, but i do not know how to access this?
 
Found a solution:

#include <Arduino.h>
void setup() {
IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B1_02 = 5; // Set pin mux to GPIO mode
IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_02 = IOMUXC_PAD_DSE(7); // Configure drive strength
GPIO6_GDIR |= (1 << 18); // Set pin direction to output
}
void loop() {
// Toggle the pin state
//GPIO6_DR_TOGGLE = (1 << 18);
//delay(500); // Delay for visibility
GPIO6_DR_SET = (1 << 18);
delay(10);
GPIO6_DR_CLEAR = (1 << 18);
delay(10);
}
 
Last edited:
I note that pin 14 is the first one that's an analog input, possibly why its different from 12 & 13. Not sure why you want to use direct register manipulation on it when digitalWrite / digitalWriteFast will both work and be readable and portable. Very precise timing? If so you'd better think about interrupts affecting the timing.
 
Hi Joe and Mark,
thanks for your quick response on the topic. I've been aware of the fact that pin 14 is different from 12 and 13.
Yes, it's about very precise timing and i guess digitalWriteFast is not as fast as direct register manipulation?
 
this means it is as fast as doing cryptic register manipulation but readable for a human? I've read it's not as fast but ok.
 
Back
Top