Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 1 > How can I debug UART ?

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



How can I debug UART ?
Moderator:
ARVI

Post Reply
Follow this topic



How can I debug UART ?

bianchi posted on 07 Mar 2013 5:53 PM PST
Top Contributor
168 Forum Posts

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




Re: How can I debug UART ?

bianchi posted on 07 Mar 2013 06:14 PM PST
Top Contributor
168 Forum Posts

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



Re: How can I debug UART ?

bianchi posted on 07 Mar 2013 06:23 PM PST
Top Contributor
168 Forum Posts

is it because of baud rate ?

How can I get 9600 baud rate ?

thank you



Re: How can I debug UART ?

arvi posted on 07 Mar 2013 07:00 PM PST
Cypress Employee
119 Forum Posts

 

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.

 

 



Re: How can I debug UART ?

H L posted on 07 Mar 2013 07:00 PM PST
Top Contributor
679 Forum Posts

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.

 



Re: How can I debug UART ?

arvi posted on 07 Mar 2013 07:05 PM PST
Cypress Employee
119 Forum Posts

 

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.

 

 



Re: How can I debug UART ?

bianchi posted on 08 Mar 2013 11:13 PM PST
Top Contributor
168 Forum Posts

is it right for 9600 ?



Re: How can I debug UART ?

bianchi posted on 08 Mar 2013 11:33 PM PST
Top Contributor
168 Forum Posts

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
        }



Re: How can I debug UART ?

bianchi posted on 08 Mar 2013 11:46 PM PST
Top Contributor
168 Forum Posts

9600 baud =

24 Mhz / 8 / 3 /20 =75000 hz

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



Re: How can I debug UART ?

Bob Marlowe posted on 08 Mar 2013 11:57 PM PST
Top Contributor
1768 Forum Posts

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



Re: How can I debug UART ?

bianchi posted on 08 Mar 2013 12:05 AM PST
Top Contributor
168 Forum Posts

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



Re: How can I debug UART ?

H L posted on 08 Mar 2013 05:32 AM PST
Top Contributor
679 Forum Posts

 Re clock:

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

 



Re: How can I debug UART ?

bianchi posted on 08 Mar 2013 05:51 AM PST
Top Contributor
168 Forum Posts

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')

{

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

}



Re: How can I debug UART ?

bianchi posted on 08 Mar 2013 06:02 AM PST
Top Contributor
168 Forum Posts

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;



Re: How can I debug UART ?

bianchi posted on 08 Mar 2013 06:34 AM PST
Top Contributor
168 Forum Posts

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



Re: How can I debug UART ?

H L posted on 08 Mar 2013 02:34 PM PST
Top Contributor
679 Forum Posts

 If you use VC, it would be  8 * 3 * 13 or  8 * 39.

For testing purpose, using VC is Ok, I normally use timer/counter as divider.



Re: How can I debug UART ?

H L posted on 08 Mar 2013 02:40 PM PST
Top Contributor
679 Forum Posts

char UART_cGetChar(void)

Return character from RX Data register when valid data is available. Function does not return until character is received.

 

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 can find these information inside the datasheet of the UART UM.



Re: How can I debug UART ?

bianchi posted on 08 Mar 2013 02:59 PM PST
Top Contributor
168 Forum Posts

to HL

 

why is this "if" doesn't work ?

if(UART_1_cGetChar()=='a')

is it because of the speed ?

 

Thank you mate



Re: How can I debug UART ?

bianchi posted on 08 Mar 2013 03:14 PM PST
Top Contributor
168 Forum Posts

Hi HL,

Any examples for : " I normally use timer/counter as divider."

Thank you



Re: How can I debug UART ?

bianchi posted on 08 Mar 2013 08:45 PM PST
Top Contributor
168 Forum Posts

I sent 'a' to RX buffer but no response:



Re: How can I debug UART ?

Bob Marlowe posted on 09 Mar 2013 01:18 AM PST
Top Contributor
1768 Forum Posts

Hi bianchi,

can you provide us with an actual archive* of your project or even a subset of it that shows the non-working part. Maybe some of your settings in the chip-view are not as required. This will help us to answer several questions at once: How to set up a baud-rate-generator, and getting UART to work.

You did not tell (or I overlooked it) about the hardware you use, is it a PSoC1 developement kit or your own hardware. Do you use RS232-level shifters to meet the desired voltages on youe PC-side?

 

Bob

 

*) to do so: under "File -> Archive Project (complete)" there will be a .Zip archive generated which you may upload here as an attached file.



Re: How can I debug UART ?

bianchi posted on 09 Mar 2013 03:42 AM PST
Top Contributor
168 Forum Posts

Ok I uploaded the complete project,

please have a look,

any suggestions will be very appreciated,

I'm using PSoC 1 and serial port on my laptop.

thank you



Re: How can I debug UART ?

danaaknight posted on 09 Mar 2013 04:46 AM PST
Top Contributor
1773 Forum Posts

An earlier poster was incorrect on this -

 

 

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

 

PRT0DR is the data register for Port 0. The register that controls drive mode is the

following -

 

 

Note PRT0DR |= 0X80; is a read/modify write intruction, and needs to be used

with a shadow register. See following discussion on shadow registers -

http://www.cypress.com/?rID=2900

http://www.cypress.com/?rID=39497

 

Regards, Dana.

 

 



Re: How can I debug UART ?

danaaknight posted on 09 Mar 2013 04:52 AM PST
Top Contributor
1773 Forum Posts

In terms of coding style, if you are pressed for code space and speed,

switch statement may not be best approach, see -

 

http://www.cypress.com/?rID=45644

 

Regards, Dana.



Re: How can I debug UART ?

danaaknight posted on 09 Mar 2013 05:01 AM PST
Top Contributor
1773 Forum Posts

You have CPU_Clock set to SysClk/8, while you are debugging

you might consider SysClk/1. A key reason to set it at a slower

speed, therefore reduced MIPs, is for lower power, but if you have

a lot of code to execute keep the MIPs up until you can establish

you can satisfy all code MIP needs with reduced speed/power.

 

Regards, Dana.



Re: How can I debug UART ?

bianchi posted on 09 Mar 2013 02:29 PM PST
Top Contributor
168 Forum Posts

To Dana,

 

"switch statement may not be best approach, see" -

So better use "if" or you have a better solution ?

strange that, I only do a simple experiment but so hard to implement in cypress.....

a lot easier with AT89S52..



Re: How can I debug UART ?

bianchi posted on 09 Mar 2013 02:30 PM PST
Top Contributor
168 Forum Posts

You have CPU_Clock set to SysClk/8, while you are debugging

you might consider SysClk/1. A key reason to set it at a slower

speed, therefore reduced MIPs, is for lower power, but if you have

a lot of code to execute keep the MIPs up until you can establish

you can satisfy all code MIP needs with reduced speed/power.

 

Regards, Dana.

 

Reply : will it make my UART code working ? or still the same thing ??



Re: How can I debug UART ?

danaaknight posted on 09 Mar 2013 03:17 PM PST
Top Contributor
1773 Forum Posts

With CPU set to SysClk/8, or 3 Mhz, and VC1+ VC2 + VC3 set

to /8/3/13 your baudrate is 9600.

 

So I would think running CPU at 3 Mhz should be OK.

 

My comments on CASE statement were made w/o looking at your project.

Use of CASE is fine in your example project, its when your processor is

heavily loaded one might re-examine use of CASE.

 

When you display characters on LCD they have to be "displayable" characters.

In the case of the Hitachi there are a number of non displayable byte values,

as you can see in this chart. Same is true for a PC acting as a terminal.

 

 

Regards, Dana.



Re: How can I debug UART ?

danaaknight posted on 09 Mar 2013 03:37 PM PST
Top Contributor
1773 Forum Posts

The clock accuracy for a UART, see following -

 

http://www.cypress.com/?rID=39848

 

Regarding BYTE transmission by UART, there is no limitation on what

BYTE value you can send, its up to the Rx end to determine if it is a displayable

ASCII character or a command. As in prior post not all BYTE values can be dis-

played by LCD, but you could convert non displayable characters into a message

with suitable code.

 

Regards, Dana,



Re: How can I debug UART ?

bianchi posted on 09 Mar 2013 05:33 PM PST
Top Contributor
168 Forum Posts

Thanks Dana for the response,

I'll try to re-code again with the simplest thing I want, without any case or something like that,

just send character and detect if there's character from PC ( putty )

It should work otherwise, I can say it's not easy to use cypress processor.....

It's only simple matter and the processor gives me too much trouble to implement...



Re: How can I debug UART ?

bianchi posted on 09 Mar 2013 05:45 PM PST
Top Contributor
168 Forum Posts

I re-code them very simple only send 'a' and receive 'a'.....

 

Hopefully there's response, I'm testing it now

 

#include <m8c.h>        // part specific constants and macros
#include "PSoCAPI.h"    // PSoC API definitions for all User Modules
#include <stdlib.h>


/*---------------------------------------------------------------------------------
void LCD_clr_line(unsigned char j)
function :     clear LCD on line number j (0 or 1)
input         line number j
----------------------------------------------------------------------------------*/
void LCD_clr_line(unsigned char j)
{
    LCD_1_Position(j,0);
    LCD_1_PrCString("                ");
}

void main(void)

    BYTE i;
     
    LCD_1_Start();                // Initialize LCD
    UART_1_CmdReset();                // Reset Command Buffer
    UART_1_Start(UART_1_PARITY_NONE);        // Start UART
    LCD_1_Position(0,0);                // Set LCD position
    LCD_1_PrCString("BaudRate = 9600 ");
    LCD_1_Position(1,0);                // Set LCD position
    LCD_1_PrCString("Enter char a ");
 

    while(1)
    {
       UART_1_CmdReset();            // Reset UART Command Buffer
        for (i=0;i<1;i++)   
        {
            UART_1_PutChar('a'); // Send a character ('a') to UART TX port
        }
       
         UART_1_CmdReset();            // Reset UART Command Buffer
      if (UART_1_cGetChar() =='a')
        {
          LCD_1_Position(0,0);
          LCD_1_PrCString("a char received");
        }
        else
        {
            LCD_1_Position(0,0);       
            LCD_1_PrCString("Cardreader error");
        }
    }
}
 



Re: How can I debug UART ?

bianchi posted on 09 Mar 2013 05:59 PM PST
Top Contributor
168 Forum Posts

I tried both :

char UART_cGetChar(void)

Return character from RX Data register when valid data is available. Function does not return until character is received

int UART_ iReadChar(void)

Read Rx Data register immediately. If data is not available or an error condition exists, return an error status in the MSB. The received char is returned in the LSB.

and both are not working ? is there anything missing here ??? so complicated for accepting only one simple 'a' charactrer ??

 

what's the different with :

BYTE UART_bReadRxData(void)

Return data in RX Data register without checking status of character is valid.

 

only low level and high level API ?



Re: How can I debug UART ?

bianchi posted on 09 Mar 2013 06:04 PM PST
Top Contributor
168 Forum Posts

if I use :

 if (UART_1_cReadChar() =='a')

I got "Card reader error" and character 'a' is being sent into my laptop without stopping...



Re: How can I debug UART ?

bianchi posted on 09 Mar 2013 06:08 PM PST
Top Contributor
168 Forum Posts

how about :

if (UART_1_bReadRxData() == 0x61)
 

?



Re: How can I debug UART ?

danaaknight posted on 09 Mar 2013 06:13 PM PST
Top Contributor
1773 Forum Posts

Thats good news 'a' is showing up on laptop, in fact you are

in a continous while loop sending 'a's, so thats working.

 

Regards, Dana.



Re: How can I debug UART ?

bianchi posted on 09 Mar 2013 07:56 PM PST
Top Contributor
168 Forum Posts

Thats good news 'a' is showing up on laptop, in fact you are

in a continous while loop sending 'a's, so thats working.

 

Regards, Dana.

to Dana

Yup it's working for sending character, but go back to my question, it can't receive 'a' character ?

is there any settings / code that I missed ?

 

It's very simple task and question, so please answer it with something simple too..

Thank you

 



Re: How can I debug UART ?

bianchi posted on 09 Mar 2013 08:09 PM PST
Top Contributor
168 Forum Posts

The chip never does this task :

 if (UART_1_cGetChar() == 'a')
        {
          LCD_clr_line(0);
          LCD_clr_line(1);
          LCD_1_Position(0,0);
          LCD_1_PrCString("a char received");
        }

 

I have no idea why....



Re: How can I debug UART ?

bianchi posted on 09 Mar 2013 08:11 PM PST
Top Contributor
168 Forum Posts

I pushed 'a' character from my keyboard.....and there's no response....



Re: How can I debug UART ?

bianchi posted on 09 Mar 2013 09:10 PM PST
Top Contributor
168 Forum Posts

I tried to test :

  c = UART_1_cGetChar();
          UART_1_PutChar(c);   

 

nothing happened when I press any buttons on my computer ?

I don't understand in this poin, it's already very straight forward.

 



Re: How can I debug UART ?

H L posted on 10 Mar 2013 10:32 PM PST
Top Contributor
679 Forum Posts

 I cannot install desinger 5.3 at home so cannot check your project now.

Do you use the psoc evac kit /board to develope you project or you use your own board?

! would also check the following:

1. connect the  tx output of posc to rx input of psoc ,

  while

   {

    send 1 byte

    read 1 char (use cgetChar)

 print the received char. 

wait 1 second 

}

See if this works or not.

If it doesn't check then check and change your clock sync selection of UART.

Do not use cReadChar or iReadChar for now as it would return immedialy even nothing is received.

 

 



Re: How can I debug UART ?

bianchi posted on 10 Mar 2013 10:50 PM PST
Top Contributor
168 Forum Posts

I'm using PSoC 1 board from cypress



Re: How can I debug UART ?

H L posted on 10 Mar 2013 11:30 PM PST
Top Contributor
679 Forum Posts

 Have you tried the loop back test I suggested.

Here is a project you can check

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



Re: How can I debug UART ?

bianchi posted on 10 Mar 2013 01:13 AM PST
Top Contributor
168 Forum Posts

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



Re: How can I debug UART ?

bianchi posted on 10 Mar 2013 01:28 AM PST
Top Contributor
168 Forum Posts

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



Re: How can I debug UART ?

danaaknight posted on 10 Mar 2013 04:33 AM PST
Top Contributor
1773 Forum Posts

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[i] = 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.

 



Re: How can I debug UART ?

H L posted on 10 Mar 2013 04:40 AM PST
Top Contributor
679 Forum Posts

  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

}



Re: How can I debug UART ?

bianchi posted on 10 Mar 2013 05:06 PM PST
Top Contributor
168 Forum Posts

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

}

 

 



Re: How can I debug UART ?

bianchi posted on 10 Mar 2013 05:11 PM PST
Top Contributor
168 Forum Posts

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[i]); // 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[i] = 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[i]); // 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");
        }
    }



Re: How can I debug UART ?

bianchi posted on 10 Mar 2013 05:15 PM PST
Top Contributor
168 Forum Posts

i'm not sure this :

 

 c = UART_1_cGetChar();

        if (c =='a')

 

working properly...???



Re: How can I debug UART ?

bianchi posted on 10 Mar 2013 05:16 PM PST
Top Contributor
168 Forum Posts

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

thank you



Re: How can I debug UART ?

H L posted on 10 Mar 2013 08:01 PM PST
Top Contributor
679 Forum Posts

 

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.


Re: How can I debug UART ?

bianchi posted on 10 Mar 2013 08:23 PM PST
Top Contributor
168 Forum Posts

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...



Re: How can I debug UART ?

H L posted on 10 Mar 2013 08:40 PM PST
Top Contributor
679 Forum Posts

it is the first tick.

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

 



Re: How can I debug UART ?

bianchi posted on 10 Mar 2013 08:40 PM PST
Top Contributor
168 Forum Posts

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.



Re: How can I debug UART ?

bianchi posted on 10 Mar 2013 08:48 PM PST
Top Contributor
168 Forum Posts

I follow from the schematic :



Re: How can I debug UART ?

bianchi posted on 10 Mar 2013 08:50 PM PST
Top Contributor
168 Forum Posts

P1.6 RX

P2.7 TX



Re: How can I debug UART ?

H L posted on 10 Mar 2013 08:52 PM PST
Top Contributor
679 Forum Posts

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?

 



Re: How can I debug UART ?

bianchi posted on 10 Mar 2013 09:13 PM PST
Top Contributor
168 Forum Posts

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

thanks guys...



Re: How can I debug UART ?

bianchi posted on 11 Mar 2013 10:09 PM PST
Top Contributor
168 Forum Posts

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



Re: How can I debug UART ?

H L posted on 11 Mar 2013 11:41 PM PST
Top Contributor
679 Forum Posts

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.

 



Re: How can I debug UART ?

bianchi posted on 11 Mar 2013 12:53 AM PST
Top Contributor
168 Forum Posts

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



Re: How can I debug UART ?

H L posted on 11 Mar 2013 05:34 AM PST
Top Contributor
679 Forum Posts

 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



Re: How can I debug UART ?

bianchi posted on 11 Mar 2013 06:23 AM PST
Top Contributor
168 Forum Posts

you mean this one ?



Re: How can I debug UART ?

bianchi posted on 11 Mar 2013 06:02 PM PST
Top Contributor
168 Forum Posts

To HL,

 

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

I'm using the software, you suggested me,

Thanks mate



Re: How can I debug UART ?

bianchi posted on 11 Mar 2013 06:04 PM PST
Top Contributor
168 Forum Posts

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



Re: How can I debug UART ?

bianchi posted on 12 Mar 2013 07:53 PM PST
Top Contributor
168 Forum Posts

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..






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20