3 Replies Latest reply on Jun 19, 2019 2:27 AM by KaGa_3938861

    PSoC 5LP UART interrupt is triggering continuously

    KaGa_3938861

      I am working with the PSoC 5LP full duplex UART example, i am using Receiver interrupt to generate the interrupt while receiving characters from UART, but as soon as i start the device, the interrupt is triggering and receiving some junk data, can any one please point out to me where i am going wrong..

       

       

      Image of the UART settings attached below.

       

      ISR handler is as follows:

       

      CY_ISR(RxIsr)

       

      {

         uint8_t count = 0;

        uint8 rxStatus; 

        uint8 rxData; 

        rxStatus = UART_ReadRxStatus();

        

         /* Check if data is received. */

         if((rxStatus & UART_RX_STS_FIFO_NOTEMPTY) != 0u

        {

         /* Read received data */

        rxData = UART_ReadRxData();

         /* Check status on error*/

         if((rxStatus & (UART_RX_STS_BREAK | UART_RX_STS_PAR_ERROR |

        UART_RX_STS_STOP_ERROR | UART_RX_STS_OVERRUN)) != 0u)

        {

        errorStatus |= rxStatus & ( UART_RX_STS_BREAK | UART_RX_STS_PAR_ERROR |

        UART_RX_STS_STOP_ERROR | UART_RX_STS_OVERRUN);

        }

         else

        {

         /* Send data backward */

         if(rxData == 0x08){

         if(count > 0){

        count = count - 1;

        }

        }else if(rxData == 0x0D){ //CARRIAGE_RETURN

         OUT_Data_Buffer[count] = 0x0;

         //break;

        }else if( rxData >= 0x20 ){ // character value greater than SPACE.

         OUT_Data_Buffer[count++] = rxData;

        } 

        }

        }

      }

       

      and This is the ISR settings:

      isr_rx_StartEx(RxIsr);

       

      Other than this i am running USB in parallel, Is there any reason why the receiver interrupt triggers automatically and continuously?

       

       

       

       

       

        • 1. Re: PSoC 5LP UART interrupt is triggering continuously
          BoTa_264741

          Check that isr_rx in Derived mode (not Level mode).

          Use this example as example code:

          Re: UART string reception garbage value

           

          /odissey1

          1 of 1 people found this helpful
          • 2. Re: PSoC 5LP UART interrupt is triggering continuously
            MoTa_728816

            Hi,

             

            For me how to clear interrupt flag is always a head ache as each MCU and/or components requires different methods :-(

             

            And reading your question, I realized that I have not written a program clearing 5LP's UART rx interrupt,.

            So I wrote one for CY8CKIT-059 as my morning exercise ;-)

             

            schematic

            001-schematic.JPG

            main.c

            ================

            #include "project.h"

            #include "stdio.h"

             

            #define TAB '\t'

            #define SPACE ' '

            #define CR  '\r'

            #define LF  '\n'

             

            #define RX_BUF_LENGTH 128

            #define STR_LENGTH 64

             

            volatile char rx_buf[RX_BUF_LENGTH] ;

            volatile int  rx_write_index = 0 ;

            int          rx_read_index = 0 ;

            char          str[STR_LENGTH+1] ;

            int          str_index = 0 ;

             

            void print(char *str)

            {

                UART_PutString(str) ;

            }

             

            int is_delimiter(char c)

            {

                return((c == TAB)||(c == SPACE)||(c == CR)||(c == LF)) ;

            }

             

            CY_ISR(RxIsr)

            {

                usr_rx_int_ClearPending() ;

                if (UART_GetRxBufferSize() > 0) {

                    rx_buf[rx_write_index] = UART_GetByte() ;

                    rx_write_index = (rx_write_index + 1) % RX_BUF_LENGTH ;

                }

            }

             

            void init_hardware(void)

            {

                UART_ClearRxBuffer() ;

                UART_ClearTxBuffer() ;

                usr_rx_int_ClearPending() ;

                usr_rx_int_StartEx(RxIsr) ;

                UART_Start() ;

              

                CyGlobalIntEnable; /* Enable global interrupts. */

            }

             

            void splash(void)

            {

                sprintf(str, "UART ISR Test for 5LP (%s %s)\n", __DATE__, __TIME__) ;

                print(str) ;

            }

             

            int get_string(void)

            {

                int result = 0 ;

                uint8_t c ;

                if (rx_read_index != rx_write_index) { /* there is a char received */

                    c = rx_buf[rx_read_index] ;

                    if (is_delimiter(c)) { /* a string received or null string */

                        str[str_index] = 0 ;

                        result = str_index ;

                        str_index = 0 ;

                    } else {

                        str[str_index++] = c ;

                        if (str_index >= STR_LENGTH) { /* str buffer is full quite here */

                            str[str_index] = 0 ;

                            result = -1 ; /* flag a buffer overflow */

                            str_index = 0 ;

                        }

                    }

                    rx_read_index = (rx_read_index + 1) % RX_BUF_LENGTH ;

                }

                return( result ) ;

            }

             

            void prompt(void)

            {

                print("> ") ;

            }

             

            int main(void)

            {

                init_hardware() ;

              

                splash() ;

             

                prompt() ;

                for(;;)

                {

                    if (get_string()) {

                        print(str) ;

                        print("\n") ;

                        prompt() ;

                    }

                }

            }

            ================

             

            TeraTerm log

            000-TeraTerm-log.JPG

             

            moto

             

            P.S. BTW, You may had better posting a 5LP question to PSoC 5LP MCU Community.

            PSoC 5LP MCU Community

            1 of 1 people found this helpful
            • 3. Re: PSoC 5LP UART interrupt is triggering continuously
              KaGa_3938861

              Thank you for your solution, your interrupt setting helped me to resolve the problem i was facing!!