Teensy 3.1 - fastest digitalWrite? Is port manipulation still the way to go?

Status
Not open for further replies.

howiemnet

Active member
On the Arduino, for fast I/O you write to the port directly, bypassing the friendly/safe/slow digitalWrite - does this still apply to the Teensy 3.1 / LC?

I gather Paul's made the PORTn stuff work with Teensys, but is it still fastest?

h
 
My understanding is that you'll always do best with digitalWriteFast. If possible, I believe it compiles to a macro for that port (without you having to do the register legwork and reading). If the pin is variable, it'll compile to a regular digitalWrite.

I believe there are also other 'fast' functions available, such as digitalReadFast.
 
Just to be clear, I believe digitalWriteFast is only fast when the pin number is constant. If it isn't constant, then it falls back to use the general library interface. Unfortunately if you doing abstractions and such, the pin number is often an argument to the constructor, and it becomes non-constant within the abstraction. You should declare pins using the const keyword to make sure the compiler knows they are constant.
 
On the Arduino, for fast I/O you write to the port directly, bypassing the friendly/safe/slow digitalWrite - does this still apply to the Teensy 3.1 / LC?

I gather Paul's made the PORTn stuff work with Teensys, but is it still fastest?

h

Either way, you can easily access port manipulation such as for PORT B: #define RGB_OUT GPIOB_PDOR, and then RGB_OUT = value; where value will be the binary that corresponds to your PORT pins, this could also be given a Hex description for example 0x16 which would be B10000 meaning only the PORT pin at 4 would go High. (counting zero as a value).
 
Status
Not open for further replies.
Back
Top