Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Teensy 4.0 Read value of pins right from register

  1. #1
    Junior Member
    Join Date
    Oct 2019
    Posts
    3

    Teensy 4.0 Read value of pins right from register

    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!

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,971
    There are some tips in at least one 'PORT' post in the last week or so.

    Not sure if this is the best post?: port-and-toggle-question-T4

  3. #3
    Junior Member
    Join Date
    Oct 2019
    Posts
    3
    This is pretty helpful, still a bit confused however... looks like this is the register I need:

    Click image for larger version. 

Name:	snap1.png 
Views:	7 
Size:	60.6 KB 
ID:	17912

    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)?

    Click image for larger version. 

Name:	snap2.png 
Views:	6 
Size:	9.2 KB 
ID:	17913

    Confused!

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,971
    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?

  5. #5
    Junior Member
    Join Date
    Oct 2019
    Posts
    3
    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.

  6. #6
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,971
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •