Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[ARM] UART data receiving problem STM32

Status
Not open for further replies.

vimalraj

Junior Member level 2
Junior Member level 2
Joined
Apr 3, 2019
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
196
Hi guys,

I have generated a code from STMCUBEMX for UART using DMA for Tx and Rx. The DMA is used so that the main function should not be disturbed.
I did not call these below functions in the while loop.

Code:
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
    if(Fault_status != 1)
    {
        for(int i=0;i<=12;i++)
         {
           data_tx[i]=data_tx1[i];
         }

     }
   
   
}

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
    HAL_UART_Receive_DMA(&huart3,data_rx,sizeof(data_rx));

    if(data_rx[0]==0x3A)
    {
   
        // user code
       
       
        }
       
        }


These receiving function is triggered once the start bit is find. The communication is proper but if I disconnect and connect the Rx line, no data is received. If I reset the program then the data is received and the same problem occurs.

If I called the receiving function in while loop then it is working fine which delays the main operations. So I wanted it to run in background.

suggest what changes need to be done.
 

Hi,

This is just a snippet. We don't see periferal configuration, nor variabkes declaration.
Nor do we see how you transmit any data.

****
How the DMA receive works:
Let's say you declare data_rx array to be 4 char in size.
* Then you call the non blocking receive_DMA function. The function returns immediately. Other code gets processed.
* 1st byte arrives and gets stored by DMA without using processing power. No ISR is called.
* 2nd byte arrives and gets stored by DMA without using processing power. No ISR is called.
* 3rd byte arrives and gets stored by DMA without using processing power. No ISR is called.
* 4th byte arrives and gets stored by DMA without using processing power.
* now the DMA buffer is full, thus the receive_complete ISR gets called

We don't see what happens when the first byte is 0x3A or not.
One problem may be that during connection one erroneous byte is received.
So the 0x3A gets stored at position 1 (instead of position 0). = mis aligned
I see nothing in your code that corrects for mis-alignment.

I guess you expect that the receive_complete gets called for every single byte. But this is not true for DMA operation. Indeed that's the benefit of DMA operation.

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top