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

Advice for Serial Comms

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



Joined: 12 May 2004
Posts: 38

View user's profile Send private message

Advice for Serial Comms
PostPosted: Wed Dec 21, 2005 5:25 am     Reply with quote

Hi

I have an application that I need to start in the new year that requires RS232 communication. I haven't done anything on this using a PIC in the past so I'm looking for some recommended sources of information.

thanks

JFK
yerpa



Joined: 19 Feb 2004
Posts: 58
Location: Wisconsin

View user's profile Send private message Visit poster's website

PostPosted: Wed Dec 21, 2005 3:12 pm     Reply with quote

Life is easier if you use a PIC with a hardware UART built-in, rather than doing a bit-banged port in software. The bit-banged port only makes sense in high volume low cost applications.
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Wed Dec 21, 2005 10:50 pm     Reply with quote

Don't forget the RS-232 transceive such as MAX232. Keep in mind also that most of the laptops produced these days have no RS-232 port.
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

Re: Advice for Serial Comms
PostPosted: Thu Dec 22, 2005 3:33 pm     Reply with quote

JohnKennedy wrote:
I have an application that I need to start in the new year that requires RS232 communication. I haven't done anything on this using a PIC in the past so I'm looking for some recommended sources of information.

i would start by getting any of the various PIC development boards that have 1) a PIC with hardware UART, and 2) an on-board level converter such as noted above like the MAX232.

with this hardware, you can use a simple serial cable to connect to your PC and you can then begin to code up a trivial program for the PIC board to spit out "hello world" to the PC. (note: on the PC, please use anything BUT MS Hyperterminal -- it is not worthy of your time.) the TX part of your work is easy, implementation wise...

once you have "hello world" on your PC screen, you can start back the other way, where you will need to use either polling or interrupts to capture bytes from the PC on the PIC. here you will find the real work of serial communications, namely managing time and buffers while trying to do other tasks. it can be easy or very simple, depending on how much other work needs to be done. if the PIC just sits waiting for a command from the PC ("temperature?"), then runs off an executes some code (get_temperature();), and then reports back to the PC ("send_temperature();), your job will be very straightforward.

on the other hand, if the PIC is generally busy and bytes arrive asynchronously from the PC, you'll need to implement a little state machine to handle interupt-driven receipt of bytes and then act when command parsing is done.

you'll note that a little thinking beforehand *at the system level* before starting implementation can save you a lot of coding and a lot of headaches. for example, it's a good idea to elect one endpoint as the master (typ. the PC) and the other as a slave (typ. the PIC). now you can draw a state diagram for the entire system, which shows who initiates communication and how fault recovery is handled (ooops, someone disconnected the serial cable!).

regards,
jds-pic
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