1 2 3 Previous Next 76 Replies Latest reply on Mar 19, 2013 12:31 AM by riko.husin

    How can I send character until there's response ?

    riko.husin

      Friends,

         

      How can I send character until there's response ?

         

      I wanna keep sending "UART_1_PutChar(0x01);" until there's response,

         

      Anyone has idea for it ?

         

      Thank you

         

       

         

      Here's the code :

         

      UART_1_PutChar(0x01);
         

          Delay10msTimes(50);
           
          c = UART_1_cGetChar();
             
            if (c == 0x01)
            {
              UART_1_CPutString("Char 0x01 accepted!");
              LCD_clr_line(0);
              LCD_clr_line(1);
              LCD_1_Position(0,0);                // Set LCD position
              LCD_1_PrCString("Card in ");
           }
           else
            if (c == 0xFE)
           {
              UART_1_CPutString("Char 0xFE accepted!");
              LCD_clr_line(0);
              LCD_clr_line(1);
              LCD_1_Position(0,0);                // Set LCD position
              LCD_1_PrCString("Card out ");
           }

        • 1. Re: How can I send character until there's response ?
          riko.husin

          can I do :

             

          while(c==' ')
              {
               UART_1_PutChar(0x01);
              }

          • 2. Re: How can I send character until there's response ?
            riko.husin

            I tried to implement :

               

               

            Am I putting the right code ?

               

            because I can't get any response eventhough I put if (c !=''), it means RX always empty although I swing the card to the device ? any idea ?

               

            UART_1_PutChar(0x01);
                
                      c = UART_1_cGetChar();
                 
                  if (c !='')
                  {
                    P0_0(1);
                    Delay10msTimes(100);
                    P0_0(0);
                  }

            • 3. Re: How can I send character until there's response ?
              user_1377889

              Bianchi,

                 

              I strongly suggest you to buy an ICE-Cube though it is not a cheap part. The ICE (In-Circuit-Emulator) is able to answer all your Questions within a few seconds and will help you to debug your program / Project within a few minutes so saving you days of trial and reeor. The debug capabilities for PSoC1 are very poor, but the ICE-Cube allows to put breakpoints to any C-line (or asm), inspect or alter variable values watch stack usage and even inspect a trace of the last instructions executed before a breakpoint.

                 

              I could not live without one, I bought mine together with my PSoC1 developement kit.

                 

              There is an actual offer from Cypress witch does not contain the first POD for the CY8C29466, but that would exactly be what you would need, so you ought to take the more expensive one.

                 

              Look at the specs here: http://www.cypress.com/?rID=3411

                 

               

                 

              Bob

              • 4. Re: How can I send character until there's response ?
                user_1377889

                Since you are communicating with an external device and missing an answer from it, there is something amiss.

                   

                1. Can you post your COMPLETE project here, using the "Archive Project" function of Designer 5.3 (and using MS Internet Explorer, not Chrome!) by attaching the .zip with your post.

                   

                2. Do you use (does the card-reader need) a level-shifter for the RS232 signals

                   

                3. Is the card-reader connected via the 9-pin serial interface? If so

                   

                3a. Cable double checked? Compared to the PSoC-Kit schematics?? Jumpers???

                   

                3b. Is the card reader using control signals as CTS and RTS

                   

                 

                   

                As you see: Serial interface is always a vivid source of adventure, measurement and gnawing fingernails...

                   

                 

                   

                Bob

                • 5. Re: How can I send character until there's response ?
                  user_14586677

                  A minor point, change this -

                     

                   

                     

                        if (c == 0x01)
                        {
                          UART_1_CPutString("Char 0x01 accepted!");
                          LCD_clr_line(0);
                          LCD_clr_line(1);
                          LCD_1_Position(0,0);                // Set LCD position
                          LCD_1_PrCString("Card in ");
                       }
                       else
                        if (c == 0xFE)
                       {
                          UART_1_CPutString("Char 0xFE accepted!");
                          LCD_clr_line(0);
                          LCD_clr_line(1);
                          LCD_1_Position(0,0);                // Set LCD position
                          LCD_1_PrCString("Card out ");
                       }

                     

                   

                     

                  to this

                     

                   

                     

                          LCD_clr_line(0);
                          LCD_clr_line(1);
                          LCD_1_Position(0,0);                // Set LCD position

                     

                        if (c == 0x01)
                        {
                          UART_1_CPutString("Char 0x01 accepted!");
                          LCD_1_PrCString("Card in ");
                       }
                       else
                        if (c == 0xFE)
                       {
                          UART_1_CPutString("Char 0xFE accepted!");
                          LCD_1_PrCString("Card out ");
                       }

                     

                   

                     

                  If you do not have a cube, start using your scope to see if your Rx character

                     

                  is present. If its a DSO, many can extract clock to make life easy reading

                     

                  character received. You can also start with a Designer supplied project

                     

                  that is working and modify it bit by bit. When you open Designer, on opening

                     

                  screen, is a group pf example projects in "Design Catalog" window.

                     

                   

                     

                  Regards, Dana.

                  • 6. Re: How can I send character until there's response ?
                    ki.leung

                    Debugging communication software is not easy without ICE and CRO.

                       

                    As others suggest get an ICE or/and a CRO.

                       

                    for the time being.

                       

                    void main (void)

                       

                    {

                       

                    usinged char ucResponse = 0;

                       

                    /*** 

                       

                    all other program to initalize the UART here 

                       

                     

                       

                    ***/

                       

                     

                       

                    whie (1)

                       

                    {

                       

                        ucResponse = 0;

                       

                       LCD_clr_line(0);
                       LCD_clr_line(1);
                       LCD_1_Position(0,0);                // Set LCD position 

                       

                       LCD_1_PrCString("Sending 0x01");

                       

                        do {

                       

                     

                       

                            UART_1_PutChar(0x01);
                        

                            Delay10msTimes(50);
                          

                       

                            /* do a read char, if 0, send 0x01 again, else can start decode the reponse */

                       

                            /* This is assuming RX to the UART is between 1 and 0xFF */

                       


                            ucResponse = UART_1_cReadChar();

                       

                     

                       

                         

                       

                          }while (ucResponse == 0);

                       

                     

                       

                     

                       

                        LCD_clr_line(0);
                        LCD_clr_line(1);
                        LCD_1_Position(0,0);                // Set LCD position 
                     

                       

                        
                        if (ucResponse == 0x01)
                        { 
                           LCD_1_PrCString("Card in ");
                        }
                        else
                        {

                       

                           if (ucResponse == 0xFE)
                           {
                               LCD_1_PrCString("Card Not in ");
                           }

                       

                           else

                       

                           {

                       

                     

                       

                              LCD_1_PrCString("Unknown response ");

                       

                     

                       

                           }

                       

                        }

                       

                        /* Show the screen for 2 seconds */

                       
                             Delay10msTimes(200);   
                       
                        }   
                       
                                     
                    • 7. Re: How can I send character until there's response ?
                      user_1377889

                      @ Dana

                         

                      Good idea!

                         

                      But

                         

                      The first character to send will be swallowed by the Tx buffer and the Putchar() returns. A second character to send would wait (blocking) for the last char beeing transmitted.

                         

                       

                         

                      Bob

                      • 8. Re: How can I send character until there's response ?
                        riko.husin

                        still doesn't work guys,

                           

                        I suspect the reader is not working properly, since I manually try it with Serial com TX and RX, sending it manually to the reader,

                           

                        no response at all.....could be broken card reader...

                        • 9. Re: How can I send character until there's response ?
                          riko.husin

                          Guys,

                             

                           

                             

                          The code has been working until :

                             

                          do {

                             

                           

                             

                                  UART_1_PutChar(0x01);
                              

                                  Delay10msTimes(50);
                                

                             

                                  /* do a read char, if 0, send 0x01 again, else can start decode the reponse */

                             

                                  /* This is assuming RX to the UART is between 1 and 0xFF */

                             


                                  ucResponse = UART_1_cReadChar();

                             

                           

                             

                               

                             

                                }while (ucResponse == 0);

                             

                           

                             

                           

                             

                          but not responding to if

                             

                           

                             

                            if (ucResponse == 0x01)

                             

                           

                             

                          looks like

                             

                          ucResponse = UART_1_cReadChar();

                             

                           not doing its job ??

                             

                           

                             

                          thanks

                          • 10. Re: How can I send character until there's response ?
                            riko.husin

                            I tried to debug it, see below :

                               

                            do {

                             

                                    UART_1_PutChar(0x01);
                               

                                    Delay10msTimes(50);
                                 

                                    /* do a read char, if 0, send 0x01 again, else can start decode the reponse */

                                    /* This is assuming RX to the UART is between 1 and 0xFF */


                                    ucResponse = UART_1_cReadChar();

                               

                                   Delay10msTimes(50);
                                    LCD_clr_line(0);
                                    LCD_clr_line(1);
                                    LCD_1_Position(0,0);                // Set LCD position
                                    LCD_1_PrHexByte(ucResponse);

                              

                             

                                

                                  }while (ucResponse == 0);

                            • 11. Re: How can I send character until there's response ?
                              riko.husin

                              Guys, it's not reading anything,

                                 

                              always displaying 00 on LCD.....

                                 

                              it means

                                 


                                      ucResponse = UART_1_cReadChar();

                                     

                                 

                              is not doing its job.....why is that ????

                              • 12. Re: How can I send character until there's response ?
                                ki.leung

                                If you read the data sheet:

                                   

                                char UART_cReadChar(void)

                                   

                                Read RX Data register immediately. If valid data is not available, return 0, else ASCII char between 1 and 255 is returned.

                                   

                                 

                                   

                                You are getting 0 means valid data is not available. 

                                   

                                Are you using a working card reader?

                                   

                                 

                                   

                                you need to read the data sheet and understand what is going on.

                                • 13. Re: How can I send character until there's response ?
                                  ki.leung

                                   The instuction is doing is job, it is saying that data is not valid.

                                  • 14. Re: How can I send character until there's response ?
                                    riko.husin

                                    I tested card reader with serial port and it's working as it supposed to be....

                                       

                                    I don't understand now.....

                                    1 2 3 Previous Next