View previous topic :: View next topic |
Author |
Message |
runtime
Joined: 15 Sep 2003 Posts: 36
|
software UART and hardware UART, please explain... |
Posted: Thu Jul 22, 2004 11:31 am |
|
|
Hello all,
This must be a silly question, but please explain to me the difference between a software UART and hardware UART, which is best? how do I implement a hardware UART? (PIC16F876)
Thank you in advance
Peter |
|
|
yeti Guest
|
uart |
Posted: Thu Jul 22, 2004 12:00 pm |
|
|
Hey,
A Hardware USART has dedicated circuitry etched into the micro's silicon. Therefor it takes almost zero code space and is always there regaurdless if you use it or not.
A Software USART uses code to transition output pins and read input pins in order to communicate. This takes up a fair amount of program space for the protocal, buffer, etc. expecialy if you are using advanded serial communications. But it is also the most flexible.
I use the hardware USART when ever possible - it's "free". I have not looked at the Pic you mentioned, so I don't even know if it has a hardware USART.
Have Fun |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Thu Jul 22, 2004 12:18 pm |
|
|
Software UARTs are more flexable. The CCS software UART can even invert the data if you want. If you write your own it can do anything. Howeve most software UARTs, like the CCS one, consume all the CPU time while they are operating. This means while you are transmitting or receiving a character the CPU can do nothing else.
However the CCS recieve routing actually finishes at the middle of the Stop bit. That means you can recieve a command byte at a time and interpret each byte in the latter half of its Stop bit. This is very useful if you don't have RAM to spare buffering a whole serial message. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jul 22, 2004 12:27 pm |
|
|
Whenever possible use a hardware UART! It has the following advantages:
- Your code can do other things while 'in the background' the hardware is receiving data. Communicating at 9600 baud a single character takes 1ms, imagine how much code you can execute in this time.
- A hardware UART is more stable because it's timing is not affected by interrupts (A SW UART must disable the interrupts).
- It can buffer 3 incomming characters and 1 outgoing character.
- Much higher baudrates are possible.
- Automatic checking of the parity bit is possible.
- Framing and overrun errors are detected.
The only reasons for using a software based solution are:
- You need more serial ports than there are HW UARTS on your chip.
- Your communication uses 5, 6 or 7 databits.
- You want to save a few cents by not including an inverter chip like the MAX-232 but instead use a resitor/diode network. The software UART allows you to use the INVERT option for this.
For example code see the manual or search this forum for '#use RS232'. |
|
|
Guest
|
|
Posted: Sun Jul 25, 2004 9:57 am |
|
|
Hi, i am learning to program pics, and after read this topic, i want to see a sample, please.
a sample of hardware and software, please someone can post it?
for 16f627 or 16f628 or 12c509 or 16f876 or 16f870
thanks |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Jul 25, 2004 12:21 pm |
|
|
Like I said before: Look in your manual for the instruction '#use RS232' or uses the search function of this forum with the same keywords.
This question has been asked so many times that you will find many good answers anfd other helpfull information. |
|
|
|