3

I am using STM32F46ZG NUCLEO discovery board. My code is like:

int main(){
  HAL_UART_Transmit_IT(&huart1, buff, 5);

  while(1)
  {
    do something;
  }
}

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
  HAL_UART_Transmit_IT(&huart1, buff, 5);
}

My code has no RTOS, and I want to continuously transmit the 5 bytes. Once the previous interrupt transmit finishes, I want to transmit 5 bytes right away. So can I just call HAL_UART_Transmit_IT() in its own call back function?

SoreDakeNoKoto
  • 1,635
  • 1
  • 13
  • 22
linkopen
  • 31
  • 1

1 Answers1

3

Sure, just make sure to avoid race conditions and blocking in anything called from an ISR. For example, if HAL_UART_Transmit_IT blocks for buffer space to become available, you must not call it from an ISR as this will almost certainly cause a hang. Also, HAL_UART_Transmit_IT must be reentrant as your interrupt could fire while HAL_UART_Transmit_IT is executing in your main loop. Another option would be to set a flag and handle the transmission somewhere else.

alex.forencich
  • 40,694
  • 1
  • 68
  • 109
  • Thank you for the reply. Setting a flag was what I did initially, but when in the main loop this flag can get processed is random, and I want to first take care of transmitting 4 packets of just 2 words in each packet, and the delay among each packet gets transmitted is even. – linkopen Mar 16 '17 at 13:16