- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
|
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You also need to clear the NVIC in the ISR. As the FIFO not empty signal is level, and the NVIC gets triggered again.
Here is the code that works for me:
void ISR_UART(void)
{
/* Check for "RX fifo not empty interrupt" */
if((UART_HW->INTR_RX_MASKED & SCB_INTR_RX_MASKED_NOT_EMPTY_Msk ) != 0)
{
read_data = UART_HW->RX_FIFO_RD_SILENT;
/* Get the character from terminal */
read_data = Cy_SCB_UART_Get(UART_HW);
/* Clear UART "RX fifo not empty interrupt" */
UART_HW->INTR_RX = UART_HW->INTR_RX & SCB_INTR_RX_NOT_EMPTY_Msk;
NVIC_ClearPendingIRQ(UART_SCB_IRQ_cfg.intrSrc);
/* Update data_received flag */
data_received = 1;
}
else
{
/* Error if any other interrupt occurs */
uart_error = 1;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was just reviewing this code and noticed that there is a bug in the interrupt code. Your use case caused this bug to show up.
The bug is that the RX fifo not empty interrupt is cleared before data is read out of the FIFO. In the code example the FIFO was read directly after the interrupt was cleared which I believe was fast enough to not cause the interrupt to retrigger. In your case you inserted code between the interrupt clear and the actual read, which causes the interrupt to fire again. So the ISR gets entered again which causes it to read out of an empty fifo...
To fix the issue move the interrupt clear code below the read of the FIFO:
read_data = UART_HW->RX_FIFO_RD_SILENT;
/* Get the character from terminal */
read_data = Cy_SCB_UART_Get(UART_HW);
/* Clear UART "RX fifo not empty interrupt" */
UART_HW->INTR_RX = UART_HW->INTR_RX & SCB_INTR_RX_NOT_EMPTY_Msk;
However with this code there is still an issue which causes the interrupt to fire for a different reason I haven't debugged yet. So for your use case to fully work you need to change your ISR to look like:
void ISR_UART(void)
{
/* Check for "RX fifo not empty interrupt" */
if((UART_HW->INTR_RX_MASKED & SCB_INTR_RX_MASKED_NOT_EMPTY_Msk ) != 0)
{
read_data = UART_HW->RX_FIFO_RD_SILENT;
/* Get the character from terminal */
read_data = Cy_SCB_UART_Get(UART_HW);
/* Clear UART "RX fifo not empty interrupt" */
UART_HW->INTR_RX = UART_HW->INTR_RX & SCB_INTR_RX_NOT_EMPTY_Msk;
/* Update data_received flag */
data_received = 1;
}
else
{
/* Error if any other interrupt occurs */
//uart_error = 1;
}
}
I'll post back when I figure how which interrupt is causing the error code to run. My guess is that it is underflow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You also need to clear the NVIC in the ISR. As the FIFO not empty signal is level, and the NVIC gets triggered again.
Here is the code that works for me:
void ISR_UART(void)
{
/* Check for "RX fifo not empty interrupt" */
if((UART_HW->INTR_RX_MASKED & SCB_INTR_RX_MASKED_NOT_EMPTY_Msk ) != 0)
{
read_data = UART_HW->RX_FIFO_RD_SILENT;
/* Get the character from terminal */
read_data = Cy_SCB_UART_Get(UART_HW);
/* Clear UART "RX fifo not empty interrupt" */
UART_HW->INTR_RX = UART_HW->INTR_RX & SCB_INTR_RX_NOT_EMPTY_Msk;
NVIC_ClearPendingIRQ(UART_SCB_IRQ_cfg.intrSrc);
/* Update data_received flag */
data_received = 1;
}
else
{
/* Error if any other interrupt occurs */
uart_error = 1;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for your fast and detailed response!
This is indeed working as expected.
Best regards,
Scott