Port access rather than pin access

With Teensy 3.5 you could access multiple GPIO pins with a single instruction using macros like GPIOD_PDDR, GPIOD_PDIR and GPIOD_PDOR.

Is this still possible with Teensy 4.1?

For example:

Code:
#define xDATA_IN()        ((byte) (GPIOD_PDIR & 0xFF))
...
byte b = xDATA_IN();

Thanks.
 
Short answer - yes you can read in ports. They are different than T3.x.
You need to know the mapping from Arduino pin number to port number and pin on port....
I usually do that by using my excel document. There are links to it on the forum plus the pin section of the product page has links...
1730122749672.png

Note the GPIO columns have numbers in them, like Arduino pin 19 is shown as 1.16 , so it is pin 16 on Port 1. However, each pin actually has two port numbers. The default one which I show on the excel and the high-speed version which the startup code switches all of the pins to.
To convert more or less just add 5. That is Port1->6, 2->7, 3->8, 4->9
So pin 19 is actually on port 6...

If you have not already done so, you should download the IMXRT reference manual, which is linked to by all of the product pages.

Another way to understand the pin mapping, is look at the core_pins.h file that is installed in the teeny4 directory.
To read in all of the 32 bits for a port you can use the PSR register. You can use the hard coded fixed ones like: GPIO6_PSR

Or you can use the structure, which is defined in the imxrt.h file.
Code:
// 12.5.1: page 961
typedef struct {
        volatile uint32_t DR;                  // 00
        volatile uint32_t GDIR;                // 04
        volatile uint32_t PSR;                 // 08
        volatile uint32_t ICR1;                // 0C
        volatile uint32_t ICR2;                // 10
        volatile uint32_t IMR;                 // 14
        volatile uint32_t ISR;                 // 18
        volatile uint32_t EDGE_SEL;            // 1C
        uint32_t          UNUSED[25];          // 20 - 83
        volatile uint32_t DR_SET;              // 84
        volatile uint32_t DR_CLEAR;            // 88
        volatile uint32_t DR_TOGGLE;           // 8C


} IMXRT_GPIO_t;
And for example, use: IMXRT_GPIO6.PSR
 
Short answer - yes you can read in ports. They are different than T3.x.
You need to know the mapping from Arduino pin number to port number and pin on port....
I usually do that by using my excel document. There are links to it on the forum plus the pin section of the product page has links...
View attachment 36154
Note the GPIO columns have numbers in them, like Arduino pin 19 is shown as 1.16 , so it is pin 16 on Port 1. However, each pin actually has two port numbers. The default one which I show on the excel and the high-speed version which the startup code switches all of the pins to.
To convert more or less just add 5. That is Port1->6, 2->7, 3->8, 4->9
So pin 19 is actually on port 6...

If you have not already done so, you should download the IMXRT reference manual, which is linked to by all of the product pages.

Another way to understand the pin mapping, is look at the core_pins.h file that is installed in the teeny4 directory.
To read in all of the 32 bits for a port you can use the PSR register. You can use the hard coded fixed ones like: GPIO6_PSR

Or you can use the structure, which is defined in the imxrt.h file.
Code:
// 12.5.1: page 961
typedef struct {
        volatile uint32_t DR;                  // 00
        volatile uint32_t GDIR;                // 04
        volatile uint32_t PSR;                 // 08
        volatile uint32_t ICR1;                // 0C
        volatile uint32_t ICR2;                // 10
        volatile uint32_t IMR;                 // 14
        volatile uint32_t ISR;                 // 18
        volatile uint32_t EDGE_SEL;            // 1C
        uint32_t          UNUSED[25];          // 20 - 83
        volatile uint32_t DR_SET;              // 84
        volatile uint32_t DR_CLEAR;            // 88
        volatile uint32_t DR_TOGGLE;           // 8C


} IMXRT_GPIO_t;
And for example, use: IMXRT_GPIO6.PSR

Thanks for the thorough response.

- Michael
 
Back
Top