cancel
Showing results for 
Search instead for 
Did you mean: 

RS485 Uart DMA Tx

DCtech
Associate II

I am using stm32f4xx, and I am using UART with DMA normal mode.

I have a problem with the Transmit Completed state, When I using the TxCompletedCallbacks I get hard fault error so I learned it does not using with normal mode so I am trying the Transmit Completed fnished with TC flag as I look the referance manual.

I enabled this interrupt:

__HAL_UART_ENABLE_IT(&huart2, UART_IT_TC)

Than I set the flag when the TC is set like this in USART2 interrupts;

void USART2_IRQHandler(void)
{
    if( (__HAL_UART_GET_FLAG(&huart2, UART_FLAG_TC) == SET))
    {
      txCmp = 1;
    //    __HAL_UART_CLEAR_FLAG(&huart2, UART_FLAG_TC);       
      
//     }
    
  }
}

when the txCmp = 1 than I check this flag in main.c loop than, I set the rs485 tranceiver to receiver mode but again I get Hardfault error how can I detect Transmit completed and set the transceiver receive mode correctly ?

3 REPLIES 3
TDK
Guru

Usually the DMA stream transfer complete interrupt is the one that is used here. I'm not sure if the USART TC will behave similarly here.

What's the reason for the hard fault? Observe SCB registers.

If you feel a post has answered your question, please click "Accept as Solution".
DCtech
Associate II

when I use the   if( (__HAL_UART_GET_FLAG(&huart2, UART_FLAG_TC) == SET) line detect the transmit completed, but this line does not detect correctly, sometimes this line does not work, but when I use HAL_UART_TxCpltCallback working correctly and detects all transmit completed flags why this happening ?

TDK
Guru

Did you read what I wrote? HAL doesn't use this flag.

If you feel a post has answered your question, please click "Accept as Solution".