View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri May 02, 2008 2:45 pm |
|
|
There are several methods to do a software UART. CCS does
it the most simple way. Of the three methods listed on the
following webpage, CCS is doing #3:
http://www.8052.com/faqs.phtml?FAQ=124758
Here's an example of method #1.
http://supp.iar.com/Support/?note=88469
I tried the method shown in that code of sampling 3x per bit cell,
and it does work. To do 3 soft UARTs (full duplex), plus the
hardware UART might be pushing the limits. You would have
to do some experiments.
---
Edit: Fixed typo.
Last edited by PCM programmer on Wed Feb 10, 2010 6:44 pm; edited 1 time in total |
|
|
RLScott
Joined: 10 Jul 2007 Posts: 465
|
Re: How many software UART's could we use on a pic? |
Posted: Fri May 02, 2008 3:45 pm |
|
|
What baudrate and what crystal speed do you have? This will determine if it is possible to run three software UARTs. It also matters what else needs to happen at the same time.
Robert Scott
Real-Time Specialties |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri May 02, 2008 5:34 pm |
|
|
Quote: |
i want to communicate all the slaves with master by rs-232..and the master communicates with computer also by rs-232(hardware uart)..so i need three software uart..
|
The only limit regarding how many software UART's is the pins availability in the MCU, its
internal speed and your skill to handle them.
In my opinion, RS232 is not the best choice because it has 2 big limitations:
1) Its inherent layer limitation (only 2 devices)
2) Maximum comunication distance: less than 20 mts
Instead I would use RS485 with all the advantages that it implies:
1) More than 32 Slaves in Half duplex mode sharing the same twisted pair (depending of
the signal quality/distance/speed)
2) Maximum comunication distance: up to 1200 mts.
3) High noise rejection.
Humberto |
|
|
KU5D
Joined: 10 Feb 2008 Posts: 46 Location: Asheville, North Carolina
|
|
Posted: Fri May 02, 2008 9:05 pm |
|
|
Exactly. If you're wanting to talk to multiple devices in the same room, or in the same building over hardware (wires), RS-485 is one way to go. You don't need multiple ports. With RS-485 you use the same port and merely address all the slaves. Even if RS-232 were a logical choice, which may be implied by the ease with which software uarts are implemented in the PIC, it has to be borne in mind that a software uart does not have all the advantages of a hardware uart. Communication with any degree of speed is best handled using interrupts, and the software uart does not lend itself easily to such an application. Timer interrupts on these ports can be a workable compromise (argh!), but otherwise you have to poll the ports. Complicated and time consuming. Finally, using any uart you are confined to the byte-oriented nature of the PIC.
Another option would be radio (or wires again) using an MSK modem such as the MX-469 and bit-banging the TX / RX using hardware interrupts. It's synchronous, mucho fast, doesnt' tie up any uarts, and you have more flexibility with roll-yer-own protocols. This would work in a master / slave arrangement much like RS-485 without the range limitations. _________________ Confidence is the feeling you have right before you fully understand the situation... |
|
|
baltazar_aquino
Joined: 16 Mar 2008 Posts: 27
|
|
Posted: Fri May 02, 2008 10:11 pm |
|
|
If you will use the old approach - Time Division Multiplexing - which practically means alloting a time slot for each data transfer - then the limit is just your available pins. But this is a very inefficient method and was used only in the early days of RS232 communication
For multiple serial devices, RS485 is the way to go. |
|
|
Andreas
Joined: 25 Oct 2004 Posts: 136
|
|
Posted: Sat May 03, 2008 2:42 am |
|
|
Hi,
Just for clarification, RS485 and RS232 is using the same protocol and is generated in the same way, the BIG difference between using RS232 and RS485 is just the way how to connect the units together.
Keep in mind when using RS485 you can only talk to ONE Device at a time, this means you need some overhead to manage to whom to talk at which time. Also unless you are using a 4 wire topology you have to make sure that none of the Slave Transmitters can be hung up, e.g. this means You can't get info from any other devices in that case.
My approach was always to have a hardware watchdog which canceled the enable line for the transmitter if it was not managed by the software !
If using a 4 wire system You are always able to send a reset sequence to all units in case of failure.
best regards
Andreas |
|
|
foodwatch
Joined: 18 Apr 2006 Posts: 66
|
|
Posted: Sat May 03, 2008 7:58 pm |
|
|
Sometimes simple is better. After toying with a similar problem, I solved it by steering the built in uart to each of two slaves by using a 74HC125D. It uses the built in RS232 port with two enable lines to switch to the slave you are addressing. There is no possibility of collisions and the code is easy to write. You could expand this to as many as you wish. Just keep in mind that it must be a master/slave arrangement. I use a simple int_rda routine to capture data. |
|
|
|