1 2 3 Previous Next 62 Replies Latest reply on Mar 12, 2013 9:53 PM by riko.husin

    How can I debug UART ?

    riko.husin

      Guys,

         

       

         

      How can I see that UART is sending and receiving my command in PSoC designer ?

         

      and what's the meaning of :

         

      PRT0DR |=  0X80;
              while(PRT0DR & 0X80)    

         

       

         

      any helps will be appreciated,

         

      thank you

        • 1. Re: How can I debug UART ?
          riko.husin

          I tried to send character :

             

          BYTE sel_card[4]={0xAB,0x02,0x01}; 

             

          for (i=0;i<3;i++)   
                  {
                      UART_1_PutChar(sel_card[i]); // Send a character to UART TX port
                  }

             

          and see in putty....it's sending something

             

          • 2. Re: How can I debug UART ?
            riko.husin

            is it because of baud rate ?

               

            How can I get 9600 baud rate ?

               

            thank you

            • 3. Re: How can I debug UART ?
              arvi

              Hi,

                 

               

                 

              You will need to send characters in ascii format to see it on the terminal.

                 

               

                 

              For example,

                 

               UART_1_PutChar('A');

                 

              or UART_1_PutChar(0x41); // Hex

                 

              or UART_1_PutChar(65); // Dec

                 

               

                 

              all will display single character A on your terminal.

                 

               

                 

              Pls refer to the ASCII table

                 

                 

               

                 

              Make sure to convert your array elements to ascii using this table before displaying.

              • 4. Re: How can I debug UART ?
                ki.leung

                When you place the UART, there is a clock source selection, select the one the you want to use as the clock source, it can be one of the VC1, VC@ and VC3, or from other row input or outputs. the clock should be 8 times the baud rate, and you need to start the UART specifying the parity as well.

                • 5. Re: How can I debug UART ?
                  arvi

                  PRT0DR |=  0X80;
                          while(PRT0DR & 0X80)  

                     

                   

                     

                  What is the intention of this code?

                     

                   

                     

                  PRT0DR is the Port0 data register. 

                     

                   

                     

                  If your Port 0, Pin 7 is configured as output, above code will cause an infinite loop.

                     

                   

                     

                  Most probably, I think it's set to Pull up drivemode, and the first statement enables the pullup.

                     

                  The seconds line waits till it detects pin7 has been pulled down by an external switch/input.

                  • 6. Re: How can I debug UART ?
                    riko.husin

                    is it right for 9600 ?

                       

                    • 7. Re: How can I debug UART ?
                      riko.husin

                      If I want to send :

                         

                      AB 02 01 ? how can I do that ?

                         

                      Please correct me if I'm wrong :

                         

                      BYTE sel_card[3]={0xAB,0x02,0x01};

                         

                          UART_1_CmdReset();                // Reset Command Buffer
                          UART_1_Start(UART_1_PARITY_NONE);        // Start UART

                         

                          UART_1_CmdReset();

                         

                      for (i=0;i<3;i++)   
                              {
                                 
                                  UART_1_PutChar(sel_card[i]); // Send a character to UART TX port
                              }

                      • 8. Re: How can I debug UART ?
                        riko.husin

                        9600 baud =

                           

                        24 Mhz / 8 / 3 /20 =75000 hz

                           

                        baud = 75000 Hz / 8 nearly 9600, is my calculation right ?

                           

                        • 9. Re: How can I debug UART ?
                          user_1377889

                          The datasheet is not quite clear at this point, but I think you have to check the UART_bReadTxStatus() to see if the transmit-buffer is empty and may receive another character for transmission.

                             

                           

                             

                          Bob

                          • 10. Re: How can I debug UART ?
                            riko.husin

                            I want to create this logic :

                               

                             

                               

                               

                             

                               

                            Please correct me if I'm wrong :

                               

                            BYTE sel_card[1]={0x01};      // Select Mifare card command  return 10 bytes

                               

                                    for (i=0;i<1;i++)   
                                    {
                                       
                                        UART_1_PutChar(sel_card[i]); // Send a character to UART TX port
                                    }

                                    if(UART_1_cGetChar()==0x01)
                                    {
                                        byte_length = UART_1_cGetChar();
                                        for (i=0;i<byte_length;i++)
                                        {
                                            RxdataBuff[i] = UART_1_cGetChar();    // Get a character from UART RX data register
                                        }           
                                        LCD_1_Position(0,0);
                                        switch(RxdataBuff[1])            // Check status byte
                                        {
                                            case 0x02:            // If 0x00 : Operation success
                                                LCD_1_PrString(Cardf_Str);    // Print "Card selected" on the LCD  ;
                                                LCD_1_Position(1,0);
                                                LCD_1_PrCString("SN: ");
                                                for (i=2;i<6;i++)
                                                {           
                                                    LCD_1_PrHexByte(RxdataBuff[i]); // Print serial number of the card detected
                                                }                   
                                                break;
                                            case 0x01:
                                                LCD_1_PrString(Notag_Str);      // Print "No tag" on the LCD  ;
                                                LCD_clr_line(1);
                                                break;
                                            case 0x0A:
                                                LCD_1_PrString(Colli_Str);      // Print "Collision occur" on the LCD  ;    
                                                LCD_clr_line(1);
                                                break;
                                            case 0xF0:
                                                LCD_1_PrString(Chksm_Str);      // Print "Checksum error" on the LCD  ;    
                                                LCD_clr_line(1);
                                                break;                           
                                        }
                                    }

                            • 11. Re: How can I debug UART ?
                              ki.leung

                               Re clock:

                                 

                              You divider is around 2.4% off. your divider is 8 * 2 *20 = 320, I would try divider ot 312. 

                              • 12. Re: How can I debug UART ?
                                riko.husin

                                What's the different between :

                                   

                                 

                                   

                                UART_1_cReadChar() =='a'

                                        UART_1_cGetChar()=='a'

                                   

                                 

                                   

                                I can see it sends character already with

                                   

                                UART_1_PutChar('a');

                                   

                                 

                                   

                                but when I used putty and send it to the board,

                                   

                                it didn't response to :
                                if (UART_1_cReadChar() =='a')

                                   

                                {

                                   

                                .....................

                                   

                                }

                                • 13. Re: How can I debug UART ?
                                  riko.husin

                                  why is this "if" doesn't work ?

                                     

                                  if(UART_1_cGetChar()=='a')
                                          {
                                              byte_length = UART_1_cGetChar();
                                                         for (i=0;i<byte_length;i++)
                                              {
                                                  RxdataBuff[i] = UART_1_cGetChar();    // Get a character from UART RX data register
                                                 
                                              }           
                                              LCD_1_Position(0,0);
                                              switch(RxdataBuff[1])            // Check status byte
                                              {    
                                                    case 'a':
                                                                    LCD_1_PrString(Cardf_Str);    // Print "Card selected" on the LCD  ;
                                                      LCD_1_Position(1,0);
                                                      LCD_1_PrCString("SN: ");
                                                      for (i=2;i<6;i++)
                                                      {           
                                                          LCD_1_PrHexByte(RxdataBuff[i]); // Print serial number of the card detected
                                                      }                   
                                                      break;

                                  • 14. Re: How can I debug UART ?
                                    riko.husin

                                    to HL, how can you make it 312 ???

                                    1 2 3 Previous Next