From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

RS232 and PIC16F877A reading problem

Hi, sorry my bad English.

I have pic16f877a and labview 7.0. I try to transfer some information(e.g temperature) to my PIC and view that information on LCD-screen. A communication idea is following:

Traffic if pic starts communication:

1. PIC send int (e.g 123) to labview
2. labview read int(and identify what measurement is equivalent with this int)
3. labview send back string which includes measure value
4. PIC prints this string to LCD-screen

Traffic if labview starts communication:

1. Labview send int to PIC
2. Labview send string to PIC


My problem is that I get wrong values from PIC. If I test algorithm on terminal program that is okay.
For example if PIC try to send 125, I can see in labview 512 or 215.

Does anyone have build good vi which reads characters from rs232? (I have downloaded and test labview's examples) What kind of vi structure is good? One difficult is that pic and labview both can start communication so I have to read characters all the time.
0 Kudos
Message 1 of 5
(4,340 Views)
Kheila,

There are a handful of VISA/Serial VIs available in LabVIEW. The shipping example 'Basic Serial Write and Read.vi' is a decent example of serial communication (Configure the serial port, write or read data with appropriate delays in between, close the port). To gain confidence in the LabVIEW Serial VIs I would recommend conducting a loopback test (connect pins 2 and 3 on a DB9). You could run this basic serial example or one of your own. For more help on basic serial communication please refer to the following:

Serial Communication Starting Point

and...

Serial Communication General Concepts

Now if this fails to help please post back!

Craig H.
NI Applications Engineering
0 Kudos
Message 2 of 5
(4,324 Views)
Kheila,

your problem sounds to me as missed synchronisation. As your protocol seems to contain just plain text, so please add a sync char to the end of ALL your messages. Define it as end_of_message in VISA and read complete messages. I'd suggest 0xA (LF) as sync char.

You know, serial comm means, that all bytes are sent out in the order they appear at the send command (here VISA_write). AND they are usually read at the UART level in the very same order. But depending on the actual situation (system load, UART buffer size, system buffer size, but more important: your coding style) VISA may miss one or the other byte. If you have no sync mechanism, than you'll have no chance to regain sync state after you've lost it once. If you have a sync mechanism, you'll lose one or two messages in such a case and regain sync with every new complete message.
Example messages (blank space meant as pause between each message)
123 123 456 122 123
read when byt 3 was missed:
121 234 561 221 23

If instead a sync mecanism is established, you'd get
12- 123 456 122 123


HTH and
Greetings from Germany!
0 Kudos
Message 3 of 5
(4,318 Views)
Thanks, for good tips!

I made new test vi and that is in attachment. I change my data format. New data format is SXXXR, where X is integer. Vi tries to find S letter and after that reads integers. I made also test program in PIC. When labview send data to pic, after that pic send back same data. I'm not sure did you ment this kind of structure when you speak "synchronisation"?
0 Kudos
Message 4 of 5
(4,310 Views)
hi,

not to the point yet. With RS232, serial communication, the string is piped thru the cable one after another. When to start and stop, that is handshaking, is the critical element for both sides to get and distribute the info. Even now you add S and R as pre- and suffix, but the hardware donot know that, though you pretend to state that. So your addition is just another operation on the data, but not on the protocal for communicating the data.

you should check the manual for PIC first. Do they need special characters for programming? These ones are what the hardware recognizes and "real signal".

If you have tested successfully your input, then for the input in the programming, you need add only the necessary EOI. It can be "/n" or others, but you have to find this specific info in your own lab stuff.

For the next, please say you know the labview programming, and how to set the serial parameters, etc. So that people understand what is the stage your problem lies.
0 Kudos
Message 5 of 5
(3,984 Views)