2020-06-20 08:18 AM
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;
}
}
}
2020-06-20 10:13 AM
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.
2020-06-20 07:45 PM
Is the interrupt_based function more quick than the blocking function?
2020-06-20 11:17 PM
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.
2020-06-21 02:26 AM
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.
2020-06-21 06:58 AM
> 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?
2020-06-21 07:03 AM
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?
2020-06-21 07:13 AM