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 support@ccsinfo.com

How many software UART's could we use on a pic?

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



Joined: 21 Apr 2008
Posts: 3

View user's profile Send private message

How many software UART's could we use on a pic?
PostPosted: Fri May 02, 2008 2:03 pm     Reply with quote

i will have a pic network with three slaves and with a master. 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.. Could i use a hardware uart and three software uarts on master pic..if yes; i want to use the interrupt function only between pic and pc...is it possible?

PIC; master 16f877, slaves;16f628a


Thanks,
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 02, 2008 2:45 pm     Reply with quote

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

View user's profile Send private message

Re: How many software UART's could we use on a pic?
PostPosted: Fri May 02, 2008 3:45 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 02, 2008 5:34 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 02, 2008 9:05 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri May 02, 2008 10:11 pm     Reply with quote

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 Very Happy
For multiple serial devices, RS485 is the way to go.
Andreas



Joined: 25 Oct 2004
Posts: 136

View user's profile Send private message

PostPosted: Sat May 03, 2008 2:42 am     Reply with quote

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

View user's profile Send private message Yahoo Messenger

PostPosted: Sat May 03, 2008 7:58 pm     Reply with quote

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.
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