Skip to main content
GShen.1
Associate II
June 20, 2020
Question

What`s the difference between Transmit_IT function and Transmit function?

  • June 20, 2020
  • 7 replies
  • 4328 views

MCU:STM32F0discovery

Tools:STM32CubeMX5.6.1+Keil5.3

OS: Windows 10pro

Question:

When I use the PLC system`s interrupt, always the interrupt just trigger once in the first scan time.

But in the MCU system, I find that the interrupt can be triggered by the loop cycle.And

when I use the Transmit_IT function and Transmit function as below, I find that the Transmit function couldn`t be used as normal, the CR word couldn`t be printed to the serial handshake software.

Does it mean that the Transmit_IT function and the transmit function use the same transmit memory,and when the transmit function is not hold in the while loop, the transmit function is disable in the communication process.

What`s the attitude about it from sincerely yours?

int main(void)

{

uint8_t CR_message[]="\r\n";

HAL_UART_Receive_IT(&huart1,(uint8_t *)aRxBuffer,10);

while(1)

{

if(huart1.RxState==HAL_UART_STATE_BUSY_RX)

{

Test_Retention=1;

Test_Follow=1;

}

else

Test_Follow=0;

if((Test_Retention==1)&&(Test_Follow==0))

{

HAL_UART_Transmit_IT(&huart1,(uint8_t *)aRxBuffer,sizeof(aRxBuffer));

HAL_UART_Transmit(&huart1,(uint8_t *)CR_message,sizeof(CR_message),10000);

HAL_UART_Receive_IT(&huart1,(uint8_t *)aRxBuffer,10);

Test_Retention=0;

}

}

}

This topic has been closed for replies.

7 replies

TDK
June 20, 2020

The HAL_UART_Transmit and the HAL_UART_Transmit_IT should not be used at the same time. The HAL_UART_Transmit is a blocking function which returns after the operation is complete. The HAL_UART_Transmit_IT is an interrupt-based function which will return immediately, but the peripheral will still be in use.

The return value from these functions will let you know if one is already in use.

"If you feel a post has answered your question, please click ""Accept as Solution""."
GShen.1
GShen.1Author
Associate II
June 21, 2020

Is the interrupt_based function more quick than the blocking function?

berendi
Principal
June 21, 2020

HAL_UART_Transmit_IT() returns more quickly, but it is not reliable.

It uses interrupts in an unspecified way to transmit data.

Hal interrupt handling is very slow, it can eat a significant amount of CPU time even at 115200 baud.

Its documentation neglects to mention that the data buffer must be volatile with static storage duration for it to work reliably.

It's for prototyping only, not suitable for learning about proper embedded programming practices or production use.

GShen.1
GShen.1Author
Associate II
June 21, 2020

Are the states such as HAL_UART_STATE_BUSY_RX and HAL_UART_STATE_BUSY_TX can descript the Interrupt state in the UART?

Or using the Interrupts of UART, It`s pair of Callback functions.

TDK
June 21, 2020

> Is the interrupt_based function more quick than the blocking function?

Not necessarily, but it will free up the CPU. A blocking function is a lot more straightforward. If you can afford to wait for the operation to complete, that's what I'd use.

> Are the states such as HAL_UART_STATE_BUSY_RX and HAL_UART_STATE_BUSY_TX can descript the Interrupt state in the UART?

Yes, those describe the current state. Those states are HAL creations.

> Or using the Interrupts of UART, It`s pair of Callback functions.

Huh?

"If you feel a post has answered your question, please click ""Accept as Solution""."
GShen.1
GShen.1Author
Associate II
June 21, 2020

Is HAL_UART_IRQHandler function to deal with the Tx or Rx?

Is HAL_UART_RxCpltCallback function the pair of HAL_UART_TX_IT function?

TDK
June 21, 2020
The interrupt handles all UART flags, including RXE and TXNE.
RxCpltCallback is called by the interrupt when your transfer completes.
You can open up those functions and look at them to see what they do. HAL is open source.
"If you feel a post has answered your question, please click ""Accept as Solution""."