cancel
Showing results for 
Search instead for 
Did you mean: 

Stop Transmit interrupt manually during transmitting

Olly Kao
Associate III

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Guenael Cadier
ST Employee

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

View solution in original post

1 REPLY 1
Guenael Cadier
ST Employee

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