I am working with NXP S32K148 Evaluation Board and developing a sample program for UART transmit and receive at the Baud rate of 115200.
Taken the Project Example S32K148_Project_LPUART and I have reconfigured the baud rate to 115200 with the following configuration
PCC->PCCn[PCC_LPUART1_INDEX] &= ~PCC_PCCn_CGC_MASK; // Ensure clk disabled for config
PCC->PCCn[PCC_LPUART1_INDEX] |= PCC_PCCn_PCS(0b110) // Source clock for LPUART1 is SPLLDIV2_CLK
| PCC_PCCn_CGC_MASK; // Enable clock for LPUART1 regs
LPUART1->BAUD = LPUART_BAUD_SBR(0xC) /* Initialize for 115200 baud, 1 stop: */
| LPUART_BAUD_OSR(28); /* SBR=12 (0xC): baud divisor = 40M/115200/29 = ~12 */
/* OSR=28: Over sampling ratio = 28+1=29 */
/* SBNS=0: One stop bit */
/* BOTHEDGE=0: receiver samples on the rising edge*/
/* M10=0: Rx and Tx use 7 to 9 bit data characters */
/* RESYNCDIS=0: Resync during rec'd data word supported */
/* LBKDIE, RXEDGIE=0: interrupts disable */
/* TDMAE, RDMAE, TDMAE=0: DMA requests disabled */
/* MAEN1, MAEN2, MATCFG=0: Match disabled */
LPUART1->CTRL = LPUART_CTRL_RE_MASK
|LPUART_CTRL_TE_MASK; /* Enable transmitter & receiver, no parity, 8 bit char: */
/* RE=1: Receiver enabled */
/* TE=1: Transmitter enabled */
With the above configuration I can able to transmit data from Evaluation Board to PC(using TTL converter).
But when I tried to UART receive data from PC to Evaluation Board is not working. The following is the code to receive the char
char LPUART1_receive_char(void) { /* Function to Receive single Char */
char receive;
while((LPUART1->STAT & LPUART_STAT_RDRF_MASK)>>LPUART_STAT_RDRF_SHIFT==0);
/* Wait for received buffer to be full */
receive= LPUART1->DATA; /* Read received data*/
return receive;
}
Data is sent from the PC to LPUART1_RX(PTC6), but the cursor is not passing the while statement LPUART1->STAT value remained at 0xC00000.
Can you please help me on this where am missing.