View previous topic :: View next topic |
Author |
Message |
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
Rs232 between pic micro |
Posted: Wed Jan 02, 2013 2:40 pm |
|
|
Does someone has any sample program how to exchange data between multiple pic, such as send a command from pic 1 to pic 2 to switch on led via rs232?
Redmir[/img] |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Wed Jan 02, 2013 2:57 pm |
|
|
PIC101 !!!
which PIC...
which compiler....
have you got the '1Hz LED' AND 'Hello PC' programs running on BOTH PIC systems....
do you have a PC with working comport and terminal software...
this is the minimal stuff you MUST have before you can do your project.
hth
jay |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
|
Posted: Wed Jan 02, 2013 3:03 pm |
|
|
Thanks temtronic. What i would like is the flow and not a project. What is the format of simple message from one pic to another? For the sake of this post we can use pic18f4550 and pic16f877. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Wed Jan 02, 2013 4:34 pm |
|
|
Start by following temtronic's advice.
Your two PICs are PIC_A and PIC_B.
Use a PC to communicate with each PIC in turn, via a null modem cable.
When the PC is connected to PIC_A, the PC behaves as though it were PIC_B.
When the PC is connected to PIC_B, the PC behaves as though it were PIC_A.
CCS provides sample code for communicating via RS232.
You're the one who knows what you want the devices to say to each other.
Mike |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
|
Posted: Wed Jan 02, 2013 4:39 pm |
|
|
But my question is how i am going to send the following statement:
Code: | output_high(pin_a0); |
To pic B via rs232
That's what i need. |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Wed Jan 02, 2013 5:01 pm |
|
|
Hi,
You don't. Instead, send something like this with one PIC:
Code: |
Printf("LED 1 On");
|
Then, with the other PIC, receive this message, and act on it.
John |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Wed Jan 02, 2013 7:00 pm |
|
|
Aaron,
You need to look up online for explanations on basic communications protocols.
Ultimately, the way you do what you want to do is up to you.
http://en.wikipedia.org/wiki/Communications_protocol
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
Re: Rs232 between pic micro |
Posted: Thu Jan 03, 2013 5:37 am |
|
|
aaronik19 wrote: | Does someone has any sample program how to exchange data between multiple pic, such as send a command from pic 1 to pic 2 to switch on led via rs232? | I agree with Ben that you have to do more reading on device communications. RS232 is a physical medium for communication between 2 devices, not more! When you want to connect multiple devices to the same physical wires than have a look at other standards like RS485.
Please consider the following choices:
- Maximum wire length
- Wire topology (bus, ring, star, etc) http://www.edrawsoft.com/Network-Topologies.php
- Minimum baud rate
- Number of devices in the network
- Master-slave or can each device start a communication?
These choices help you to choose the correct physical network. Some popular standards are:
- RS232: point-to-point, maximum 20m
- RS485: multi-drop, maximum 1200m+
- I2C: master-slave, maximum 2m (often inside same enclosure)
- 1-Wire: similar to I2C but slower data rate over longer lines.
- CAN: multi-master for harsh environments (automotive)
- ZigBee: wireless mesh network
- Ethernet
Then on top of this 'physical layer' you will need a protocol. What the protocol looks like will partly depend on the properties of your physical network, for example when more devices share the same bus you'll need some kind of addressing scheme which can be left out in a point-to-point communication.
You can use one of the many existing standard protocols. Some popular protocols for use in the PIC are: CAN, LIN, ModBUS
But depending on your requirements it is perhaps easier to define your own protocol. I suggest you do some reading into the above mentioned protocols and physical layers. Study at least 3 protocols, you'll find there are many similarities but specific needs made it necessary to implement just again another protocol. We don't know what kind of system you want to design and there is no single 'best' protocol. So do some reading and then come back here with more detailed questions. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
Re: Rs232 between pic micro |
Posted: Thu Jan 03, 2013 12:07 pm |
|
|
ckielstra wrote: | aaronik19 wrote: | Does someone has any sample program how to exchange data between multiple pic, such as send a command from pic 1 to pic 2 to switch on led via rs232? | I agree with Ben that you have to do more reading on device communications. RS232 is a physical medium for communication between 2 devices, not more! When you want to connect multiple devices to the same physical wires than have a look at other standards like RS485.
|
Oh, now that ckielstra has mentioned it, make sure to also read:
http://en.wikipedia.org/wiki/OSI_model
As an exercise, go read up and tell us where you think RS232 fits in the OSI model.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
|