S32K144 GPIO register

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S32K144 GPIO register

3,147 Views
autics
Contributor III

I'm using the S32K144 EVB board.

I'm learning about <2.1 Hello world> in AN5413 document. It works well for the relevant part.

Additionally, I wanted to know about the Port Data Output Register (PDOR), so I programmed it as follows.

The LED lights up only when the Reset button is pressed.

Please explain the Port Data Output Register (PDOR).

 

// ****************************************************

for (;;)
{

  if (PTC->PDIR & (1<<PTC12)) { /* If Pad Data Input = 1 (BTN0 [SW2] pushed) */
  // PTD-> PCOR |= 1<<PTD0; /* Clear Output on port D0 (LED on) */
     PTD->PDOR|= 0<<PTD0;}
  
  else { /* If BTN0 was not pushed */
  // PTD-> PSOR |= 1<<PTD0; /* Set Output on port D0 (LED off) */
     PTD->PDOR|= 1<<PTD0;}

}

0 Kudos
Reply
1 Reply

3,130 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @autics,

Each port pin is mapped to the following 32-bit GPIO registers, each bit represents a pin in the port x:

  • GPIOx->PDOR. Data Output
  • GPIOx->PSOR. Set Output
  • GPIOx->PCOR. Clear Output.
  • GPIOx->PTOR. Toggle Output
  • GPIOx->PDIR. Input register
  • GPIOx->PIDR. Input disable register
  • GPIOx-> PDDR. Data Direction register

If the PDIR of a pin is cleared, then it is configured as an input. If the PDIR of a pin is set, it is configured as output, which means that the logic state is controlled via PDOR or PCOR, PSOR and PTOR.

In your code modification, you are trying to clear the output for PTD0 with "PTD->PDOR|= 0<<PTD0". To clear a bit, it should be instead done with the AND operator, for example: "PTD->PDOR&= ~(1<<PTD0)"

Clearing the bit could be done this way, or (as the example includes) with the PCOR register. This is the same as setting the bit with PDOR or with PSOR (as the example includes).

I hope you find this helpful.

Best regards,
Julián.