View previous topic :: View next topic |
Author |
Message |
Einly
Joined: 10 Sep 2003 Posts: 60
|
How to send data from pic to pc using rs232? |
Posted: Tue Nov 16, 2004 1:17 am |
|
|
Dear all,
I am trying to build a real time data acquisition system from pic to pc using rs232/ uart. However, I don't have any idea how the synchronization like between the pic and pc. How does the pic know when to send the data/ or actually it just continuously send data to the pc? If it just continuously send data, will the data get lost? Is there any buffer required to store data, e.g. transmit buffer? Any example code for this type of application? Thanks _________________ Einly |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Tue Nov 16, 2004 1:50 am |
|
|
You should be able to use an application on the PC side to constantly poll the serial port and read any available data.
Or, you can use a software handshaking protocol. PC can inform the PIC that it is ready by sending a special character. You shouldn't need to have the PIC send a special character to PC too. However if you want you can make this handshaking both ways, similar to XON/XOFF. This method has its own shortcomings: it's in-band (consuming two character codes which could also happen in data, and it is not robust against dropped characters .. if an XON (or your flag character) gets dropped, communication fails.
Or, you can use hardware handshaking (CTS/RTS). This should be easy to implement using a MAX232 (as it has two input and two output pins). |
|
|
Einly
Joined: 10 Sep 2003 Posts: 60
|
Hardware handshaking |
Posted: Tue Nov 16, 2004 7:57 am |
|
|
"hardware handshaking (CTS/RTS). This should be easy to implement using a MAX232 (as it has two input and two output pins)."
May I know how should it be done? How should the pins be connected (between the pic and max232)? Is it just hardware? _________________ Einly |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Tue Nov 16, 2004 8:59 am |
|
|
The hard part of using CTS/RST will be getting the PC to use it. Most serial packages for the PC do not use these lines, or at least don't use them correctly. You will likely end up having to write your own serial drivers for the PC.
The PIC end is trivial if you use a software UART and not much harder if you use a hardawre UART. Once you find out how the PC handles these lines you can figure out how to make the PIC work with them. It is simillar to controlling the transmit enable line for RS485.
In your aquisition application what is the effect of lost data? Generally I would have the PIC take measurements and send them to the PC at some known sample rate with a start of message byte at the beginning of each packet. The PC would wait for each measurement ot arrive and process it. If the PC isn't ready when the measurement arrives it will miss the start of message byte, punt that packet and wait for the next. What else would you want it to do?
You could have the PIC wait for each packet to be acknowledged before sending the next. But that will take some time.
You could have the PIC buffer several packets and wait for the PC to acknowledge them. Any packen not acknowledged in a reasonable time is re-sent. Now the PC has to be able to re-order packets to put the re-sent ones in their proper place. You also have to figure out what to do when the PIC runs out of buffer space.
Or you could get REALLY complicated:
<insert 100 pounds of PHD theses here>
_________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Guest
|
|
Posted: Tue Nov 16, 2004 10:02 am |
|
|
How long generally this kinds of works for an experience engineer. one week, two week or three weeks...? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Nov 16, 2004 12:46 pm |
|
|
If you are asking how long would this type of program take for an experienced programmer (PIC and PC) then speaking for myself, less than a day! |
|
|
Steve H Guest
|
|
|
|