Hi,
I am trying to use USART interrupt to get more than 32 bytes message at once, but I am not 100% sure how to do that.
It would be greatly appreciated if anyone could help me to figure out why my code is not working well.
Here is a code snippet.
uint8_t req_msg[BUF_SIZE] = {0, };
size_t req_msg_len = 0;
void DEMO_USART_IRQHandler(void)
{
uint8_t msg[BUF_SIZE] = {0, };
size_t msg_len = 0;
/* If new data arrived. */
while ((kUSART_RxFifoNotEmptyFlag) & USART_GetStatusFlags(DEMO_USART))
{
req_msg[req_msg_len++] = USART_ReadByte(DEMO_USART);
if (req_msg_len >= BUF_SIZE)
{
// error handling
}
}
do_task();
req_msg_len = 0;
// __NVIC_ClearPendingIRQ(DEMO_USART_IRQn);
// USART_ClearStatusFlags(DEMO_USART, kUSART_RxError);
SDK_ISR_EXIT_BARRIER;
}
I want to do a small task within USART ISR, but when I sends more than 16 bytes through USART, it only receives 16 bytes (others are ignored).
Also, sometimes it receives a single USART message (larger than 16 bytes) separately, so USART ISR is triggered twice (first receives 1 byte and second receives next 16 bytes).
That's why I attempted to use __NVIC_ClearPendingIRQ() and USART_ClearStatusFlags() functions (I want to clear the pended interrupt just in case).
Any suggestions or ideas?
FYI, this code is executed in secure world, so I can't use RTOS on it.
Thank you in advance for your support!!!