NXP S32K148 Evaluation Board UART Receive Fails

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

NXP S32K148 Evaluation Board UART Receive Fails

跳至解决方案
3,795 次查看
ParthiVenkat
Contributor I

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.

0 项奖励
回复
1 解答
3,742 次查看
Robin_Shen
NXP TechSupport
NXP TechSupport

I test your configuration on S32K148EVB. If I send char one by one, then it's ok. But if I send several bytes at a time, then it will not exiting the while loop due to the Receiver Overrun Flag.

Receiver Overrun Flag.pngReceiver Overrun Flag.png

You may need to modify the receive function by refer the API of SDK.

 

 

在原帖中查看解决方案

0 项奖励
回复
5 回复数
3,586 次查看
ParthiVenkat
Contributor I

Resolved. By default the code have been configured to use LPUART1, updated the configuration to use LPUART0 and the code works fine as expected.

0 项奖励
回复
3,779 次查看
Robin_Shen
NXP TechSupport
NXP TechSupport

It looks like you are using the S32K148_Project_LPUART
example in S32DS Example Projects for S32K1xx.
If you use the lpuart_echo_s32k148 example in S32SDK S32K1xx RTM v3, it will be much easier to use Processor Expert to modify the clock source and baud rate.

S32K1xx RTM lpuart_echo_s32k148.pngS32K1xx RTM lpuart_echo_s32k148.png

Source clock for LPUART1 is SPLLDIV2_CLK.pngSource clock for LPUART1 is SPLLDIV2_CLK.pnginput baudrate.pnginput baudrate.png

Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 项奖励
回复
3,758 次查看
ParthiVenkat
Contributor I

Thank you Robin_Shen for your reply.

I think, Baud rate configuration is not the primary issue here.

Because even with S32K148_Project_LPUART code default baud rate of 9600, UART receive is not working.

It is not exiting the while loop

while((LPUART1->STAT & LPUART_STAT_RDRF_MASK)>>LPUART_STAT_RDRF_SHIFT==0);

Please help me on this.

0 项奖励
回复
3,743 次查看
Robin_Shen
NXP TechSupport
NXP TechSupport

I test your configuration on S32K148EVB. If I send char one by one, then it's ok. But if I send several bytes at a time, then it will not exiting the while loop due to the Receiver Overrun Flag.

Receiver Overrun Flag.pngReceiver Overrun Flag.png

You may need to modify the receive function by refer the API of SDK.

 

 

0 项奖励
回复
2,280 次查看
LBLDT
NXP Employee
NXP Employee

I have exactly the same problem except I configured correctly the UART, how can I overcome this OR flag issue ?

0 项奖励
回复