Skip to main content
Olly Kao
Associate II
Sep 8, 2020 2:10 AM UTC
Solved

Stop Transmit interrupt manually during transmitting

Hi

I'm doing a project to detect collision on UART, when I get data from Rx, I will compare it with the data I transmitted, if there aren't the same, means collision occurred, then I will immediately stop my transmitting interrupt to stop sources waste on the bus.

​

I am using

HAL_UART_Transmit_IT(&huart1, Message1.data, length);

to transmit data,​

I tried

UART_EndTransmit_IT(huart);

, but this function is not declared in main, so I directly write

CLEAR_BIT(huart1.Instance->CR1, USART_CR1_TCIE);
huart1.gState = HAL_UART_STATE_READY;

but the result is when I detected collision, the transmit yes stop, but then I recall HAL_UART_Transmit_IT(&huart1, Message1.data, length); transmit is not working, is there any more register I need to clear? or are there any other way to stop transmit interrupt during transmitting?

This topic has been closed for replies.
Guenael Cadier
Guenael CadierBest answer
ST Employee
Sep 8, 2020 7:58 AM UTC

Dear @Olly Kao​ ,

Indeed, UART_EndTransmit_IT() is not expected to be called in Application code.

In order to abort transmit sequence, and to allow further calls to HAL_UART_Transmit_IT(), I would recommend use of dedicated HAL UART API, in blocking mode :

  • HAL_UART_Abort() : aborts both TX and RX
  • HAL_UART_AbortTransmit(() : aborts only TX

Similar primitives exist in non blocking mode, with execution of callbacks when Abort operations is completed ;

  • HAL_UART_Abort_IT() : aborts both TX and RX, call HAL_UART_AbortCpltCallback() at the end
  • HAL_UART_AbortTransmit_IT() : aborts only TX, call HAL_UART_AbortTransmitCpltCallback() at the end

Regards

1 reply

Guenael Cadier
Guenael CadierBest answer
ST Employee
Sep 8, 2020 7:58 AM UTC

Dear @Olly Kao​ ,

Indeed, UART_EndTransmit_IT() is not expected to be called in Application code.

In order to abort transmit sequence, and to allow further calls to HAL_UART_Transmit_IT(), I would recommend use of dedicated HAL UART API, in blocking mode :

  • HAL_UART_Abort() : aborts both TX and RX
  • HAL_UART_AbortTransmit(() : aborts only TX

Similar primitives exist in non blocking mode, with execution of callbacks when Abort operations is completed ;

  • HAL_UART_Abort_IT() : aborts both TX and RX, call HAL_UART_AbortCpltCallback() at the end
  • HAL_UART_AbortTransmit_IT() : aborts only TX, call HAL_UART_AbortTransmitCpltCallback() at the end

Regards