S32K118 UART1 Configuration

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

S32K118 UART1 Configuration

1,898 Views
ambarishhundeka
Contributor III

Hello NXP team,

We are using S32K118 controller in our project.

We are using UART1 configuration for Data transmission.

1. Configuring the UART1 pins 6 and 7 As gpio pins

PCC->PCCn[PCC_PORTC_INDEX ]|=PCC_PCCn_CGC_MASK; //Enable clock for PORTC

PORTC->PCR[7]|=PORT_PCR_MUX(1); //Port C6: MUX = ALT1,gpio pin

PORTC->PCR[6]PORT_PCR_MUX(1); // Port C7: MUX = ALT1,gpio pin

PTC->PDOR &= ~(1<<7);

PTC->PDDR |= 1<<7; //Port C7 : Data Direction= output

PTC->PDDR &= ~(1<<6); // Port C6 : Data Direction= input

Configuring the above pins as gpio pins .

2. Gpio 6 and 7 pins configured as UART pins

PCC->PCCn[PCC_LPUART1_INDEX] &= ~PCC_PCCn_CGC_MASK; /* Ensure clk disabled for config */

PCC->PCCn[PCC_LPUART1_INDEX] = PCC_PCCn_PR_MASK|PCC_PCCn_CGC(1)|PCC_PCCn_PCS(3);

PORTC->PCR[UART1_TX_PIN]|=PORT_PCR_MUX(PCR_UART_CONFIG); /* Port C6: MUX = ALT2,UART1 TX */

PORTC->PCR[UART1_RX_PIN]|=PORT_PCR_MUX(PCR_UART_CONFIG); /* Port C7: MUX = ALT2,UART1 RX */

LPUART1->BAUD = 0x0F00001A; //9600 baud rate , 1 stop bit and no parity

//LPUART1->BAUD |= LPUART_BAUD_SBNS(1); //testing purpose 30_6_2018

LPUART1->CTRL |= LPUART_CTRL_TXINV(1);

//LPUART1->STAT |= LPUART_STAT_RXINV(1);

LPUART1->CTRL |= LPUART_CTRL_TE(ENABLE) ;

LPUART1->CTRL |= LPUART_CTRL_RE(ENABLE);

if((LPUART1->STAT & LPUART_STAT_RDRF_MASK)>>LPUART_STAT_RDRF_SHIFT== 1)

{

    buffer = LPUART1->DATA;

  buffer = buffer & 0x00FF;

if(buffer == 0xA0)

{

  //doing some operation

}

}

first we are configuring pins as gpio pins for some other purpose(Internal method for Auto baud detection) and then configuring the pins as UART pins.

First Implemented the code for S32K144 and tested using S32 design studio, its working fine.

but same code used for S32K118 and using S32 Design studio, but it is not working.

I have noticed one thing , if I don't configure pins as gpio pins and directly configure pins as UART pins, then it is working fine for S32K118.

Please help me in this.

Thank you in advance.

Labels (1)
0 Kudos
1 Reply

1,390 Views
dianabatrlova
NXP TechSupport
NXP TechSupport

Hi Ambarish,

I checked the code and the OR ( |= ) for writing to PCR register change only one bit. The first set changed the MUX using OR operator to 1 and second write changed the MUX using OR operator to 3, but LUPART is alternative 2.

So, before the second write just clear or set all MUX bits.

Note:  In the code is the missing operator.

PORTC->PCR[6]  |= PORT_PCR_MUX(1); // Port C7: MUX = ALT1,gpio pin

I hope it helps you.

Best regards,

Diana

0 Kudos