UART Byte receive Problem.

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

UART Byte receive Problem.

1,768 Views
dipak
Contributor I

I have a problem with UART Receiving byte.

First, I have run UART example program on S32K142EVB. It is working with no problem. Both receive and transmit demo is working as it should be.

Then I write code for the real application board. I am not using interrupt or DMA, just simple pooling method. Baud rate is 19200. The PutChar function is working well (MCU to PC data send, captured in PuTTY or RealTerm). But GetChar function is not working (PC to MCU). I have checked first invoke to the function is working properly, but then it stuck at 

>> while((pUART->STAT & LPUART_STAT_RDRF_MASK)>>LPUART_STAT_RDRF_SHIFT==0)

Any idea please?

The code is as follow:

void UART_pin_settings(void)

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

   /* enable the UART port for the UART of S32K142 */
   PORTC->PCR[3]|=PORT_PCR_MUX(4); /* Port C3: MUX = ALT4, UART0 TX */
   PORTC->PCR[2]|=PORT_PCR_MUX(4); /* Port C2: MUX = ALT4, UART0 RX */
}

void UART_Init(LPUART_Type *pUART, uint32_t u32SysClk, uint32_t u32Baud)
{
   uint16_t u16Sbr;

   /* Enable the clock to the selected UART */
   if (pUART == LPUART0)
   {
      PCC->PCCn[PCC_LPUART0_INDEX] |= PCC_PCCn_PCS(0b011) /* Clock Src= 1 (SOSCDIV2_CLK) */
      |PCC_PCCn_CGC_MASK; /* Enable clock for LPUART1 regs */
   }
   else if (pUART == LPUART1)
   {
      PCC->PCCn[PCC_LPUART1_INDEX] |= PCC_PCCn_PCS(0b011) /* Clock Src= 1 (SOSCDIV2_CLK) */
      |PCC_PCCn_CGC_MASK; /* Enable clock for LPUART1 regs */
   }

   /* Make sure that the transmitter and receiver are disabled while we
   * change settings.
   */

   pUART->CTRL &= ~(LPUART_CTRL_TE_MASK | LPUART_CTRL_RE_MASK);

   /* Configure the UART for 8-bit mode, no parity */
   pUART->CTRL &= ~(LPUART_CTRL_M7_MASK | LPUART_CTRL_M_MASK | LPUART_CTRL_R8T9_MASK |    LPUART_CTRL_R9T8_MASK);


   /* Calculate baud settings */
   pUART->BAUD |= LPUART_BAUD_OSR(15);
   u16Sbr = (u32SysClk/u32Baud)/16;
   pUART->BAUD |= LPUART_BAUD_SBR(u16Sbr);

   /* Enable receiver and transmitter */
   pUART->CTRL |= LPUART_CTRL_TE_MASK | LPUART_CTRL_RE_MASK;
}

uint8_t UART_GetChar(LPUART_Type *pUART)
{

   /* Wait until character has been received */
   while((pUART->STAT & LPUART_STAT_RDRF_MASK)>>LPUART_STAT_RDRF_SHIFT==0);
   /* Return the 8-bit data from the receiver */
   return pUART->DATA;
}

void UART_PutChar(LPUART_Type *pUART, uint8_t u8Char)
{
   /* Wait until space is available in the FIFO */
   while((pUART->STAT & LPUART_STAT_TDRE_MASK)>>LPUART_STAT_TDRE_SHIFT==0);
   /* Send the character */
   pUART->DATA = (uint8_t)u8Char;
}

0 Kudos
4 Replies

1,594 Views
dianabatrlova
NXP TechSupport
NXP TechSupport

Hello,

Why do not you use the code from example if it is working for you?

I have changed the baudrate to 19200 and select SOSCDIV2_CLK in the example and it is working well. (attached)

I'm not sure which clock you are using because this code select the FIRCDIV2_CLK, but your comment says SOSCDIV2_CLK

PCC->PCCn[PCC_LPUART0_INDEX] |= PCC_PCCn_PCS(0b011)

Could you try it? But I'm using PTC6 and PTC7.

Also, have you checked LPUART-> STAT register?

Note: the example code is created in the S32 Design Studio for ARM ver 2.2 

Best regards,

Diana

0 Kudos

1,594 Views
dipak
Contributor I

Hi Diana,

Thank you for your reply.

Yes, I am using FIRCDIV2_CLK. Sorry for the wrong comment.

I think the clock is not a issue here. Because I can transmit data without any problem. Problem is in receiving. I am summarizing my actions.

I tested on Evaluation board (Both pooling and interrupt mode). Transmit and Receive both working good.

The same code I run in Application board (changed the pin configuration only to fit the application design). Now, I am able to transmit only, reception of data failed. I have tested both pooling and interrupt mode, but only transmit is successful, no reception in the application board!

Hope, I am able to clear my scenario.

Regards

Dipak Kumar

0 Kudos

1,594 Views
dianabatrlova
NXP TechSupport
NXP TechSupport

Hello,

Thank you for your clarification. Have you measured with an analyzer or oscilloscope the signal on the RX pin to disprove the possibility of a wrong connection on the application board?

Best regards,

Diana

1,594 Views
dipak
Contributor I

Hello,

Thank you for your suggestions.

The problem is identified and solved. You are right, it was h/w issue. When I measured with oscilloscope, found that RX pin routing was wrong.

Best regards

Dipak Kumar

0 Kudos