How can I debug UART ?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

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

0 Likes
65 Replies
Anonymous
Not applicable

I'm using PSoC 1 board from cypress

0 Likes
Anonymous
Not applicable

 Have you tried the loop back test I suggested.

   

Here is a project you can check

   

http://www.cypress.com/?id=4&rID=58574

0 Likes
Anonymous
Not applicable

  while

   

   {

   

    send 1 byte

   

    read 1 char (use cgetChar)

   

 print the received char. 

   

wait 1 second 

   

}

Like this :   

   

while(1)
    {
  
   
    c = UART_1_bReadRxData();
    UART_1_SendData(c);
   }
  

0 Likes
Anonymous
Not applicable

Here is a project you can check

   

http://www.cypress.com/?id=4&rID=58574

   

 

   

I have studied that article but it doesn't include on how to receive one character on the RX port.....

   

does anyone know ?

   

thank you

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

You have interrupts off, basically in a polled mode.

   

 

   

Can you set up a DSO and capture Tx line from PC to PSOC Rx line to see if

   

PC is sending out keyboard character ?

   

 

   

When you use this -

   

 

   

UART_cReadChar

   

   
    
     Description:    
    
     Reads UART RX port immediately if data is not available or an error condition exists, or zero is returned. Otherwise, the character is read and returned.    
   
   

   

 Am I mistaken or does your code read once the character sent to it from PC, then all other

   

time gets no char, so net effect is you have a very low duty cycle write to display of receiving

   

a character, alternated most of the time no character received, net effect is you never see the

   

message chaqracter received on LCD ? Note also you use

   

 

   

            byte_length = UART_1_cReadChar();
            for (i=0;i<byte_length;i++)    {
           
                RxdataBuff = UART_1_cGetChar();    // Get a character from UART RX data register
            }

   

 

   

Does the byte_length = character received a non legit value for use as a index into RxdataBuff ?

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

  while (1)

   

 {

   

/* Send one character via the UART TX */

   

    send 1 byte; (eg  'A')

   

 

   

/* rea one character from the RX of UART*/

   

/* ONLY USE cGetchar(), it would wait forever if not receive */

   

 

   

    read 1 char (use cgetChar)

   

 

   

/* print the received charater on LCD, any location would do */

   

     print the received char. to LCD line 1 colum 0

   

 

   

/* a little bit of delay */

   

   wait 1 second 

   

 

   

/* print another charter to LCD 1,0 so if a new character is receive */

   

/* if would be noticed */

   

  print a leter 'B' to LCD line 1,colum 0

   

}

0 Likes
Anonymous
Not applicable

can you write it in a real code please ? I can't guess what you mean

   

 

   

 while (1)

   

 {

   

/* Send one character via the UART TX */

   

    send 1 byte; (eg  'A')

   

 

   

/* rea one character from the RX of UART*/

   

/* ONLY USE cGetchar(), it would wait forever if not receive */

   

 

   

    read 1 char (use cgetChar)

   

 

   

/* print the received charater on LCD, any location would do */

   

     print the received char. to LCD line 1 colum 0

   

 

   

/* a little bit of delay */

   

   wait 1 second 

   

 

   

/* print another charter to LCD 1,0 so if a new character is receive */

   

/* if would be noticed */

   

  print a leter 'B' to LCD line 1,colum 0

   

}

0 Likes
Anonymous
Not applicable

while(1)
    {
        PRT0DR |=  0X80;
        while(PRT0DR & 0X80)         //Test tag detect signal
        {                //  low level indicating tag in detection range;
            LCD_1_Position(0,0);        //  high level indicating tag out.
            LCD_1_PrString(Notag_Str);    // Print "No tag" on the LCD  ;
        }
       
        UART_1_CmdReset();            // Reset UART Command Buffer
        //for (i=0;i<4;i++)   
        for (i=0;i<1;i++)   
        {
            UART_1_PutChar('a'); // Send a character ('a') to UART TX port
            //UART_1_PutChar(sel_card); // Send a character to UART TX port
            //UART_bReadTxStatus();
        }
         UART_1_CmdReset();            // Reset UART Command Buffer
         c = UART_1_cGetChar();

        if (c =='a')
       
        {
          LCD_1_Position(0,0);
          LCD_1_PrCString("a char received");
           
            byte_length = UART_1_cGetChar();
          for (i=0;i<byte_length;i++)
            {
                RxdataBuff = UART_1_cGetChar();    // Get a character from UART RX data register
                 
            }           
            LCD_1_Position(0,0);
            LCD_1_PrCString("a char received");
            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); // Print serial number of the card detected
                    }                   
                    break;
               
                case 'b':
                    LCD_1_PrString(Notag_Str);      // Print "No tag" on the LCD  ;
                    LCD_clr_line(1);
                    break;
                case 'c':
                    LCD_1_PrString(Colli_Str);      // Print "Collision occur" on the LCD  ;    
                    LCD_clr_line(1);
                    break;
                case 'd':
                    LCD_1_PrString(Chksm_Str);      // Print "Checksum error" on the LCD  ;    
                    LCD_clr_line(1);
                    break;
                      
            }
        }
        else
        {
            LCD_1_Position(0,0);       
            LCD_1_PrCString("Cardreader error");
        }
    }

0 Likes
Anonymous
Not applicable

i'm not sure this :

   

 

   

 c = UART_1_cGetChar();

        if (c =='a')

   

 

   

working properly...???

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Please give a test drive if you guys have a time....

   

thank you

0 Likes
Anonymous
Not applicable
    A failure in embedded system can be due to software and hardware.   
   
        
   
    In your case, The problem can be   
   
        
   
                    The pin is not connected,   
   
                    The pin is in wrong I/O type   
   
                    The pin is dead   
   
                    The UART is not wire to the correct pin in the designer   
   
                    The UART is not started   
   
                    The UART is set with wrong clock   
   
                    The UART is set with wrong baud rate   
   
                    The UART is set with wrong data bit rate   
   
                    The UART is set with wrong stop bits   
   
                    The UART clock source is not the right sync type   
   
                    The UART digital block is faulty   
   
                    The RS232 chip is faulty.   
   
                      
   
                    The data send from the PC is not what your think it is   
   
                    API used is wrong type   
   
                    ….   
   
                    ….   
   
        
   
    You need to isolate the problem one at a time, as there can be multiple failure. You have to build your project one bit at a time from the bottom up.   
   
        
   
    Without a known working hardware, there is no way to check if your software works or not .   
   
        
   
    Since you can send an ‘a’ to the PC means that your baud rate, the data bit and the stop bit most likely to be correct.   
   
        
   
    So it is the receiving side you have to work on.   
   
        
   
    I didn’t give you the exact C code because you need to know what to use by studying the data sheet and from C manual, and that should give you an idea what it is expected to do. And that is what embedded designer needs to learn.   
   
        
   
    I would use a CRO to check the input to the psoc pin but as you don’t have one, we just need to do it in a different way.   
   
        
   
    If you use a loop in receiving only. You should be able to receive something, if it doesn’t I would check the wiring and the signal to the PSOC input pin and the configuration of the UART.     
   
        
   
    PSoC is a good chip to use once your master it.   
0 Likes
Anonymous
Not applicable

it's better if there's a practical example of receiving character,

   

since I can send already.....but I can't receive I'm sure the wire connection is right...

   

P2.7 to TX and P1.6 to RX  J13 female header...

0 Likes
Anonymous
Not applicable

it is the first tick.

   

Did you check if there is a correct RS232 signal to your PSoC RX pin?

0 Likes
Anonymous
Not applicable

I tried  the code :

   

 UART_1_CPutString("Testing UART");
    c = UART_1_cGetChar();
    while (c !='')
    {
       
        UART_1_PutChar(c);
    }

   

 

   

I don't understand why cGetChar() doesn't give me any response.....big question mark,  I check all the parameter and they're all fine.

   

0 Likes
Anonymous
Not applicable

I follow from the schematic :

   

0 Likes
Anonymous
Not applicable

P1.6 RX

   

P2.7 TX

   

0 Likes
Anonymous
Not applicable

If there is no correct 232 signal at the input pin, even if your software is correct, it will not receive.

   

Can you check if your have the correct 232 signal on the RX pin of the PSoC?

0 Likes
Anonymous
Not applicable

Got the answer, I must press Enter after I put the character, it works now,

   

thanks guys...

0 Likes
Anonymous
Not applicable

How can I get the character without pressing enter ?

   

I need it for detecting card :

   

while(1)
    {
    UART_1_CmdReset();            // Reset UART Command Buffer
    
    //Put command to card
    UART_1_PutChar(0x01);

    
    
    c = UART_1_cGetChar();  // how can I take it without waiting for enter button ?
    
      if (c == 0x01)
      {
        LCD_clr_line(0);
        LCD_clr_line(1);
        LCD_1_Position(0,0);                // Set LCD position
        LCD_1_PrCString("Card in ");
     }
     else
     {
        LCD_clr_line(0);
        LCD_clr_line(1);
        LCD_1_Position(0,0);                // Set LCD position
        LCD_1_PrCString("Card out ");
     }
    
   }

0 Likes
Anonymous
Not applicable

You mean you need to press ENTER on your laptop to send the 'a' to the PSOC?

   

I do not use putty so not sure if that can be change, I use realTerm which is a very flexible terminal software. Have a look.

0 Likes
Anonymous
Not applicable

You mean you need to press ENTER on your laptop to send the 'a' to the PSOC?

   

I do not use putty so not sure if that can be change, I use realTerm which is a very flexible terminal software. Have a look.

    Reply :
   

   

Yup, I need to press ENTER in putty to send character.

   


   

How can I receive character without ENTER ? because it's sent from a RFID reader ...

   

I send a command then the reader will send response which will be received by Cypress (RX) UART_1_cGetChar(), I can't use ENTER button in this point

0 Likes
Anonymous
Not applicable

 I think you are using putty to test your program, so I suggest to try realterm because it can send one charater at a time without needing to press ENTER. 

   

I understand that your RFID would resonponse an 'a'.

   

My suggestion is to use a terminal software so you can control when to send and what to send to your psoc. Once you debug your software and works in a control way using a terminal software. you can use the true RFID to test.

   

However, it doesn't matter now as you already fix your software. 

   

Happy coding

0 Likes
Anonymous
Not applicable

you mean this one ?

   

0 Likes
Anonymous
Not applicable

To HL,

   

 

   

It's responding to 0x01, but not responding immediately, why is that ?

   

I'm using the software, you suggested me,

   

Thanks mate

0 Likes
Anonymous
Not applicable

The code :

   

 

   

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 ");
     }

0 Likes
Anonymous
Not applicable

I manually tested the RFID module through serial port,

   

it is not working, that's why I can't send command via my PSoC 1 board..

0 Likes