Equivalent to Port Manipulation on Arduino

Rhino_

New member
I use an Arduino MEGA as a Motion Controller for a CNC Machine and use Port Manipulation to set all the Pins on a Port at the same time for precise Movement of multiple Motors at the same time.

I’ve found examples of setting a Single Pin on the Teensy, but I can’t find any information regarding Ports.

Is there a way to set the state of Multiple Pins at the same time, or must it be done a Single Pin at a time?

If it must be a Single Pin at a time, are there concerns for moving Multiple Motors in sync with each other?

For example, to Step 8 individual Motors at the same time on Arduino:
// PORTB = Step Pins
// PORTC = Direction Pins

PORTC = 0B11010001; //Set Motor Direction
PORTB = 0B11111111; //Set Step Pins HIGH
delay(20); //Wait 20 Microseconds
PORTB = 0B00000000; //Set Step Pins LOW
delay(20); //Wait 20 Microseconds
 
If I understand correctly, there are NO actual Ports on the Teensy 4.1, only Port Emulation which ultimately just uses “digitalWriteFast()” on each Pin individually.

Is that correct?
There are, but they're not called PORTB / PORTC / etc. because those are specific to AVR CPUs.
 
As mentioned, there are port. GPIO1-5 (they are also known as GPIO6-9), The pins on GPIO1 in normal mode are on GPIO6 in fast mode.
The Teensy startup code sets all of the pins into fast mode.

If you have not already done so, would recommend you download the IMXRT Reference Manual from one of the Teensy product pages:
Chapter 12 is on GPIO.
I keep my own Excel document about each of these processors: For example if you look at this page, for the Teensy 4.1
1715643895701.png

you will see the GPIO column on each side. For example, for pin 0, I have 1.3 This says that it is Pin 3 on GPIO1 (or normal usage GPIO6. Note each of these ports are 32 bits wide. If you write to these ports it will impact all of the pins on that port.
The header file imxrt.h has most of the processor registers defined in it. For most subystems, it has a typedef struct defined for it.
For port 6 if you wish to write to port6 you can do something like:
Code:
Serial.printf("%x", GPIO6.PSR);

Again the registers are defined in the chapter I mentioned in the reference manual
 
Back
Top