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 tried to send character :

   

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

   

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

   

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

   

0 Likes
Anonymous
Not applicable

is it because of baud rate ?

   

How can I get 9600 baud rate ?

   

thank you

0 Likes
ArvindK_86
Employee
Employee
10 sign-ins 5 sign-ins 10 solutions authored

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.

0 Likes
Anonymous
Not applicable

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.

0 Likes
ArvindK_86
Employee
Employee
10 sign-ins 5 sign-ins 10 solutions authored

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.

0 Likes
Anonymous
Not applicable

is it right for 9600 ?

   

0 Likes
Anonymous
Not applicable

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); // Send a character to UART TX port
        }

0 Likes
Anonymous
Not applicable

9600 baud =

   

24 Mhz / 8 / 3 /20 =75000 hz

   

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

   

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
Anonymous
Not applicable

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

0 Likes
Anonymous
Not applicable

 Re clock:

   

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

0 Likes
Anonymous
Not applicable

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

   

{

   

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

   

}

0 Likes
Anonymous
Not applicable

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 = 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); // Print serial number of the card detected
                    }                   
                    break;

0 Likes
Anonymous
Not applicable

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

0 Likes
Anonymous
Not applicable

 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.

0 Likes
Anonymous
Not applicable

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.

0 Likes
Anonymous
Not applicable

to HL

   

 

   

why is this "if" doesn't work ?

   

if(UART_1_cGetChar()=='a')

   

is it because of the speed ?

   

 

   

Thank you mate

0 Likes
Anonymous
Not applicable

Hi HL,

   

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

   

Thank you

0 Likes
Anonymous
Not applicable

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

   

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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.

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

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

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

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.

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

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.

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

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.

0 Likes
Anonymous
Not applicable

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

0 Likes
Anonymous
Not applicable

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

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

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.

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

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,

0 Likes
Anonymous
Not applicable

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

0 Likes
Anonymous
Not applicable

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

0 Likes
Anonymous
Not applicable

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 ?

0 Likes
Anonymous
Not applicable

if I use :

   

 if (UART_1_cReadChar() =='a')

   

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

   

0 Likes
Anonymous
Not applicable

how about :

   

if (UART_1_bReadRxData() == 0x61)
 

   

?

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

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.

0 Likes
Anonymous
Not applicable

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

0 Likes
Anonymous
Not applicable

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

0 Likes
Anonymous
Not applicable

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

0 Likes
Anonymous
Not applicable

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.

0 Likes
Anonymous
Not applicable

 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.

0 Likes