This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

STM32 UART DMA can receive first time correct then it receive nothing

0

I'm trying to use dma with uart in stm32f746 nucleo in receiving mode i can receive correct data in first use when i try to receive again receiving buffer doesn't change its initial values before receiving although i can get receive complete signal callback every time

/ Main Loop */ while(1) { HAL_GPIO_TogglePin(LED_PORT,LED_GREEN); // Led Example

        HAL_Delay(200);
        
        pRxData[0]=5;
        pRxData[1]=0;
// HAL_UART_Receive_IT(&UartHandle,pRxData,2);
   if( HAL_UART_Receive_DMA(&UartHandle,pRxData,2)==HAL_OK);  // UART-DMA-IT Example
        {
            while (UartReady != SET)                     // wait for msg len
            {
                 HAL_GPIO_WritePin(LED_PORT,LED_GREEN,1);
                 HAL_Delay(20);
                 HAL_GPIO_WritePin(LED_PORT,LED_GREEN,0);
                 HAL_Delay(400); 
            } 
            UartReady = RESET;                        // reset transmition flag
            LEN = pRxData[0]+pRxData[1]*256;             // calc msg length
            
            if ( LEN > 0 )
            {
                pTxData[0]= 25;//LEN;                            // ACK
                //HAL_UART_Transmit_IT(&UartHandle,pTxData,1);
                if(HAL_UART_Transmit_DMA(&UartHandle,pTxData,1)==HAL_OK);
                {
                
                    while (UartReady != SET) 
                    {   
                     HAL_Delay(1);
                    } 
                    
                    UartReady = RESET;
                    if(HAL_UART_Receive_IT(&UartHandle,pRxData,LEN)==HAL_OK)
                    {
                    //HAL_UART_Receive_DMA(&UartHandle,pRxData,LEN); 
                        while (UartReady != SET)                  // waiting loop for msg
                        { 
                            HAL_GPIO_WritePin(LED_PORT,LED_GREEN,1);
                            HAL_Delay(300);
                            HAL_GPIO_WritePin(LED_PORT,LED_GREEN,0);
                            HAL_Delay(50);
                            
                        } 
                        
                        UartReady = RESET;
                        
                            if (MBU_StrCompareNC(pRxData,"LED_ON_BLUE",LEN)==0)
                            {
                                HAL_GPIO_WritePin(LED_PORT,LED_BLUE,1); 
                            }
                            
                            if (MBU_StrCompareNC(pRxData,"LED_OFF_BLUE",LEN)==0)
                            {
                                HAL_GPIO_WritePin(LED_PORT,LED_BLUE,0); 
                            }
                            if (MBU_StrCompareNC(pRxData,"LED_ON_RED",LEN)==0)
                            {
                                HAL_GPIO_WritePin(LED_PORT,LED_RED,1); 
                            }
                            
                            if (MBU_StrCompareNC(pRxData,"LED_OFF_RED",LEN)==0)
                            {
                                HAL_GPIO_WritePin(LED_PORT,LED_RED,0); 
                            }
                            
                    }
                        
                 
                    HAL_UART_Abort(&UartHandle);
                }
            }
         }
 }
}