View previous topic :: View next topic |
Author |
Message |
Gerhard
Joined: 30 Aug 2007 Posts: 144 Location: South Africa
|
Comms between PC, PIC master and several slave pics |
Posted: Mon May 04, 2009 10:35 am |
|
|
Hi. I am starting a project where data will be sent from a PC to a master PIC (probably using RS232 485 or ethernet). This data then needs to be checked and reworked and sent to several different slave pics according to the requirements received from the PC. I need some advice as to which Protocol would be the recommended one to use between PC and Master and Master and the slaves. The distance would at all times be less than 100m between nodes. Would I2C,SPI or RS232,485 be better between master and slave and what is better to use between PC and Master? Or is there a better one and what might there be?
Thanks |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Mon May 04, 2009 11:05 am |
|
|
I would use a FTDI USB to serial for the PC to master.
Then rs485 for master to slaves.
You could also have the FTDI chip talk RS485 and make the master and
all the slaves the same design. RS485
If you don't want to build that part yourself...
http://www.bb-elec.com/product_family.asp?FamilyId=397&Trail=45&TrailType=Main
Make the protocol have a broadcast message type.
All slaves could have a address and be selectable. |
|
|
Gerhard
Joined: 30 Aug 2007 Posts: 144 Location: South Africa
|
|
Posted: Mon May 04, 2009 12:31 pm |
|
|
Thanks.
I will use the RS485 then but I do have a question regarding the hardware config of the nodes. I intend using 18F4682 Pics and for the Coms to PC i have a rs232-usb converter which will be connected to the RX and TX pins via max232 chip of the pic. To comunicate with 485 to the slave pics should I use different pins and how would I go about implementing 2 serial ports on the pic if the TX and RX pins are dedicated serial pins? Can I implement 2 serial ports on one device and if its possible how would I go about in doing so. |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Mon May 04, 2009 1:07 pm |
|
|
Nope, instead stick with the one hardware USART.
The PC/USB to serial converter should have a RS485 instead of the max232
Then ALL nodes master and slaves talk on one RS485 bus.
This is called a multi-drop bus
The master is just a unique address, say addr=1.
All/any node can talk to any other.
Say the PC is address 0. addr=0 and 3 slaves addr=2,3,4
then 2 can talk to 4.
3 can talk to 0
1 can talk to 2,3,4 or ANYcombination.
The normal way will be PC(addr=0) talks to master(Addr=1)
And then Master(Addr=1) talks to any/all slaves(addr=2,3,4) |
|
|
Gerhard
Joined: 30 Aug 2007 Posts: 144 Location: South Africa
|
|
Posted: Mon May 04, 2009 1:26 pm |
|
|
Thanks.
I usually do 485 by
Code: | #use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7 |
and the just use putc on the line with a max 485 chip. Is this the correct way?
If I start doing multi drop how would the structure of data look and how would I go about sending and recieving via a master to slaves with a specific adress? Do I set each slave up with specific adress or do I just use some type of checksum to establish if the data on the line was meant for that slave? |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
Re: Comms between PC, PIC master and several slave pics |
Posted: Mon May 04, 2009 1:40 pm |
|
|
Gerhard wrote: | Hi. I am starting a project where data will be sent from a PC to a master PIC (probably using RS232 485 or ethernet). This data then needs to be checked and reworked and sent to several different slave pics according to the requirements received from the PC. I need some advice as to which Protocol would be the recommended one to use between PC and Master and Master and the slaves. The distance would at all times be less than 100m between nodes. Would I2C,SPI or RS232,485 be better between master and slave and what is better to use between PC and Master? Or is there a better one and what might there be?
Thanks |
Being a network guy, my first choice would be Ethernet. It is very cheap to implement on a PIC using the PIC18F97J60 family. With Ethernet all devices could belong to the same subnet or be distributed around the work. I can forget about the problem associated with USB devices that will not longer enumerate correctly because I may or may not have installed another USB device that causes problems. I do not need to be concerned that an unrelated USB device stalls the bus, or causes the bus power budget to be exceeded invoking the enumeration process again. Ethernet provides 1.5KV of galvanic isolation - minimizing the chance of latchup when connecting devices together.
Ethernet with or without TCP/IP provides you an addressing solution to deal with unicast, (1:1 communications), broadcast (1:many communications) and multicast (1 : group or group:group). _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
Gerhard
Joined: 30 Aug 2007 Posts: 144 Location: South Africa
|
|
Posted: Mon May 04, 2009 1:50 pm |
|
|
Thanks
Problem is this seems very complicated and I am not yet at a level of competence to allow me to use this. I have used 485 on several ocasions but never on more than 2 pics at a time. I had a look at your site thanks.
This is definitely something i will look at in future but for now i think 485 will be better. |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Mon May 04, 2009 2:55 pm |
|
|
Quote: | #use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7
Is this the correct way? |
I would start out slower. and use the enable that most RS485 chips have.
Tie RE_bar to DE and that to the enable-pin_c5 or whatever.
That says if PIN_C5=0 your receiving if PIN_C5=1 your transmitting.
Code: | #use rs232(baud=19200,errors,xmit=PIN_C6,rcv=PIN_C7,enable=PIN_C5,stream=RS485)
|
|
|
|
|