cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 UART DMA

KondenserSoketi
Associate II

Hello all,

I have a project using UART DMA for receive datas from Nextion HMI. When i touch a button on Nextion Screen, data should be received a buffer via UART DMA. 

 

First five hour it works good but after five hours no data flows. It is like the button doesnt work. I checked wire and other hardware stuff. They are all OK. It seems my code is wrong. Can anyone help to find where is the mistake? Shold i arrange flags?

 

Thanks in advance. You can find the code below.

 

void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
{
if(huart->Instance == USART3)
{
HAL_UARTEx_ReceiveToIdle_DMA(&huart3, rx_data_ekran, sizeof(rx_data_ekran));
__HAL_DMA_DISABLE_IT(&hdma_usart3_rx, DMA_IT_HT);
 
 
  if(rx_data_ekran[2] == 2){ // ON-OFF  button control
    if((rx_data_ekran[3] == 0)) // ON-OFF IKB OFF
    {
     
    bIKB_On_manuel = false;
  //NEXTION_SendNum("n1", 0);
    }
    else if((rx_data_ekran[3] == 1)) //  IKB ON
    {
    bIKB_On_manuel = true;
      
  //NEXTION_SendNum("n1", 1);
    }
    }
//
//
    if(rx_data_ekran[2] == 3 && rx_data_ekran[3] == 1){ // Oto Mod Kontrol
    bOtoModAktif_manuel = true;
    bManuelModAktif_manuel = false;
    bMod2= false;
           }
 
    else if(rx_data_ekran[2] == 47 && rx_data_ekran[3] == 1){ // Mod2 Kontrol
    bMod2 = true;
    bOtoModAktif_manuel = false;
    bOtoModAktif_manuel = false;
    }
 
 
}
 
 
 
 
}
2 REPLIES 2

You're going to want to test and clear receiver errors, like Noise, Framing, Overrun, etc.

If not errors/issues in UART, check DMA unit reporting.

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

UART is a stream interface, not message interface... One cannot just look for the data at a constant offset in the buffer - one has to find the beginning of the message according to the used higher layer protocol and parse that message properly.

The HAL_UARTEx_RxEventCallback() function is also called on the IDLE event and doen't mean that all of the buffer is full. That's why it has a Size parameter. And, on top of that, the HAL_UARTEx_ReceiveToIdle_DMA() call is not guaranteed to succeed...

https://community.st.com/t5/stm32-mcus-products/stm32f401-hal-uart-dma-qna/td-p/569223

Learn this:

https://github.com/MaJerle/stm32-usart-uart-dma-rx-tx