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 CCS Technical Support

Multiple PIC communication
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bwgames



Joined: 21 Jul 2005
Posts: 36

View user's profile Send private message

Multiple PIC communication
PostPosted: Fri Aug 25, 2006 8:46 am     Reply with quote

Hiya,

(Using 18F452s, but this can be changed if need be, with CCS 3.249 all at 40Mhz)

I'm looking at interfacing 4/5 PICs together, one master and the rest are slaves, but I need the slaves to be able to communicate back to the master as well as master -> slave. Slave -> slave communication would be nice also...
I was originally going to use multiple RS232 lines on the master PIC, one to each slave PIC, but I doubt it could handle it, plus I would run out of I/O quickly...

Doing searches on CCS forum gives me lots of info on RS-485, MODBUS etc.
I found Neuotone's modbus example, but it looks overly complicated...

All I want is for each device to have its own address, and commands can be sent between the PICs, with the PICs acting on them depending on the contents.

The CCS suggestion of 1-wire serial on B0 (http://www.ccsinfo.com/faq.php?23) and the EX_PBUSM.C looks like the best method to adapt, but how good is it? It appears to have inbuilt collision detection and it will only display messages meant for that device, which is what I want.

I'm looking at distances of 10/15m between each slave PIC and the master PIC. It would be a star layout with the master PIC equidistant from each PIC, so for slave->slave it would be 20/30m total distance.
I was thinking of using MAX232's to boost the voltages across the cables, but how would this work with 1-wire, as there is both TX and RX?

The cable is already laid, its twisted pair (piggybacking on ethernet cable), so there is no problem with using 2 wire communication, but what is the easiest way? I'm thinking of just going for the 1-wire interface based on its simplicity....
Ttelmah
Guest







PostPosted: Fri Aug 25, 2006 9:50 am     Reply with quote

First comment, a 'twisted pair', is only effectively going to give you 'one wire' communication!. The 'point' of such a pair, is that when twisted together, noise gets induced on both wires together. Hence you normally send a single 'differential' signal, and use a differential receiver, which allows this noise to be rejected. Having the two wires then, is not going to allow you to have duplex comms. If you use the two wires for duplex, you will have the possibility of significant noise problems, and crosstalk. This will be made worse, because the wires will then have to be unterminated (normally, when using the 'pair', you have a termination resistor at each end of the wire, selected to match the characteristic impedance of the pair, and thereby reduce signal reflection, allowing much higher switching rates to be simply used). On this basis then, given the relatively low price of the transceivers, and the simplicity of driving them using the 'use RS232' commands already present in CCS, I'd say, use the wires as a differential pair, with RS485 transceivers. Have the line terminated with 120R at each end, and arrange the termination to apply a small bias to the line pair, so when nothing is driving the lines, the PIC chips 'see' the idle 'high' signal. Leave the receivers turned on at each chip, and use the 'enable' option on the PIC, to turn on the 485 transmitter.
Now you then have a choice depending on how much data needs to be sent, and how often the slaves may need to send to the master. The 'simplest' solution, is to run the bus 'polled'. Use a simple packet design, with perhaps a '0xAA' header, followed by the slave ID, and then the data the master wants to send (can be null), sent in something like hex, so that the 'control' byte values can never accidentally occur. The master sends a packet to each slave in turn, perhaps once a second, and the slave, then 'replies', with anything it wants to send. The master pauses for a couple of packet times after sending a packet. Plus side of this, is that there is no need to have software able to deal with a bus collision, since all transactions are 'triggered' by the master. Downside, is that if the slave needs to send something urgently, it has to wait till the next request fom the master.
The alternative to this, is to use a more complex communication protocol able to handle collision, here each device looks at the signal pair to see if the line is idle. Only if it is, does it start sending, and it monitors the data on the line as it sends. If the data is corrupt (implies either a collision, or noise), then it delays for a variable time, and tries again. The complex part is designing the 'retry', so that different devices can't get into a synchronous state, with them successively retrying at the same time...
A simple 'polled' system, could be implemented relatively easily. You can even have it that when a 'slave' replies after the master polls it, it can reply with the target ID it wants the packet to go to. Effectively the bus becomes 'time slotted', based on the timing of the master poll. If all devices (master included), watch the bus, and receive any packet starting with their ID, slave to slave communication becomes possible after the master 'polls' the source device.

Best Wishes
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

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

PostPosted: Fri Aug 25, 2006 9:59 am     Reply with quote

I like Ttelmah's idea. I have it working 24/7 over 700' in RS485.
But for shorter distances I've thought about the P82B715. Its an I2C extender.

http://www.semiconductors.philips.com/acrobat_download/datasheets/P82B715_6.pdf

And then use the I2C examples that CCS provides.
The master/slave PIC acting as an eeprom, comes to mind.
EX_SLAVE.C

Anyone use these? With pics with different power supplys ie: ground planes?
bwgames



Joined: 21 Jul 2005
Posts: 36

View user's profile Send private message

PostPosted: Fri Aug 25, 2006 10:06 am     Reply with quote

Thanks very much for your replies, you've both helped clear it up for me.

So, RS-485 is basically RS-232 but with the ability for more than one device? I can use fprintf etc with it?

Thats brilliant then, as I have a library already developed for wireless RS232 with more than two wireless PICs, if its just a matter of changing the #use parameters to adapt it, thats brilliant (I can't afford to use the same wireless chips for this project, at £10 each)

One thing that I hope you don't mind me asking, the RS485 transceivers, what is a good chip to use?

I looked at the MAX485 earlier, but the typical operating circuit confused me somewhat. Could someone tell me how I would connect up the MAX485 or a similar chip?
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

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

PostPosted: Fri Aug 25, 2006 11:21 am     Reply with quote

I spec the SN65176.
I run my signals through a opto isolator..
But if I remember right,
RC6->D
RC7->R
anypin->DE and RE(bar)..this is transmit enable
This might help. Someone elses schematic using LTC chip
http://www.mikroe.com/pdf/rs485_board_schematic.pdf
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

CAN bus
PostPosted: Fri Aug 25, 2006 12:30 pm     Reply with quote

bwgames wrote:
I'm looking at interfacing 4/5 PICs together, one master and the rest are slaves, but I need the slaves to be able to communicate back to the master as well as master -> slave. Slave -> slave communication would be nice also...

CAN bus might be what you're looking for. Just like RS-485, transmission is done with a differential pair with 0V to +5V levels. Strictly speaking, it's a peer-to-peer bus - there's no dedicated bus controller. The messages on the CAN bus have priorities. So if one of the controllers sends only high-priority mesages, it effectively becomes a master. There is a number of PICs that have hardware support for CAN (e.g. 18F258 and 18F458). I've never written communication protocols for the PIC+RS485, but I would guess that CAN would require less code that RS485.
Ttelmah
Guest







PostPosted: Fri Aug 25, 2006 3:04 pm     Reply with quote

Yes. I personally wish they'd change the '#use rs232' command in CCS, to '#use async', since the same command can be used for a whole range of different asynchronous communication links. 'RS232', implies the relatively high voltage 'point to point' communication hardware, which the chip itself cannot produce. RS485, is a differential pair communication link, which can be directly connected to the serial pins, and supports multiple receivers/transmitters.
There are about a dozen chips that are pretty much pin compatible with teh MAX485. You link the 'A' pins on all the transceivers, and the 'B' pins on all the transceivers. At each PIC, the 'RO' pin goes to the RX input on the PIC. The TX output on the PIC, goes to the 'DI' input on the transceiver. Then the /RE input on the transceiver goes to 0v (if you want to monitor what you send), or connects to the 'DE' pin if not. The DE pin, connects to whichever pin on the PIC, you set as the 'enable' pin, in the RS232 statement.

Best Wishes
bwgames



Joined: 21 Jul 2005
Posts: 36

View user's profile Send private message

PostPosted: Sun Aug 27, 2006 8:51 am     Reply with quote

Thanks for your feedback, it is *very* helpful.

Just looked at CAN bus and it seems that only messages of 8bytes can be transmitted?

http://www.ccsinfo.com/product_info.php?products_id=CANbuskit - "Each controller connected to the network is called a node and is able to transmit and receive messages from the network. CAN Bus offers a secure communication channel to exchange up to 8 bytes between several network nodes."

RS-485 seems the best way to go, as I can re-use my RS232 message ID codes etc..

CAN looks good in principle as the CCS manual seems to have interrupts for when a whole message is received etc, but the CCS example code seems to use if(can_kbhit) etc, rather than the interrupts which I would have thought would have been a neater way.
neverlog



Joined: 02 May 2010
Posts: 36

View user's profile Send private message

PostPosted: Sun Jul 18, 2010 9:50 am     Reply with quote

Dear All,

Sorry to raise question from the old thread.

I am new to RS485, I would like to know if I want to link 16 PIC as slave and monitor and send/receive command from PC, so for testing, I just need to load the ex_modbus_slave hex file into each PIC, ans then send/receive from PC hyperterminal?

Please help. Thanks in advance.

regards,
jbmiller



Joined: 07 Oct 2006
Posts: 73
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Jul 18, 2010 3:41 pm     Reply with quote

Ok, I'm old school....but..
I've used a form of 'one wire' communications for over 30+ years to interface with remote energy control systems. Yes, it's a proprietary system, slow but bullet proof. Up to 16 slaves per one wire (plus ground). Maximum distance is about 18 miles, yes, miles on plain old,u nconditioned leased telephone wires. PS it is HACKERproof as well.
The major plus is the ability to isolate faults in the wires something no other system (rs232,r2485,ethernet,fibre,etc) can do and still communicate with the slaves.
Yes, it's not off the shelf or high speed but after 30 years, it still works!
Jay
Jerson



Joined: 31 Jul 2009
Posts: 125
Location: Bombay, India

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

PostPosted: Sun Jul 18, 2010 7:58 pm     Reply with quote

Jay

I am a little intrigued with your technique as I have devised a 1-wire power line communication system for my work too. Mine works off a DC 24V supply. I do not have any performance stats on my system yet as it is still not off the drawing board. I wonder if you can reveal the baud rate and the power you use on the wireline to achieve signalling to 18 miles(wow)?

Thanks
_________________
Regards
Jerson Fernandes
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sun Jul 18, 2010 9:04 pm     Reply with quote

I do 1000 meters through a 24 AWG twisted shielded pair at 1200 baud in an older product using nothing more than a capacitor coupled PIC pin at each end. The master PIC commands and the slave PIC responds.

The cap is just there in case the cable gets miswired. If the data line gets crossed with the power supply, the PICs don't get fried.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Jerson



Joined: 31 Jul 2009
Posts: 125
Location: Bombay, India

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

PostPosted: Mon Jul 19, 2010 1:57 am     Reply with quote

Sherpa

1 wire for data + 2 wires for power makes that 3-wires. Jay was talking (I think) about a 2 wire-only scheme and that is what I'm doing at the moment.

I hope I haven't mis-understood what you're saying, if so, my apologies

Jerson
_________________
Regards
Jerson Fernandes
jbmiller



Joined: 07 Oct 2006
Posts: 73
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jul 19, 2010 5:14 am     Reply with quote

OK, don't laugh or fall off your seats, but my system runs at 24 BAUD.
Yes, that's NOT a typo, twenty four baud, pulse widths are 41.666 ms.
Communications power is a custom +-60 volt, 20mA supply, obviously NOT compatible with 'off the shelf' Rs232,RS485 or ethernet devices, great for security. Also it's a tri-level system,-60V,0V,+60V ALL have their meanings. Original unit had a 6800 as the brain,wirewrapped too !
Why so slow...it was designed for remote energy control systems, Speed is NOT the issue, being able to reliably communicate and control in lightning storms, heavy rains, cut wires from backhoes, welder noise, etc. is more important. Over 30 years in service, and while customers PCs have croaked, my stuff keeps on working.
We did push the envelope once and got almost 27 miles but at the reduced speed of 16 Baud. This is over regular Bell lines from Hamilton to Toronto airport. We could even tell well the Don river was getting low...
Jerson



Joined: 31 Jul 2009
Posts: 125
Location: Bombay, India

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

PostPosted: Mon Jul 19, 2010 7:22 am     Reply with quote

Jay

Thanks. That lets me see my work in the right perspective. I am currently doing 1200 on my design board. I had a hunch something wasn't quite right. I think I'll slow it to at least 600 baud for the first run; maybe more if I run into issues. I need this to run at max about 700 meters. But, I think I have the concept right.

Regards
Jerson
_________________
Regards
Jerson Fernandes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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