Teensy 3.xx pin definition

Status
Not open for further replies.

2n3055

Well-known member
Hi,

Is the PIN6 equivalent to D6?

Code:
#define DATAIN_PIN      PIND
#define DATAIN  6    

    while (DATAIN_PIN & (1 << DATAIN))
{}

Thanks
 
There are a few ways to answer this question.

#1: Using digitalReadFast(6) will compile to the fastest possible direct register read, as long as the input "6" is a constant the compiler knows. A variable only known at runtime compiles to the normal digitalRead, so make sure you use the actual number of a define of the number.

#2: Using the AVR register names as you've done will also work, because Teensy emulates these AVR registers as the Arduino Uno pinout. AVR's PD6 happens to be pin 6 on Uno. The emulation code causes your (PIND & (1<<6)) to be automatically replaced by the fastest native access method.

#3: Using the native registers, first you'd look at the schematic to see pin 6 is native pin PTD4. The native register access is (GPIOD_PDIR & (1<<4))

#4: The Teensyduino core library also defines convenient names for the native registers based on the Arduino pin numbers. So you could also use (CORE_PIN6_PINREG & CORE_PIN6_BITMASK)

All 4 of these compile to the same code.

However, no matter which of these you use, you must use pinMode(6, INPUT) first. The pins default to a low-power disabled state, which is different from AVR where they default to input mode.
 
Status
Not open for further replies.
Back
Top