cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L496 UART1 Problem

Sim Be
Associate
Posted on January 18, 2018 at 15:09

Hello,

in a recent design I am experiencing some trouble on the L496RGT6 MCU when using UART1 in connection with an FT232RL. I am using HAL drivers.

The following problem occurs: Transmitting data in blocking an non-blocking mode works fine. But receiving leads to problems as UARt stays busy receiving. For receiving I use the HAL_UART_Receive_IT(...) function. When receiving data the Callback routine is executed as desired, but when executing the next receive out of the Callback UART is staying busy. My Callback routine is shown below. My code is exported by CubeMX with the SW4 Toolchain. The code is testet on two MCU. Same code wors fine on other STM32 F-/L-Series MCUs.

Are there any similar problems known yet? Has someone an idea for a workaround?

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){

    if(huart->Instance == USART1){

         // sending back received char

        HAL_UART_Transmit(&huart1, (uint8_t *)UART1_Rx_Data, 1,100);

        HAL_UART_Transmit(&huart1, (uint8_t *)'\r\n', 2,100);

         // print out current uart state and call receive_it again

        if (HAL_UART_Receive_IT(&huart1,(uint8_t *)UART1_Rx_Data,1) == HAL_OK){

            HAL_UART_Transmit(&huart1, (uint8_t *)'OK\r\n', 4,100);

        }

        if (HAL_UART_Receive_IT(&huart1,(uint8_t *)UART1_Rx_Data,1) == HAL_ERROR){

            HAL_UART_Transmit(&huart1, (uint8_t *)'ERROR\r\n', 7,100);

        }

        if (HAL_UART_Receive_IT(&huart1,(uint8_t *)UART1_Rx_Data,1) == HAL_BUSY){

            HAL_UART_Transmit(&huart1, (uint8_t *)'BUSY\r\n', 6,100);

        }

    }

}

Kind regards,

Simon

#stm32l496 #uart-it
1 ACCEPTED SOLUTION

Accepted Solutions
Sim Be
Associate
Posted on January 31, 2018 at 10:18

Ok, I solved the problem. It was a combination of several configuration and self made programming mistakes.

View solution in original post

4 REPLIES 4
Posted on January 18, 2018 at 16:35

The L4 has different flag and clearing method for overrun, noise and framing errors. If you have reception problems you should make sure these are cleared.

Pretty sure the IF/THEN structure really doesn't work the way you think it does, and the HAL_UART_Transmit is going to block for multiple byte times, compounding any other problems you have. Remember Callbacks are called in Interrupt Context, nothing is going to be serviced properly if you dwell excessively.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 18, 2018 at 16:36

In HAL manual I see: 'In the Half duplex communication, it is forbidden to run the transmit and receive

process in parallel, the UART state HAL_UART_STATE_BUSY_TX_RX can't be useful.'. But have not experienced such problem.
Sim Be
Associate
Posted on January 31, 2018 at 10:18

Ok, I solved the problem. It was a combination of several configuration and self made programming mistakes.

SMula
Associate II

Hi Sim Be,

I am also facing the same issue in the STM32L011F4P6 microcontroller(data is transmitting and the only receiving one byte but am sending more than a byte data). The transmitting & receiving data can be seen in the CRO , but am not getting the complete data in the microcontroller. I am also using the CubeMX generated code with HAL libraries.

So if your problem is solved can you tell me what changes have you made to correct it.

Thanks

Shiva