I was looking at: https://www.maximintegrated.com/en/app-notes/index.mvp/id/3524 and it claims that one can achieve over 2mbps on a 32Mhz clock when bit-banging with an 8051. That means 1mbps on 16Mhz. I'm using a clock greater than 16Mhz and feel I can only achieve a max of 19.2kbps.
I looked at their source code and it doesn't really help. I did borrow code snippets for I2C protocol for the 8051 but thats an overkill.
Because the two 8051s I'm dealing with run at the same clock speed and have the same capacitors connected to the crystal, theres a good chance I'd get this code to work. A safer approach I used in the past was to add extra check code (example: jnb clocktriggered,$ and jb clocktriggered,$) to make sure the byte was read, but that uses an additional 2 clock cycles per bit.
I apologize for the extra long code, but I deliberately repeated code instead of using loop control in order to save an additional 2 clock cycles.
I also considered using interrupts but each interrupt call wastes at least 4 clock cycles. 2 to jump to a new address and 2 to return from the interrupt address.
The microcontroller I'm trying to optimize this for is for an AT89C4051-12PU: http://www.kynix.com/Detail/95559/AT89C4051-12PU.html
So how can the people at Maxim get such a high speed (16000kbps+) and I cant? Is it because they jam features into their 8051 microcontroller that allows them to achieve such speeds?
;RUN=logic high starts data transfer
;DIN=Data input
;DOUT=Data output
;Worst case total cc (clock cycles): 39
;Crystal used: 22.1184Mhz
;Max UART speed = 22118400 / (39cc * 2 * 12) = 23.6K. Convert to standard = 19.2K
main:
jnb RI,nrcv ;2cc
mov R7,SBUF ;1cc
nrcv: ;3cc total receive from serial
jnb RUN,main ;2cc
jb RUN,$ ;2cc
jnb IO,nosxmit ;2cc
nosrcv: ;uC to serial
CLR A ;had to add nops to align with receiver
nop
nop
mov C,DIN
RRC A
nop
mov C,DIN
RRC A
nop
mov C,DIN
RRC A
nop
mov C,DIN
RRC A
nop
mov C,DIN
RRC A
nop
mov C,DIN
RRC A
nop
mov C,DIN
RRC A
nop
mov C,DIN
RRC A
jnb TI,$ ;Trying to make it where program doesn't stall forever waiting for transmission
CLR TI
mov SBUF,A
ajmp main ;36cc total transmit
nosxmit: ;Serial to uC
mov DOUT,C
mov A,R7
RRC A
mov DOUT,C
RRC A
mov DOUT,C
RRC A
mov DOUT,C
RRC A
mov DOUT,C
RRC A
mov DOUT,C
RRC A
mov DOUT,C
RRC A
mov DOUT,C
RRC A
mov DOUT,C
ajmp main ;33cc total receive
This is my setup:
As you can see, for the main master (AT89S52) there is one UART which is used by the computer. I have 4 GPIO pins I can use with the AT89C4051. The UART on that micro is used by the HM-TRP wireless transceiver module.
I'm trying to make a game which requires each device in turn to connect with the server since the HM-TRP is half-duplex.
And why bother with older hardware? Its lower priced and I already learned how to use it and I already made PCB's for it.
I looked at their source code and it doesn't really help. I did borrow code snippets for I2C protocol for the 8051 but thats an overkill.
Because the two 8051s I'm dealing with run at the same clock speed and have the same capacitors connected to the crystal, theres a good chance I'd get this code to work. A safer approach I used in the past was to add extra check code (example: jnb clocktriggered,$ and jb clocktriggered,$) to make sure the byte was read, but that uses an additional 2 clock cycles per bit.
I apologize for the extra long code, but I deliberately repeated code instead of using loop control in order to save an additional 2 clock cycles.
I also considered using interrupts but each interrupt call wastes at least 4 clock cycles. 2 to jump to a new address and 2 to return from the interrupt address.
The microcontroller I'm trying to optimize this for is for an AT89C4051-12PU: http://www.kynix.com/Detail/95559/AT89C4051-12PU.html
So how can the people at Maxim get such a high speed (16000kbps+) and I cant? Is it because they jam features into their 8051 microcontroller that allows them to achieve such speeds?
;RUN=logic high starts data transfer
;DIN=Data input
;DOUT=Data output
;Worst case total cc (clock cycles): 39
;Crystal used: 22.1184Mhz
;Max UART speed = 22118400 / (39cc * 2 * 12) = 23.6K. Convert to standard = 19.2K
main:
jnb RI,nrcv ;2cc
mov R7,SBUF ;1cc
nrcv: ;3cc total receive from serial
jnb RUN,main ;2cc
jb RUN,$ ;2cc
jnb IO,nosxmit ;2cc
nosrcv: ;uC to serial
CLR A ;had to add nops to align with receiver
nop
nop
mov C,DIN
RRC A
nop
mov C,DIN
RRC A
nop
mov C,DIN
RRC A
nop
mov C,DIN
RRC A
nop
mov C,DIN
RRC A
nop
mov C,DIN
RRC A
nop
mov C,DIN
RRC A
nop
mov C,DIN
RRC A
jnb TI,$ ;Trying to make it where program doesn't stall forever waiting for transmission
CLR TI
mov SBUF,A
ajmp main ;36cc total transmit
nosxmit: ;Serial to uC
mov DOUT,C
mov A,R7
RRC A
mov DOUT,C
RRC A
mov DOUT,C
RRC A
mov DOUT,C
RRC A
mov DOUT,C
RRC A
mov DOUT,C
RRC A
mov DOUT,C
RRC A
mov DOUT,C
RRC A
mov DOUT,C
ajmp main ;33cc total receive
This is my setup:
As you can see, for the main master (AT89S52) there is one UART which is used by the computer. I have 4 GPIO pins I can use with the AT89C4051. The UART on that micro is used by the HM-TRP wireless transceiver module.
I'm trying to make a game which requires each device in turn to connect with the server since the HM-TRP is half-duplex.
And why bother with older hardware? Its lower priced and I already learned how to use it and I already made PCB's for it.
10006 Hits