9 Replies Latest reply on Feb 24, 2016 10:58 PM by JoMe_264151

    help with UART ISR

    userc_40302

      Hi,

         

      Ive been messing around with the UART function..... again. Ive implemented a simple ISR so on RX byte received which when triggered shows pn the LCD a message ISR, just to show it works.

         

      I wanted to use the ISR to fill a buffer because i dont want other code to stop running while the PSoC is polling the uart rx.

         

      I have a simple isr function and was wondering what would be the best way of filling a char array of size maybe 20 with some data in the correct order, then have the ISR exit and return back to code after that.

         

      I can send a string to the PSOC with a  specific start command i.e an 'S' followed by a number but Id need to get that data into an array first before acting on it.

         

      thanks guys

        • 1. Re: help with UART ISR
          BoTa_264741

          Cfcorp,

             

          Attached is another incarnation of a project for reading UART into circular buffer. Use it as you wish
           

          • 2. Re: help with UART ISR
            userc_40302

            Hi again, thanks for the sample code. I have implemented a simple ISR for the rx data byte on the UART module.

               

            It seems to read in data correctly, I am only reading in 8 bytes. I have the interrupt function check a 'flag' on data reception, In the main code I check if the flag is equal to 1 then read in the data. Ive since added an ADC function and I put a 100msec delay in the code. I notice that the delay messes up me reading in data. the delay seem to stall the CPU and misses the data being read, transmitting again seems to mostly work. Have i set up my interrupt incorrectly using the method ive implemented? Or is it that the delay of 100msec will always get in the way?

               

            thanks guys

            • 3. Re: help with UART ISR
              userc_40302

              Hi,

                 

              Ive had some time to look at the UART ISR.

                 

              Ive seen some sample code that may apply and ive tried this routine although it doesn't work.

                 

              I only want to fill a small buffer called UART_Buffer that is a set size of 9 bytes for now.

                 

              it seems like it should work but it unfortunately doesn't

                 

              CY_ISR(Rcvd_byte)
              {
                
                  if(UART_1_ReadRxStatus() & UART_1_RX_STS_FIFO_NOTEMPTY)
                  {
                  UART_Buffer[i++] = UART_1_ReadRxData();
                  }

              • 4. Re: help with UART ISR
                JoMe_264151

                There is something fishy with your interrupt handler. Can you please post your complete project, so that we all can have a look at all of your settings? To do so, use

                   

                Creator->File->Create Workspace Bundle (minimal)
                and attach the resulting file.

                   

                 

                   

                Bob

                • 5. Re: help with UART ISR
                  userc_40302

                  Hi,

                     

                  i have uploaded the project i was working on.

                     

                  thank you

                  • 6. Re: help with UART ISR
                    userc_40302

                    Hi,

                       

                    That code is also missing  CyGlobalIntEnable;

                       

                    Hmm must have deleted it by accident.

                    • 7. Re: help with UART ISR
                      JoMe_264151

                      Yepp, and you overflow your buffer because the variable i is never reset,

                      • 8. Re: help with UART ISR
                        userc_40302

                        Oh yes , i didnt notice that until now.

                           

                        Im still having some issues, ive quickly changed the code. Its difficult to see the contents of the UART_buffer in debug mode.

                           

                        while(UART_1_ReadRxStatus() & UART_1_RX_STS_FIFO_NOTEMPTY & i<=8)

                           

                        {

                           

                        UART_Buffer[i++]  = UART_1_ReadRxData();

                           

                        }

                           

                        i=0;

                        • 9. Re: help with UART ISR
                          JoMe_264151

                          No, that will not work ;-) too fast changed, a loop waiting for 8 chars in the interrupt handler might stall your system.

                             

                          Easiest:

                             

                          Define an Rx buffer > 4 (use 20) and let the PSoC handle it with its internal interrupt. You may inspect GetBufferSize() in main() and see how many bytes are already in the buffer. When there are 8 bytes, you may start to read them off

                             

                           

                             

                          Bob

                          1 of 1 people found this helpful