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

Uart Bus

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



Joined: 05 Oct 2008
Posts: 1

View user's profile Send private message

Uart Bus
PostPosted: Sun Oct 05, 2008 10:48 am     Reply with quote

Is it possible to create a serial bus connecting multiple pics together in a master multi slave config? Connecting the master tx to the slaves rx and the master rx to the slaves tx. Just wondering, I've heard this can't be done, although I had it working on a system with two slaves but adding a third brought the bus down. I'm in col but I'm just messing with this project, any insight or advice is welcomed, thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 05, 2008 11:56 am     Reply with quote

See this recent thread on "What is RS-485 ?
http://www.ccsinfo.com/forum/viewtopic.php?t=35986

Summary:
http://en.wikipedia.org/wiki/EIA-485
jaymiller
Guest







PostPosted: Sun Oct 05, 2008 4:03 pm     Reply with quote

Yes it can and has been done. Did that 'trick' 30 years ago on my Model III as the master to several(8 or 10) slave units.
Today it's just as easy to use RS-485.
The bottom line is that it's just chips and code......
been there..done that.
Jay
SherpaDoug



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

View user's profile Send private message

PostPosted: Sun Oct 05, 2008 9:18 pm     Reply with quote

If you have several PICs close to each other, sharing a common ground, and your baud rate is not terribly high you can use a "Wired Or" configuration AKA "Open Collector". I believe CCS has an option in the #useRS232 statement to inplement this, but I don't have my manual or the compiler at hand.
_________________
The search for better is endless. Instead simply find very good and get the job done.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Oct 05, 2008 11:40 pm     Reply with quote

The other option is to use tristatable RS232 drivers and create a kind of RS232 bus. Although RS485 is the more reliable technique, multi-drop RS232 is sometimes used in instrumentation. It works well in a small area according to my experience. The main adavantage is, that you can use a PC master without level converter.
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Mon Oct 06, 2008 8:39 am     Reply with quote

First of all, is the "master" always the same processor? If you want to allow more than one PIC to take the master role, it gets much more complicated.

If it's the same master all the time, the major design issue is how to allow the slaves to talk without interfering with each other's data. You can't connect all the outputs together unless you're sure you can tri-state all except one of them, either on a time-slot basis or when they're explicitly commanded by the master. An open-collector scheme solves the electrical problem, but not the issue of multiple slaves talking at once and delivering a gabled message.

But these things have all been solved in many ways, and it's fun to play with, if the pointy-haired boss isn't hassling you to get it working quickly.
red
Guest







help: same problem.
PostPosted: Tue Mar 17, 2009 1:42 am     Reply with quote

Hi, i am newbie, but how can i perform a open collector scheme in ccs? Links are very much appreciated. Tnx
Ttelmah
Guest







PostPosted: Tue Mar 17, 2009 3:28 am     Reply with quote

The actual 'open collector' bit, is easy (provided you have a reasonably recent compiler). Look at the 'float_high' option in the RS232 setup. This basically tells the code to actually 'switch off' the UART, when not sending, and switch the pin to a 'float' state. You then need to have a pull up resistor on the line.
In terms of reliability, for more than a very few feet, much better, to use RS485.
Code wise, it becomes a little more work. First, you really need to operate the bus 'half duplex', and have all the receive lines monitoring the serial line. Then, before sending, your 'intended sender', needs to check that the line is idle (high). If it is, then it needs to send, _and check that it receives what it sends_. If it doesn't, then the assumption is that something else has tried to send at the same time (a collision). You then need a collision recovery algorithm. If the number of slaves is small, a simple one, is to have each pause for a different time, before retrying. Ater the time, again testing that the bus is idle. In a sense, the devices with the shortest 'retry' times, will be the highest priority devices on the bus. The only downside of this, is that times may become long, if you have a lot of devices. Alternative is some form of random time selection, but you need to be very careful here, that 'random' number geerators ae of course only _psuedo random_, and if multiple chips wake up together at the same time, all could end up with their number generators 'in sync', resulting in a deadlock.....

Best Wishes
frothbeast



Joined: 08 Jul 2010
Posts: 4

View user's profile Send private message

PostPosted: Mon Jul 12, 2010 1:07 pm     Reply with quote

Ttelmah wrote:
The actual 'open collector' bit, is easy (provided you have a reasonably recent compiler). Look at the 'float_high' option in the RS232 setup. This basically tells the code to actually 'switch off' the UART, when not sending, and switch the pin to a 'float' state. You then need to have a pull up resistor on the line.
In terms of reliability, for more than a very few feet, much better, to use RS485.
Code wise, it becomes a little more work. First, you really need to operate the bus 'half duplex', and have all the receive lines monitoring the serial line. Then, before sending, your 'intended sender', needs to check that the line is idle (high). If it is, then it needs to send, _and check that it receives what it sends_. If it doesn't, then the assumption is that something else has tried to send at the same time (a collision). You then need a collision recovery algorithm. If the number of slaves is small, a simple one, is to have each pause for a different time, before retrying. Ater the time, again testing that the bus is idle. In a sense, the devices with the shortest 'retry' times, will be the highest priority devices on the bus. The only downside of this, is that times may become long, if you have a lot of devices. Alternative is some form of random time selection, but you need to be very careful here, that 'random' number geerators ae of course only _psuedo random_, and if multiple chips wake up together at the same time, all could end up with their number generators 'in sync', resulting in a deadlock.....

Best Wishes


Is it possible to have 2 pics 'float_high' and one normal so that the 2 pics can pull the one pic's line down? Or would that be like shorting 5V to ground?

I have done something similar to the original post. I have 3 pics listening to a master(c7RX slaves wired to c6tx master) and each of the three will transmit back to the master when addressed(c7rx master wired to c6tx slaves). I plan to use a pull-up on the slave's tx and float them all high, unless I can leave 1 slave normal and float the other 2.

Does anyone know?

PS sorry for not jumping to RS 485. Next time...

I forgot to mention that it works with 2 slaves and 1 master, but 3 slaves can receive from master but none can transmit.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 12, 2010 4:37 pm     Reply with quote

Quote:

Is it possible to have 2 pics 'float_high' and one normal so that
the 2 pics can pull the one pic's line down?
Or would that be like shorting 5V to ground?

You would be stressing the pin drivers. It's not recommended design practice.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon Jul 12, 2010 6:15 pm     Reply with quote

Quote:

Is it possible to have 2 pics 'float_high' and one normal so that the 2 pics can pull the one pic's line down? Or would that be like shorting 5V to ground?

Quote:

Is it possible to create a serial bus connecting multiple pics together in a master multi slave config?

Quote:

Hi, i am newbie, but how can i perform a open collector scheme in ccs? Links are very much appreciated. Tnx


I know that all these "fresh ideas" are looking for the simplest/easiest way to get something running,
but there is not any reason to re-invent the wheel.
A regular microcontroller pin out was not designed to be wired away to perform a data transmition bus line,
there are more than 25 arguments for a NO.
To overcome the arising problems of this, over the years had been created hundreds of hardware
interfaces and procedures to handling communications (protocols), these rules are know as standards.
Every standard used widely (RS232, RS422, RS485, LIN, CAN, etc) has been impossed for many good
reasons, there are one that is optimum for each application and you should know them at least before
trying for yourself something that was already done and is warrantied that it must run.
All this bla-bla-bla has the only purpose to suggest you newbie guys to read and investigate a little
regarding this, and finaly for your application, I suggest to use LIN (Local Interconnect Network) is an
easy standard to implement and can be do it in a cheaper way.

Humberto

Edited: to remark add bold letter


Last edited by Humberto on Mon Jul 12, 2010 8:53 pm; edited 1 time in total
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon Jul 12, 2010 7:17 pm     Reply with quote

FWIW, CCS has an example of a multi-PIC one wire comm setup:

http://www.ccsinfo.com/faq.php?page=connect_pics
_________________
Google and Forum Search are some of your best tools!!!!
frothbeast



Joined: 08 Jul 2010
Posts: 4

View user's profile Send private message

PostPosted: Mon Jul 12, 2010 9:45 pm     Reply with quote

I found a post by Bill Boucher

http://www.ccsinfo.com/forum/viewtopic.php?p=39163&highlight=#39163

The part where he mentions the tx pin of the master can go to the rx pins of the slaves and the tx pins of the slaves can be can go to the rx pin of the master. I think this will work for me, I will let you know.

As for re-inventing wheels, I forgot to design my project with wheels. So I am attempting to fix my skis.

Thanks for the help. Next time I will use a max232 chip or go with an equivalent rs485 chip.
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