13 Replies Latest reply on Dec 19, 2011 5:09 PM by ki.leung

    serial port comunnication



      I have to send 3 long tipe variable form a PLC to CY8C kit001 and i tought to use the serial port from this kit, but i don't have any clue how to start. what components should i use to program it to send and recive data using the serial port. pleasssse help!

        • 1. Re: serial port comunnication

          The module you need is the UART ( Acronym of: Universal Asynchrone receiver and Transmitter afaik)


          Available in all PSoC versions.


          Happy coding



          • 2. Re: serial port comunnication

            10xthx for your answers! indeed using the UART module I managed to establish the communication between the PLC and the kit but the LCD dose not display's the data I'm sending from the PLC witch is a constant on 16 bites. For example I am sending from the PLC the number 3 (on 16 bites) and on the display of the PSoC kit appears all kind of strange characters. I thought it is because of the bits/seconds rate but I didn't solved this problem even if I fixed the same baude rate to both devices. Any ideas how to solve this problem?

            • 3. Re: serial port comunnication

              Well, zip your project and let us have a look at it, there are some pitfalls one can make...



              • 4. Re: serial port comunnication

                You mentioned not showing the data, there can be


                1. you are not sending the data or the data is not is the correct format


                2. The psoc doesnt see the signal from the input pin whcih could be a problem with the buffer/level shifter...


                3. The spindoes get the signal, but Psoc Uart doesn't peform the receiving funtion


                4. The Psoc handles the receiving correctly but your program get the data from a wrong address or decoding in a wrong format


                5. the data is receved and decoded correctly, but the LCD display fucntion not outputing it to the LCD correctly


                6. The data is output to the LCD module correctly but the LCD module not displaying the right thing.


                This would be the way I check.


                Check this, upload the project and tell people here which one is your problem, some one may be able to help

                • 5. Re: serial port comunnication

                  Here is my project. As I said  before the PSoC Kit has to recive and display on the lcd 3 long variables data witch I am sending to it from a PLC witch has a baude rate of 19200. Insted of the 3 variables it dispays continousely some strange characers.(I also tryed to use the sprintf() function but without succes).

                  • 6. Re: serial port comunnication

                     1. First of all


                    I would change


                    int16 ch;       /* Data received from the Serial port */




                    char ch;       /* Data received from the Serial port */




                    2. What do you send from PLC, ASCII 0-9 or a byte of 0-255 ( ie an int from 0x00 to 0xffff? If you are send a binary value, you need to convert it to ascii string to display.


                    3. Have you use hyperterminal to check what you are sending from the PLC?

                         4. As I menention in my last post,  have you check as what list on the steps? which step does it project failed?    
                    • 7. Re: serial port comunnication

                      to send 3 long variables with an UART may be complicated: An UART is an 8-Bit device, you have to send one long as four separate bytes and on the receiving side, you have to combine them to form again a long integer. A bit of shifting or indexing or use of a union seems nessecary on both sides.


                      You ought to check first with a program whether your separating into bytes and the re-combination works, before you sent them via UART.


                      The LCD-Component is a CHARACTER component, it only displays ASCII chars (the one is 0x31, the letter "A" is 0x41) you will have to convert your numbers into a character string to display it. Fortunately there is a function for that:


                      #include <stdio.h>


                      char Buffer[16];


                      uint32 MyVar = 0x7FFFFFFF;


                      // and now the bit cryptic sprintf:


                      sprintf(Buffer,"%Lu",MyVar; //






                      Hope, there's no typo...



                      • 8. Re: serial port comunnication

                        Ooops! Insert ")" where needed!



                        • 9. Re: serial port comunnication

                          1. I tryed also with 'char ch' insted 'int16' but it dose not work.


                          2. I think  the plc is sending byte. The data that the plc can send are boolean, word and long(binary value I think).


                          3. I have tested the program posted here with the hiper terminal and it works. It recives data from the PC rs232 port, and I also tested a program so that the PC recives data that the PSoC sends and also worked, but when I used the hyperterminal to see what is the plc sending....appeared some strange characters. But to send the same data to another PLC works.


                          4. I think is a problem of codification of the information. Let me see if I understood correctly: the LCD  can display only ACSII code so if the  PLC is sending binary code, using fprintf() function i have to convert it to ASCII.

                          • 10. Re: serial port comunnication

                            Yes, perfectly right. When you use sprintf as I showed in the example, you can easylier debug, look at Buffer or the input-value before printing to LCD.




                            Happy debugging



                            • 11. Re: serial port comunnication

                              And exactely how can i see what PSoC is reciveing whithout printing  on the LCD? How can Iook at what is in the buffer?

                              • 12. Re: serial port comunnication

                                Do you have the ICE? If you do, use the debugger to step and trace

                                • 13. Re: serial port comunnication

                                  If you don't have the ICE, then you may use the following functions


                                  LCD_PrHexByte, LCD_PrHexInt.


                                  You can find the descritpion of this function in the LCD DATA sheet from the designer.


                                  THe first one let you print one byte at a time, try this first. This way you print it out as four seperate bytes.


                                  If that works, your receiving should be OK. The rest would be how to groupt the 4 bytes to form a long and also how to display it, using printf and these printing fucntion should work, you just need to read thru the specificationa and pick the one the suits you.