STM8S105C4, are nested interrupts recommended for TIM4 and UART2?
Hello, I am new to ITC. I use a the TIM4 interrupt as a 10ms time base, using a callback function for the SPL interrupt handler INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23).
The callback transmits a UART2 packet to an external device and then waits for a UART2 response packet. The response is received using the UART2_IT_RXNE_OR interrupt and the callback for the SPL interrupt handler INTERRUPT_HANDLER(UART2_RX_IRQHandler, 21).
The default interrupt priorities are used for all interrupts: Level 3 (lowest).
The dev. environment is STVD and STM8 Cosmic compiler.
See the below pseudo code.
Problem:
The while() loop in the TIM4 interrupt routine blocks the UART2_RX interrupt.
Question:
Is it good practice to wait for the UART2 IRQ in the TIM4 interrupt routine? Is a nested interrupt setup a good solution, and how to implement this on the STM8S MCU? Section 6.5.2 in the reference manual is brief. Thank you!
Callback_for_TIM4_UPD_OVF_IRQHandler()
{
/* Disable the UART2_RX interrupt */
UART2->CR2 &= ~UART2_CR2_REN; // disable RX
UART2->CR2 |= UART2_CR2_TEN; // enable TX
UART2_ITConfig(UART2_IT_RXNE_OR, DISABLE);
Send_UART2_packet();
/* Enable the UART2_RX interrupt */
UART2->CR2 &= ~UART2_CR2_TEN; // disable TX
UART2->CR2 |= UART2_CR2_REN; // enable RX
UART2_ITConfig(UART2_IT_RXNE_OR, ENABLE);
while(packet_not_received) /* Loop block the UART2_RX interrupt */
{ }
Process_the_UART2_response();
}