1
\$\begingroup\$

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

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

update

This is my setup:

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.

\$\endgroup\$
  • \$\begingroup\$ Can you please explain why even bother with this? 8051 is an ancient artifact. The fact you have to bit-bang communication, means your hardware is absolutely not matching your requirements. Pick a modern microcontroller with hardware UART and a decent C compiler (BTW, there is C compiler for 8051, but see the above). \$\endgroup\$ – Eugene Sh. Oct 16 '17 at 14:20
  • 3
    \$\begingroup\$ The maxim App note refers to an SPI port, you appear to be implementing a UART port. \$\endgroup\$ – Steve G Oct 16 '17 at 14:28
  • 1
    \$\begingroup\$ Can you tell us what you are trying to achieve, exactly? Connect two 4051's together? And you cannot use the hardware UART? Because it's used for something else? \$\endgroup\$ – PkP Oct 16 '17 at 14:40
  • 1
    \$\begingroup\$ Better to make a synchronous serial interface, e.g. one with a clock signal, than asynchronous. What's your speed requirement and how much data do you need to transmit? Are there separate IO lines between your S52 and all 4051's? \$\endgroup\$ – PkP Oct 16 '17 at 15:06
  • 1
    \$\begingroup\$ @Mike Just as an aside, I've got a box of (100) 80C32 devices laying here about two feet from where I'm sitting now and I've programmed commercial devices (less than 10 years ago) from SiLabs using their 8051 core on the C8051F061 device. And my very first 100%-my-own-design used an 8031 to convert an IBM model 85 electronic typewriter into a printer. So I don't have any arguments about "ancient" devices, etc., as others may. The 8051 remains and people should stop sitting on a high horse about it. There are still places for the core. \$\endgroup\$ – jonk Oct 16 '17 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy