Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 1 > serial port comunnication

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



serial port comunnication
Moderator:
ARVI

Post Reply
Follow this topic



serial port comunnication

eusebiu posted on 06 Dec 2011 1:18 PM PST
Member
5 Forum Posts

Hello,

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!




Re: serial port comunnication

Bob Marlowe posted on 06 Dec 2011 01:42 PM PST
Top Contributor
1768 Forum Posts

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

Available in all PSoC versions.

Happy coding

Bob



Re: serial port comunnication

eusebiu posted on 18 Dec 2011 10:38 AM PST
Member
5 Forum Posts

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?



Re: serial port comunnication

Bob Marlowe posted on 18 Dec 2011 10:54 AM PST
Top Contributor
1768 Forum Posts

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

Bob

 



Re: serial port comunnication

H L posted on 18 Dec 2011 02:31 PM PST
Top Contributor
679 Forum Posts

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

 

 



Re: serial port comunnication

eusebiu posted on 19 Dec 2011 12:28 AM PST
Member
5 Forum Posts

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



Re: serial port comunnication

H L posted on 19 Dec 2011 01:52 AM PST
Top Contributor
679 Forum Posts

 1. First of all

I would change

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

to

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?


Re: serial port comunnication

Bob Marlowe posted on 19 Dec 2011 04:22 AM PST
Top Contributor
1768 Forum Posts

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

LCD_PrintString(Buffer);

 

Hope, there's no typo...

Bob

 

 



Re: serial port comunnication

Bob Marlowe posted on 19 Dec 2011 04:24 AM PST
Top Contributor
1768 Forum Posts

Ooops! Insert ")" where needed!

Bob

 



Re: serial port comunnication

eusebiu posted on 19 Dec 2011 06:38 AM PST
Member
5 Forum Posts

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.



Re: serial port comunnication

Bob Marlowe posted on 19 Dec 2011 07:36 AM PST
Top Contributor
1768 Forum Posts

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

Bob

 



Re: serial port comunnication

eusebiu posted on 19 Dec 2011 01:35 PM PST
Member
5 Forum Posts

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

 



Re: serial port comunnication

H L posted on 19 Dec 2011 02:59 PM PST
Top Contributor
679 Forum Posts

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



Re: serial port comunnication

H L posted on 19 Dec 2011 03:09 PM PST
Top Contributor
679 Forum Posts

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.

 






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