View previous topic :: View next topic |
Author |
Message |
akokyaw
Joined: 11 Feb 2005 Posts: 24
|
Difference between use of USART module and bitbang |
Posted: Tue Oct 18, 2005 6:59 pm |
|
|
Hi,
I found that 16F877 has USART module for serial communication. For this application, I have two options for writing code:
(1) by using USART registers such as BRGH, SPBRG (hardware)
(2) by using #use rs232(baud=9600, xmit=PIN_A3, rcv=PIN_A2) (software)
I believe there are some major differences. I feel that bitbang is easier to use. Does anyone know about the difference between use of USART module (hardware) and bitbang (software)? What are the advantage and disavantage?
Thank you,
ako |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Tue Oct 18, 2005 8:46 pm |
|
|
The #use RS232 statement will use the embedded hardware UART if the tx and rx pins you define are the same as the ones used by the hardware and provided you do not use the force SW flag.
Wherever possible you should use the HW UART. If you use the software UART you have to be continuously calling kbhit() at multiple times the bit rate to ensure you do not lose characters or bits.
If you want to use a Rx interrupt handler then you need to use the HW UART as the SW implementation does not support Rx interrupts. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Last edited by asmallri on Wed Oct 19, 2005 2:44 am; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
akokyaw
Joined: 11 Feb 2005 Posts: 24
|
|
Posted: Wed Oct 19, 2005 2:26 am |
|
|
Hi,
Thank for reply, Andrew. Now, I understand that bitbang (software) has to use initialization routine while USART module (hardware) has to use interrupt such as (TXIF). Anyway, CCS's printf function is intelligent and useful bitbang.
what condition we must use USART module except we need interrupt?
Regards,
ako |
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Wed Oct 19, 2005 2:55 am |
|
|
Quote: | Now, I understand that bitbang (software) has to use initialization routine |
The bitbang approach requires more software polling. If you think about it the software approach requires the CPU to be able to accurated detect each bit of a serial data stream. The hardware approach means the CPU only has to detect each character. Far fewer CPU cycles are required to reliably receive the data stream.
Quote: | while USART module (hardware) has to use interrupt such as (TXIF) |
The Hardware does not HAVE to use Interrupts (although it does read the interrupt flag TXIF) but more accurately it ALLOWS receive interrupts to be used.
Quote: | Anyway, CCS's printf function is intelligent and useful bitbang.
what condition we must use USART module except we need interrupt? |
The software UART is half duplex. While it is sending it cannot receive (characters are lost). The hardware UART is full duplex PROVIDED you use a receive interrupt handler _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
![](templates/subSilver/images/spacer.gif) |
|