9 Replies Latest reply on Dec 8, 2014 7:23 AM by devendra.gajjar

    how to use uart for getting 32bytes data

    devendra.gajjar

      here  is my code i am trying to get 32 bytes by uart when it is sent from other mcu    .
      this data is used for further process.
      my cy conroller will wait for this 32 bytes data train and whenever it come interrupt is  triggered and it will be stored and it will again wait for another 32 bytes data..





      void main(void)
      {  
       
       
      M8C_EnableGInt ;
      UART_1_Start(UART_PARITY_NONE);
      SPIM_1_Start(SPIM_1_SPIM_MODE_0 | SPIM_1_SPIM_MSB_FIRST);


      start:
      UART_1_Start(UART_PARITY_NONE);
      UART_1_CPutString("\r\nSTART\r\n");
      a=0;x=0;
      LED_3_Switch(0x01);
      UART_1_IntCntl(UART_1_ENABLE_RX_INT);

      while(!x);


      goto start;
      /*

      */
       }

      void UART_1_RX_ISR_C(void)
      {UART_1_CPutString("\r\n*I*\r\n");
       LED_4_Switch(0x00);
          a=0;
          rpt:    
          if(UART_1_bReadRxStatus() & UART_1_RX_COMPLETE )
          {
                  cUARTData1[a]=UART_1_cReadChar();
                   a++;
                   LED_4_Switch(0x01);
                  }
                  if(a<32){goto rpt;}
                  LED_3_Switch(0x00);
                  for(b=0;b<32;b++)
                  {
                   UART_1_PutChar(cUARTData1[b]);
                  }


                  

      x=1;
      return;  


              
       }


       

        • 1. Re: how to use uart for getting 32bytes data
          devendra.gajjar

          it is not working pls help me how to get 32bytes?

          • 2. Re: how to use uart for getting 32bytes data
            user_1377889

            Some comments on your code:

               

            In your interrupt handler you wait for the arrival of some more bytes. Depending on the UART's baud-rate this will take some time during which the CPU can not respond. Quite easier is to set a flag in the handler or a count which indicates that or how many bytes have been received. Poll for that flag in the main-loop (which you did not yet program)

               

            You have written no comments, who is to understand what you have done and judge whether it is good or bad if he/she cannot understand easily what you intend to do.

               

            You are using "goto"s. that is bad programming technique and usually can (and should) be avoided. Only for some performance issues it is tolerated to use "goto".

               

            As an example a program in the embedded world looks prinzipially alike (Pseudo code)

               

            Declarations;

               

            main(void)

               

            {

               

                Initialize Hardware();

               

                while(forever)     // *** Main program loop ***

               

                {

               

                    if(FlagIsSet())

               

                    {

               

                        ReactOnFlag();

               

                        ResetFlag();

               

                    }

               

                }    // End-of-Main-Loop

               

            }

               

             

               

            Helpful to detect any issues will be when you post your complete project. To do so, use Designer -> File -> Archive Project and attach the resulting file with the next post. What hardware and which equipment do you use for your project?

               

             

               

             

               

            Bob

            • 3. Re: how to use uart for getting 32bytes data
              user_1377889

              You have got probably 30°C more than we have got here outdoors, so sometimes some more action is required to stay from freezing-in ;-)

                 

              Do not get impatient when it takes an hour to get answered, this is a developer's forum and not a help-desk.

                 

               

                 

              Bob

              • 4. Re: how to use uart for getting 32bytes data
                devendra.gajjar

                here i have made some change in my program

                   

                but still my controller is not exiting from interrupt

                   

                 

                   

                pls guide  me how to exit from interrupt.

                   

                i have also attched my project..

                   

                void main(void)
                {  

                   

                //system  Initialize
                 

                   

                  UART_1_CmdReset();   
                  M8C_EnableGInt ;
                  UART_1_Start(UART_PARITY_NONE);
                  UART_1_IntCntl(UART_1_ENABLE_RX_INT);
                 

                   

                   // *** Main program loop ***
                 

                   

                while(1)
                {
                 UART_1_CPutString("\r\nSTART\r\n");
                 a=0;x=0;    //reseting  flag x and a
                 

                   

                while(!x);  //waiting for intrupt trigrred
                    

                   

                        /*sending  back recived data*/
                for(b=0;b<32;b++)
                            {
                             UART_1_PutChar(cUARTData1[b]);
                            }

                UART_1_CPutString("\r\nend\r\n");
                 

                   

                }
                }


                void UART_1_RX_ISR_C(void)//interrupt handler routine
                {   
                             for(a=0;a<32;)     //for loop for getting 32bytes from uart
                              { 

                   

                                  if(UART_1_bReadRxStatus() & UART_1_RX_COMPLETE )//  UART_1_RX_COMPLETE=0x10
                                   {

                   

                                  cUARTData1[a]=UART_1_cReadChar();
                                  a++;
                                  
                                 }
                            }
                        x=1;//setting flag
                return;
                        
                 }

                 

                • 5. Re: how to use uart for getting 32bytes data
                  user_1377889

                  As I said, please use "Designer -> File -> Archive Project" to create a complete project archive.

                     

                  It is very frustrating to go through a code snipped without the help of the IDE.

                     

                   

                     

                  Bob

                  • 6. Re: how to use uart for getting 32bytes data
                    user_14586677

                    This ap note discusses setting up interrupts in PSOC 1.

                       

                    Pay particular attention to the vector modification you

                       

                    have to do in boot.tpl, in root directory of your project.

                       

                     

                       

                    www.cypress.com/

                       

                     

                       

                    Regarding the use of GOTO -

                       

                     

                       

                        

                       

                             

                       

                    http://stackoverflow.com/questions/245742/examples-of-good-gotos-in-c-or-c

                       

                    http://www.cprogramming.com/tutorial/goto.html

                       

                     

                       

                     

                       

                    Regards, Dana.

                    • 7. Re: how to use uart for getting 32bytes data
                      devendra.gajjar

                      i have done change in boot.tpl as per below.

                         

                      uart is palced on dcc03 block

                         

                      actuly

                         

                      here intruppt is trigrred but my controller is not exit from   intruppt subroutine ..

                         

                       

                         

                       

                         

                      org   28h                      ;PSoC Block DCC02 Interrupt Vector
                          `@INTERRUPT_10`
                          reti

                          org   2Ch                      ;PSoC Block DCC03 Interrupt Vector
                          ljmp    _UART_1_RX_ISR_C
                          reti
                          
                          org   30h                      ;PSoC Block DBC10 Interrupt Vector
                          `@INTERRUPT_12`
                          reti

                      • 8. Re: how to use uart for getting 32bytes data
                        user_14586677

                        void UART_1_RX_ISR_C( void ) { 
                           
                            for( a = 0; a < 32 ; ) {                                             //for loop for getting 32bytes from uart
                               
                                if( UART_1_bReadRxStatus( ) & UART_1_RX_COMPLETE ) {
                                   
                                    cUARTData1[ a ] = UART_1_cReadChar( );
                                    a++;
                                }
                            }

                            x=1;
                            return;
                         }

                           

                         

                           

                        The way this loop will not exit is if "a" does not reach 32. So is

                           

                        host not sending 32 bytes, or is host baudrate not correct ?

                           

                         

                           

                        You have cmd buffer enabled and Rx buff set to 8, even though

                           

                        you are trying to process incoming stream one byte at a time ?

                           

                         

                           

                        There is a project, CE54939, in the example projects that implements

                           

                        a cmd based UART link you might take a look at.

                           

                         

                           

                        Regards, Dana.

                        1 of 1 people found this helpful
                        • 9. Re: how to use uart for getting 32bytes data
                          devendra.gajjar

                          thanks dana.

                             

                          thanks bob

                             

                           i cleared intruppt controller regester manualy now it is working ok 

                             

                          i write down in the end of subroutine as per bellow

                             

                          INT_CLR0=0x00;
                          INT_CLR1=0x00;
                          INT_CLR2=0x00;
                          INT_CLR3=0x00;

                             

                          now it is doing well.