cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to receive UART data randomly

VijayRakeshM
Associate III

Hi,

I'm using STM32L0 series and working on UART to communicate with other module and I had chosen the polling method because i know the device max response time and exact data what i'm going to receive. I was running my application for testing and it worked fine for 24 hours and then after and MCU not able to receive data even the module is responding i don't understand this scenario, can anyone please suggest what could be the problem. Thanks in advance.

Regards,

Vijay Rakesh

HAL_UART_Transmit(&huart1,A_Buff,7,200);
HAL_UART_Receive(&huart1,Rx_Buf,4,5000);  // Timeout value is 5 seconds to receive data

1 ACCEPTED SOLUTION

Accepted Solutions

In my work I generally use a pair of FIFO buffers, and manage the reception/transmission from those directly in the IRQ Handler. The data is inserted and removed from the FIFO in a worker or foreground task so the interrupt is not loaded with processing overhead.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

8 REPLIES 8
S.Ma
Principal

It is looking for trouble to process rx in polling. At least get a cyclic dma buffer in reception si there won t be any timeout issue.

Hi @S.Ma​ 

Thanks for the reply, I don't have any idea on implementing DMA could please refer any document so that i can implement your suggestion and just now I have implemented UART interrupt method could this method can solve the above issue?

Regards,

Vijay Rakesh.

S.Ma
Principal

Check on stm32 library folders, nucleo board, usart projects.

They way you've implemented this with blocking functions is not conducive to concurrent transmit/receive. The HAL libraries just make such a mess of this rather than implementing some clean ring buffering.

My guess would be that you are getting over/under run type errors, or noise errors that don't get cleared and result in data loss. Compounded by fixed expectations about how much data will be received.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hi @Community member​ ,

Thanks for the reply, what can be the best solution for implementing concurrent transmit/receive.

Regards,

Vijay Rakesh

In my work I generally use a pair of FIFO buffers, and manage the reception/transmission from those directly in the IRQ Handler. The data is inserted and removed from the FIFO in a worker or foreground task so the interrupt is not loaded with processing overhead.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I was actually trying to do the same after facing the issue but i couldn't find the call back for each UART data I receive and I can only find HAL_UART_RxCpltCallback() where I need to mention how much data I'm about to receive.

HAL functions are built for expected length messages. Otherwise, use length of "1".

Otherwise use LL (low layer) especially for USART peripheral as it's pretty manageable.