2 Replies Latest reply on Apr 16, 2019 6:57 PM by MoTa_728816

    How to clear UART interrupt psoc4

    user_3902336

      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,

        • 1. Re: How to clear UART interrupt psoc4
          XiaoweiZ_71

          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 */
          }

          • 2. Re: How to clear UART interrupt psoc4
            MoTa_728816

            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

            1 of 1 people found this helpful