| Author |
Message |
winit_a
Joined: 16 Nov 2003 Posts: 17
|
15 Feb 2004 5:42 How to Create UART with Software (not used SBUF) on 8051 |
|
|
|
How to Create UART With Software?
My project Used 3 UART (normal have 1 UART with HARDWARE P3.0 and P3.1)
8051 MCU @ 11.0592MHz
How to Create UART used P2 or P1 to Interface RS-232
|
|
| Back to top |
|
 |
pisoiu
Joined: 31 Dec 2002 Posts: 900 Helped: 24 Location: Romania
|
15 Feb 2004 11:58 Re: How to Create UART with Software (not used SBUF) on 8051 |
|
|
|
Hi,
My opinion: it is damn hard. You will have to do it using interrupts, but 8051 is a relatively slow controller, its performance stays under 1mips at 11,0592mhz clock for clasic 8051 versions (1instruction cycle=12 clock cycle). More than one serial port implemented in software will eat almost all processor time, especially if you want to go up to 115200bps with those ports, or if you want to implement all possible parameters (6/7/8 data bits selecteble, 1/2 stop bits, parity odd/even/mark/space/none, flow control selectable xon-xoff/hard/none). My sugestion is to use an modified architecture 8051 from cypress, or to use a scenix microcontroller ( www.ubicom.com ). For scenix controller I can provide code for 8 uarts simultaneously. This if you want a software implementation. If yau want hardware, you can use max3100 (maxim).
Best,
|
|
| Back to top |
|
 |
Ajay
Joined: 29 Feb 2004 Posts: 31
|
01 Mar 2004 0:10 Re: How to Create UART with Software (not used SBUF) on 8051 |
|
|
|
You could create one UART (in addition to using the SBUF) by using a dedicated timer and writing very fast code to rotate bit. On the incoming side (RXD), you must use an interrupt pin. When the interrupt comes, start your timers and read the pin status into carry, rotate and create your incoming bytes. Works well upto 9600 Baud (I have used it).
However, creating two MORE at the same time? Forget it. Even if you use two dedicated timers, the interrupt routines become so big that you will miss bits.
If you are looking for slow UARTs (1200 Baud or slower), then this technique works for upto 2 UART's. Keep in mind that you will give up all the three timers (one used for baud rate gen for SBUF, one for port 1 and one for port 2 timing) as well as both the interrupts.
So, better design is to use an ARM chip with two UART's (I have created 2 additional UARTs at 19200 Baud with an ARM) or use the Rabbit controller or some such thing.
Ajay
|
|
| Back to top |
|
 |
beuch
Joined: 06 Jun 2001 Posts: 65 Location: France
|
03 Mar 2004 14:45 Re: How to Create UART with Software (not used SBUF) on 8051 |
|
|
|
Hi,
have a look to the attached file from Philips web AN.
AN446
bye
|
|
| Back to top |
|
 |
crazytnt
Joined: 02 Feb 2004 Posts: 8
|
03 Mar 2004 17:43 Re: How to Create UART with Software (not used SBUF) on 8051 |
|
|
|
It's very difficult.
Suggest using hardware.
|
|
| Back to top |
|
 |
J_expoler2
Joined: 10 May 2003 Posts: 179 Helped: 19
|
03 Mar 2004 18:00 Re: How to Create UART with Software (not used SBUF) on 8051 |
|
|
|
Hi
i have some idea UART but send data only by using timer 0
bit T232 as TxD
MOV TMOD,#22H
MOV TH0,#70H
MOV TL0,#70H
SETB EA
SETB ET0
SETB TR1
;
;
;
;
function send data:
CLR T232 ;START BIT
SETB TR0
MOV R7,#8
TX_LOOP: RRC A
JNB TF0,$
MOV T232,C
CLR TF0
DJNZ R7,TX_LOOP
JNB TF0,$
SETB T232 ;STOP BIT
CLR TF0
JNB TF0,$
RET
it maybe help u
BR.
|
|
| Back to top |
|
 |
fireplus
Joined: 31 Oct 2003 Posts: 198 Helped: 5
|
04 Mar 2004 3:29 Re: How to Create UART with Software (not used SBUF) on 8051 |
|
|
|
try that
[hr:5c6e3c7296]
Fire in the Wire :sm2:
|
|
| Back to top |
|
 |
Ajay
Joined: 29 Feb 2004 Posts: 31
|
08 Mar 2004 12:28 Re: How to Create UART with Software (not used SBUF) on 8051 |
|
|
|
| J_expoler2 wrote: |
Hi
i have some idea UART but send data only by using timer 0
bit T232 as TxD
MOV TMOD,#22H
MOV TH0,#70H
MOV TL0,#70H
SETB EA
SETB ET0
SETB TR1
;
;
;
;
function send data:
CLR T232 ;START BIT
SETB TR0
MOV R7,#8
TX_LOOP: RRC A
JNB TF0,$
MOV T232,C
CLR TF0
DJNZ R7,TX_LOOP
JNB TF0,$
SETB T232 ;STOP BIT
CLR TF0
JNB TF0,$
RET
it maybe help u
BR. |
This is only good for transmitting. Problem comes when you try to receive as well. First of all, this method will NEVER work for full duplex operation unless you use two DIFFERENT timers.
Moreover, for receiving, you will need to use a hardware interrupt which will precisely start the timer at the right time and then will help shift the data. Again, this method is only good as a half duplex communication.
Another complexity comes from the fact that the interrupt routines become long and will cause problems by missing bits. Keep in mind that the error will accumulate over a period of time!
The best way is to use a chip which has more serial ports (ARM, uPSD from ST etc.)
Ajay
|
|
| Back to top |
|
 |