Teensy 4.0 Read value of pins right from register

Status
Not open for further replies.

gompertz

New member
Hi all,

Playing with the Teensy 4.0 which is my first adventure in something non-AVR. Looks like the whole concept of PORTA, PORTB, etc doesn't apply anymore, and I'm curious how I can go about reading pins in one call (therefore, no digitalRead). Also I already know what pins are for what, so I don't want to burn bunch of CPU time in the digitalRead method with the whole -if-then-else nature of the function.

Right now I have:

Code:
                d_r[0][col] = (CORE_PIN0_PINREG & CORE_PIN0_BITMASK) ? 1 : 0;
		d_r[1][col] = (CORE_PIN1_PINREG & CORE_PIN1_BITMASK) ? 1 : 0;
		d_r[2][col] = (CORE_PIN2_PINREG & CORE_PIN2_BITMASK) ? 1 : 0;
		d_r[3][col] = (CORE_PIN3_PINREG & CORE_PIN3_BITMASK) ? 1 : 0;
		d_r[4][col] = (CORE_PIN4_PINREG & CORE_PIN4_BITMASK) ? 1 : 0;
etc....

However this obviously still burns a lot of CPU cycles. Is there way to get the whole register of values for all 39 pins and mask out what I need in one swoop? I know in AVR world I could read the whole PORT at once.

Thanks!
 
This is pretty helpful, still a bit confused however... looks like this is the register I need:

snap1.png

But then Paul has coded this register from values 1 to 9 in imxrt.h
I would think maybe there would be 4 of them only (as per the image)?

snap2.png

Confused!
 
There is another post recently regarding PINS and perhaps the \hardware\teensy\avr\cores\teensy4\imxrt.h and also the schematic - that will have more info on the four PORTS and the pins presented as associated with the T4.

seems it was @mjs513?
 
Thanks, hopefully someone has a code example... tracing all the #defines its not looking promising. Unsure what point of 600MHz speed is if have to burn oodles of CPU reading pin values, especially if lots of IO connected. This effectively leaves only 5MHz of processor time left for the real work, with the 15 pins I have connected up.
 
A bit more of a forum search may find another example - seems there was one more with better detail than that.

it is one thing I've not done much with so haven't understood the new scheme yet. And gotta run now.
 
Status
Not open for further replies.
Back
Top