CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How to send data from pic to pc using rs232?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Einly



Joined: 10 Sep 2003
Posts: 60

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger ICQ Number

How to send data from pic to pc using rs232?
PostPosted: Tue Nov 16, 2004 1:17 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 16, 2004 1:50 am     Reply with quote

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

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger ICQ Number

Hardware handshaking
PostPosted: Tue Nov 16, 2004 7:57 am     Reply with quote

"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

View user's profile Send private message

PostPosted: Tue Nov 16, 2004 8:59 am     Reply with quote

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>
Wink
_________________
The search for better is endless. Instead simply find very good and get the job done.
Guest








PostPosted: Tue Nov 16, 2004 10:02 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Tue Nov 16, 2004 12:46 pm     Reply with quote

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







PostPosted: Tue Nov 16, 2004 2:26 pm     Reply with quote

You can see some sample code and a design at my website at:

http://www.geocities.com/hagtronics/pic_das/index.html

Steve H.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group