3
\$\begingroup\$

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?

\$\endgroup\$
  • 3
    \$\begingroup\$ Best you set a flag in the ISR and use that flag in the main loop to send the next packet. \$\endgroup\$ – TisteAndii Mar 15 '17 at 23:08
3
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – linkopen Mar 16 '17 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.