cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

abho_4730071
New Contributor II

Hi Team,

I am using serial port- DB9 connection. I am using below code. But i am getting the below output.

int main(void)

{

    uint8_t c;

   

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

    UART_PutString("\x1b[2J\x1b[;H") ; /* clear screen */

    UART_PutString("This is an ECHO program\n\r") ;

   

    for (;;) {

      c= UART_GetChar();

    if(c=='L')

    UART_PutString("Light");

    else

    UART_PutString("Dark");

        //if (UART_GetRxBufferSize() > 0) { /* received some data */

       //     c = UART_GetByte() ;

       //     if ((c != 0) && (c != 0xFF)) {

               // UART_PutChar(c) ;

        //    }

      //  }

    }

}

pastedImage_0.png

0 Likes
1 Solution
MotooTanaka
Esteemed Contributor

Hi,

> I write the below code. When i type any code the LED is turned off and also 'L' the LED is not turning on.

> Working fine but while getting character to teraterm is not working.The character are unrecognized.

I assume that you used my sample code attached in my previous response,

namely "uart_test_050_200730", right?

I could not understand why LED does not turned on/off, then I noticed that in that project I was not connecting LED.

Meantime, about the printed letters, your tera term setting may be wrong.

The following is my Tera Term Setting(s).

Menu: Setup > Terminal...

003-TeraTerm-Terminal-setup.JPG

Menu: Setup > Serial Port...

Note: As you know, Port may be different depending on the environment.

004-TeraTerm-Serial-port-setup.JPG

And my Tera Term output is

000-TeraTerm-log.JPG

Meantime to take care of LED, I modified the project as below.

schematic

001-schematic.JPG

pins

002-Pins.JPG

main.c

===========================

#include "project.h"

#define LED_ON 1u

#define LED_OFF 0u

int main(void)

{

    uint8_t c ;

   

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

    UART_PutString("\x1b[2J\x1b[;H") ; /* clear screen */

    UART_PutString("This is an ECHO program\n\r") ;

   

    for(;;)

    {

        if (UART_GetRxBufferSize() > 0) { /* received some data */

            c = UART_GetByte() ;

            if ((c != 0)&&(c != 0xFF)) {

                if ((c == 'L') || (c == 'l')) {

                    LED_Write(LED_ON) ;

                    UART_PutString("Light\n\r") ;

                } else if ((c == 'D') || (c == 'd')) {

                    LED_Write(LED_OFF) ;

                    UART_PutString("Dark\n\r") ;

                }

            }

        }

    }

}

===========================

moto

View solution in original post

0 Likes
15 Replies
Swathi
Moderator
Moderator

Hello,

Please have a look at the attached example project. Make the corrections in the API commands as per the Example code. Make sure that you have configured the Serial Terminal's (TeraTerm) Baud rate same as that of the UART component's Baud rate. Also, right click on the UART module on the schematic to find the component datasheet for more information.

Regards,

Swathi

Best Regards,
Swathi
0 Likes
abho_4730071
New Contributor II

Hi Swathi,

I am getting below error.

When i tried to find the device in device selector i could not found this device.

pastedImage_0.png

0 Likes
Swathi
Moderator
Moderator

Hi,

You got that error because the code example was for PSoC 4 device. Looking at the error message, I realised that you are using PSoC 5LP device, so, I have attached an example code compatible with PSoC 5LP. Please follow all the instructions in the pdf document provided along with the project.

The example project attached, displays the transmitted characters on the Serial Terminal as well as on the LCD. Let me know if it works.

Regards,

Swathi

Best Regards,
Swathi
0 Likes
MotooTanaka
Esteemed Contributor

Hi,

UART_GetChar() returns something, even if it has note received data.

So I used a test to check any incoming data arrived, which you commented out.

     if (UART_GetRxBufferSize() > 0) { /* received some data */

Meantime, in case data is not valid or some errro happens,

UART_GetChar() tends to return 0 or 0xFF, in my experience,

so I wrote below, which you also commented out

c = UART_GetByte() ;

if ((c != 0) && (c != 0xFF)) {

UART_PutChar(c) ;

}

After all, if you want to write Dark or

    for (;;) {

          if (UART_GetRxBufferSize() > 0) { /* received some data */

          c = UART_GetByte() ;

          if ((c != 0) && (c != 0xFF)) {

               if ((c == 'L') || (c == 'l')) {

                    UART_PutString("Light") ; // I wonder if this should be "Light\n\r"

               } else {

                    UART_PutString("Dark") ; // again, could be "Dark\n\r"

               }

           }

  }

    }

moto

P.S. And as I have asked you not a once, please try a loop-back test to make sure that PC to DB9 path is working.

To do that you short the TXD and RXD of your USB-Serial Converter and check if what you are typing are echoed back to the PC.

If loop-back test is not working, the rest is just a waste of time.

Meantime, if the loop-back test is working and you are getting something like above, may be you connected TXD and RXD to wrong pin.

It is work trying to swap TXD and RXD if it cause any improvment.

0 Likes
MotooTanaka
Esteemed Contributor

Hi,

So finally similar USB-Serial converter I ordered arrived.

IMG_4316.JPG

I soldered pin-sockets for easy connection with jumper wires.

The first thing I tried was test the voltage of TXD when the jumper setting is 3.3V on this board.

And, Yes, TXD was 3.3V.

So DO NOT connect this device to the pins of DB9 on CY8CKIT-050.

Next I performed the loop-back test.

To do this test we need to short TXD and RXD of the USB-Serial Converter like below.

loop_back_connection.JPG

On my board

IMG_4317.JPG

Then connect the USB cable to PC and start Tera Term.

Then all the keys typed in the Tera Term were echoed back.

Note: This requires no program.

001-loop-back-tera-term.JPG

If this does not work, probably your USB-Serial Converter is damaged.

Now for the program, I wrote another program.

The schematic

002-schematic.JPG

pins

003-pins.JPG

main.c

======================

#include "project.h"

int main(void)

{

    uint8_t c ;

 

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

    UART_PutString("\x1b[2J\x1b[;H") ; /* clear screen */

    UART_PutString("This is an ECHO program\n\r") ;

  

    for(;;)

    {

        if (UART_GetRxBufferSize() > 0) { /* received some data */

            c = UART_GetByte() ;

            if ((c != 0)&&(c != 0xFF)) {

                if ((c == 'L') || (c == 'l')) {

                    UART_PutString("Light\n\r") ;

                } else if ((c == 'D') || (c == 'd')) {

                    UART_PutString("Dark\n\r") ;

                }

            }

        }

    }

}

======================

Then the hardware connection was

TXD of the USB-Serial to P0[0] of CY8CKIT-050 (White Jumper Wire)

RXD of the USB-Serial to P0[1] of CY8CKIT-050 (Green Jumper Wire)

GND of the USB-Serial to  GND (or VSSD) of CY8CKIT-050 (Black Jumper Wire)

IMG_4318.JPG

Then I ran the debugger.

In the screen shot below, I typed L, D, L, L, D, D

002-ProgramTest.JPG

moto

(Edited) some typos were taken care of.

0 Likes
abho_4730071
New Contributor II

Hi,

I write the below code. When i type any code the LED is turned off and also 'L' the LED is not turning on. Working fine but while getting character to teraterm is not working.The character are unrecognized.

pastedImage_0.png

0 Likes
MotooTanaka
Esteemed Contributor

Hi,

> I write the below code. When i type any code the LED is turned off and also 'L' the LED is not turning on.

> Working fine but while getting character to teraterm is not working.The character are unrecognized.

I assume that you used my sample code attached in my previous response,

namely "uart_test_050_200730", right?

I could not understand why LED does not turned on/off, then I noticed that in that project I was not connecting LED.

Meantime, about the printed letters, your tera term setting may be wrong.

The following is my Tera Term Setting(s).

Menu: Setup > Terminal...

003-TeraTerm-Terminal-setup.JPG

Menu: Setup > Serial Port...

Note: As you know, Port may be different depending on the environment.

004-TeraTerm-Serial-port-setup.JPG

And my Tera Term output is

000-TeraTerm-log.JPG

Meantime to take care of LED, I modified the project as below.

schematic

001-schematic.JPG

pins

002-Pins.JPG

main.c

===========================

#include "project.h"

#define LED_ON 1u

#define LED_OFF 0u

int main(void)

{

    uint8_t c ;

   

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

    UART_PutString("\x1b[2J\x1b[;H") ; /* clear screen */

    UART_PutString("This is an ECHO program\n\r") ;

   

    for(;;)

    {

        if (UART_GetRxBufferSize() > 0) { /* received some data */

            c = UART_GetByte() ;

            if ((c != 0)&&(c != 0xFF)) {

                if ((c == 'L') || (c == 'l')) {

                    LED_Write(LED_ON) ;

                    UART_PutString("Light\n\r") ;

                } else if ((c == 'D') || (c == 'd')) {

                    LED_Write(LED_OFF) ;

                    UART_PutString("Dark\n\r") ;

                }

            }

        }

    }

}

===========================

moto

View solution in original post

0 Likes
abho_4730071
New Contributor II

Hi I am getting the output but sometimes some special character is coming as below hilighted.

pastedImage_0.png

0 Likes
MotooTanaka
Esteemed Contributor

Hi,

Usually we see that symptom when Tera Term Terminal setup's New-line "Receive" is incorrect.

005-new-line.JPG

But in your case I'm suspecting the followings

(1) The USB-Serial Converter (especially RX) is damaged as you may have connected the pin to the 15V output.

(2) Connection of CY8CKIT-050 and rx of UART-Serial Converter is not reliable.

(3) The Font of Character Set is set to some special language.

     But if you see the output without problem, when you use USBFS (USBUART),

    I would suspect (1) or (2)

moto

0 Likes
abho_4730071
New Contributor II

Hi ,

If the USB - serial converter damaged then how LED functionality is working in the same program and also see the initial string ""This is an ECHO Program" is showing as expected?

#include "project.h"

int main(void)

{

    //uint8_t c;

    char c;

  

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

    UART_PutString("\x1b[2J\x1b[;H") ; /* clear screen */

    UART_PutString("This is an ECHO program\n\r") ;

  

    for (;;) {

 

        if (UART_GetRxBufferSize() > 0) { /* received some data */

            c = UART_GetByte() ;

          

           // UART_PutString("This is an ECHO program\n\r") ;

          //  c = UART_GetChar() ;

            CyDelay(1000);

            if ((c != 0) && (c != 0xFF))

            {

                if(c=='L' || c=='l')

                {

                UART_PutString("Light \n\r") ;

                LED_Write(1);

                }

                else

                {

                    UART_PutString("Dark \n\r") ;

                    LED_Write(0);

                }

            }

        }

    }

}

Thanks,

Abinash

0 Likes
MotooTanaka
Esteemed Contributor

Hi,

> If the USB - serial converter damaged then how LED functionality is working in the same program?

That part requires only the TXD port of the USB Serial converter,

so it will work even if the RXD port is not working perfectly.

And if you have connected the USB-Serial Converter to the DB9/RS232C level signal,

there should have been over voltage applied to the RXD of the USB Serial Converter.

But as you are seeing at least "Light" and "Dark", I hope that the TXD port is working

(or almost working).

Meantime, if you changed the Tera Term's new line / receive to AUTO

and still having unexpected letters along with Light and Dark

there may be problem with the TXD port.

Are you using the project I attached or have you manually copied the program?

If you are using your own project, can you attach the archive here,

so that I can test it in my side of the planet.

moto

(edited) some typos and RXD Part -> RXD Port

0 Likes
abho_4730071
New Contributor II

Please find an attachment of my project.

0 Likes
MotooTanaka
Esteemed Contributor

Hi,

I downloaded your project and tested.

As you have changed the baud rate of UART component to 19200

003-Uart-Config.JPG

I needed to change the TeraTerm Serial setup

002-Tera-Term-Serial-port-setup.JPG

Then with the following setup

IMG_4336.JPG

Your program was working OK.

Except that I needed to wait 1 sec for each key press.

001-TeraTerm-log1.JPG

IMHO, you don't need the following line

            CyDelay(1000);

The I did an experiment.

To simulate the condition in which the RX port of USB Serial Converter is not working.

I disconnected the jumper between the RXD of USB Serial Converter and the P0_0 (Tx_1) of CY8CKIT-050.

IMG_4337.JPG

Needless to mention, there were no feed back to TeraTerm,

but when I typed 'L' the LED turned on

and when I typed 'D' the LED turned off.

Now for the summary of the day.

I modified you program as below

===========================

#include "project.h"

int main(void)

{

    //uint8_t c;

    char c;

   

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

    UART_PutString("\x1b[2J\x1b[;H") ; /* clear screen */

    UART_PutString("CY8CKIT-050 USB-Serial Test 6-Aug-2020\n\r") ;

   

    for (;;) {

  

        if (UART_GetRxBufferSize() > 0) { /* received some data */

            c = UART_GetByte() ;

           

           // UART_PutString("This is an ECHO program\n\r") ;

          //  c = UART_GetChar() ;

           // CyDelay(1000); // this line is not necessary

            if ((c != 0) && (c != 0xFF))

            {

                if(c=='L' || c=='l')

                {

                UART_PutString("Light \n\r") ;

                LED_Write(1);

                }

                else

                {

                    UART_PutString("Dark \n\r") ;

                    LED_Write(0);

                }

            }

        }

    }

}

===========================

And the TeraTerm log was

010-TeraTerm-log2.JPG

moto

0 Likes
abho_4730071
New Contributor II

Ya that is fine i am also getting special character whenever i am typing something along with my output.

Not sure why i am getting that. Can you please help me on that?

0 Likes
MotooTanaka
Esteemed Contributor

Hi

नमस्ते

I think that the current setup is like below.

मलाई लाग्छ कि हालको सेटअप तल जस्तै छ।

002-connection.JPG

As LED is working, the path from TXD to P0[1] seems to be OK.

जस्तो कि LED ले काम गरिरहेको छ, TXD बाट P0 [१] सम्मको मार्ग ठीक छ जस्तो देखिन्छ।

I am suspecting that there is a problem in the path of P0[0] to RXD or RXD to USB.

म शंका गर्दै छु P0 [0] को RXD वा RXD बाट USB सम्मको समस्यामा।

First, I want to test the path from RXD to USB.

पहिले, म मार्ग RXD बाट USB सम्म परीक्षण गर्न चाहन्छु।

This is why I have been asking you to perform "loopback" test.

यसैले मैले तपाईंलाई "लुपब्याक" परीक्षण गर्न भन्दैछु।

"loopback" test is easy.

"लूपब्याक" परीक्षण सजिलो छ।

Connect TXD and RXD of FTDI board like below.

TXD र FTDI बोर्डको RXD तल जस्तै जडान गर्नुहोस्।

If you use TeraTerm program, all the letters you type must be echoed back.

यदि तपाइँ टेराटर्म प्रोग्राम प्रयोग गर्नुहुन्छ भने, तपाईले टाइप गर्नु भएको सबै अक्षरहरू प्रतिध्वनित हुनुपर्दछ।

If you see additional letters, which you have not typed, or the letter you typed did not come back, the FTDI board may be damaged.

यदि तपाईंले थप अक्षरहरू देख्नुभयो जुन तपाईंले टाइप गर्नुभएको छैन, वा तपाईंले टाइप गर्नुभएको अक्षर फिर्ता आएको छैन भने, FTDI बोर्ड बिग्रिएको हुन सक्छ।

003-loopback.JPG

If "loopback" test is OK, please make sure the connection between P0[0] to RXD is OK.

यदि "लूपब्याक" परीक्षण ठीक छ भने, कृपया P0 [०] RXD बीचको जडान ठीक छ भन्ने कुरा निश्चित गर्नुहोस्।

Then try the following program.

त्यसो भए निम्न प्रोग्राम प्रयास गर्नुहोस्।

main.c

========================

#include "project.h"

#include "stdio.h"

#include "ctype.h"

#define STR_LEN 32

char buf[STR_LEN+1] ;

int main(void)

{

    char    buf[32] ;

    uint16_t data ;

    uint8_t status ;

    char     c ;

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

    UART_PutString("\x1b[2J\x1b[;H") ; /* clear screen */

    UART_PutString("CY8CKIT-050 USB-Serial Test 7-Aug-2020\n\r") ;

  

    for (;;) {

 

        if (UART_GetRxBufferSize() > 0) { /* received some data */

            data = UART_GetByte() ;

          

            c = data & 0xFF ;    /* LSB of data is the letter */

            status = data >> 8u ; /* MSB of data is Rx Status */

            if (status != UART_RX_STS_FIFO_NOTEMPTY) { /* Status error */

                snprintf(buf, STR_LEN, "RX Error: 0x%02X ", status) ;

                UART_PutString(buf) ;

            }

          

            snprintf(buf, STR_LEN, "C = 0x%02X", c) ;

            UART_PutString(buf) ;

            if (isprint(c)) { /* if c is printable char */

                snprintf(buf, STR_LEN, "(\'%c\') ", c) ;

                UART_PutString(buf) ;

            }        

         

            if(c=='L' || c=='l') {

                UART_PutString("Light") ;

                LED_Write(1);

            } else if ((c == 'D')||(c == 'd')) {

                UART_PutString("Dark") ;

                LED_Write(0); 

            }

          

            UART_PutString("\n\r") ;

        }

    }

}

========================

This program shows you what letter is sent to PSoC.

यस कार्यक्रमले तपाइँलाई PSoC लाई के पठाइन्छ भनेर देखाउँदछ।

So you can see if there is corrupted input letter.

त्यसोभए तपाईं देख्न सक्नुहुनेछ कि त्यहाँ भ्रष्ट इनपुट अक्षर छ भने।

001-TeraTerm-log.JPG

Although this can not detect the problem about P0[0] to RXD, this may be able to provide you some hint.

जे होस् यसले समस्या P0 [०] RXD को बारेमा पत्ता लगाउन सक्दैन, यसले तपाईंलाई केहि संकेत प्रदान गर्न सक्षम हुन सक्छ।

moto

मोटो