How to clear UART interrupt psoc4

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
user_3902336
Level 1
Level 1
First like given

Hi,

I do not know why, but I could not clear the interrupt after receiving the first byte.

I've tried in every way I know, but the interruption is occurring every moment (I know that because my led is "blinking" at several Megahertz).

My intention is for an interrupt to occur whenever I receive a byte so that my code handles a request and answer via UART properly.

Best regards,

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I think you had (at least) a couple of problems

(1) as VisonZ_71-san pointed you need to clear using

  UART_ClearRxInterruptSource(

        UART_INTR_RX_FIFO_LEVEL |

        UART_INTR_RX_NOT_EMPTY |

        UART_INTR_RX_FULL ) ;

(2) Even clearing the flag if the status remains, the flag returns.

In this case, you were not consuming the data in the buffer

so  UART_INTR_RX_NOT_EMPTY will never been cleared.

So I modified your ISR as

CY_ISR(ISR_UART)

{

    UART_ClearRxInterruptSource(

        UART_INTR_RX_FIFO_LEVEL |

        UART_INTR_RX_NOT_EMPTY |

        UART_INTR_RX_FULL ) ;

    while(UART_SpiUartGetRxBufferSize()) {

        rx_buf[rx_write_index] = UART_UartGetByte() ;

        rx_write_index = (rx_write_index + 1) % RX_BUF_LEN ;

    }

    ldR_Write(!ldR_Read());

}

and it seems working now.

moto

View solution in original post

2 Replies
Vison_Zhang
Moderator
Moderator
Moderator
First comment on KBA 750 replies posted 250 sign-ins

UART Interrupt sources managed by the user (this category includes any enabled interrupt source which is not reserved by the Component) are not cleared automatically. It is the user’s responsibility to do that. Interrupt sources are cleared by writing a ‘1’ in corresponding bit
position. The Component provides functions to clear interrupt sources (for example:
SCB_ClearRxInterruptSource()).


/* Check if enabled interrupt source is active */
if (0u != (SCB_GetRxInterruptSourceMasked() & SCB_INTR_RX_PARITY_ERROR))
{
/* Clear interrupt source */
SCB_ClearRxInterruptSource(SCB_INTR_RX_PARITY_ERROR);
/* Add user code to handle SCB_INTR_RX_PARITY_ERROR event */
}

lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I think you had (at least) a couple of problems

(1) as VisonZ_71-san pointed you need to clear using

  UART_ClearRxInterruptSource(

        UART_INTR_RX_FIFO_LEVEL |

        UART_INTR_RX_NOT_EMPTY |

        UART_INTR_RX_FULL ) ;

(2) Even clearing the flag if the status remains, the flag returns.

In this case, you were not consuming the data in the buffer

so  UART_INTR_RX_NOT_EMPTY will never been cleared.

So I modified your ISR as

CY_ISR(ISR_UART)

{

    UART_ClearRxInterruptSource(

        UART_INTR_RX_FIFO_LEVEL |

        UART_INTR_RX_NOT_EMPTY |

        UART_INTR_RX_FULL ) ;

    while(UART_SpiUartGetRxBufferSize()) {

        rx_buf[rx_write_index] = UART_UartGetByte() ;

        rx_write_index = (rx_write_index + 1) % RX_BUF_LEN ;

    }

    ldR_Write(!ldR_Read());

}

and it seems working now.

moto