I'm trying to figure out the best way to integrate all devices flawlessly on the 8051 based microcontrollers. If each device was the same low speed, then I could multiplex each and every one of them within the timer routine by itself and forget about the serial interrupt, but one device needs to run about 10x faster. But I found a bottleneck...
Surely the optimal way is to have an interrupt for the serial routine and one for the timer so everything supposedly executes cleanly. I drafted rough code below:
Org (Timer) (insert software uart routines here) reti Org (Serial Interrupt vector) push PSW mov PSW,#SERIALBANK jbc RI,gotabyte jbc TI,sentabyte exitserial: pop PSW reti gotabyte: mov CHAR,SBUF ajmp exitserial sentabyte: inc R1 cjne R1,#ENDOFBUF,notend ajmp exitserial notend: mov SBUF,@R1 ajmp exitserial
But there's a major problem. It seems that I can either receive and send data correctly on the higher speed device while having all the lower-speed devices out of sync (just because the serial interrupt has priority and delays execution of the timer handling the remaining UARTs by the time it takes to finish its interrupt), or I can have all low-speed devices work correctly while the high-speed device is out of sync (just because of the opposite situation... timer runs right at a bad time while the serial routine attempts to send or receive data). Trust me, I even ran a timer and have the TI and RI flags checked at a much higher speed than that of the UART and that even returned inaccurate data.
So I thought of an idea
Based on my past circuit boards and the hardware available to me, I'm thinking of offloading most of the serial routines to another 8051 based microcontroller (AT89C2051) since much of the serial data coming into the main system is almost immediately discarded after processing (such as checksum).
Question is, how do I best do data transfer between the two microcontrollers?
As It stands, I can make extra uarts and have all run at a slow speed on the main microcontroller, but I'm trying to think of a way to send the data back and forth reliably over three wires without introducing serious lags on either side to the point where data on any device is out of sync.
One may suggest SPI but that involves having one microcontroller stall until the clock line is set. Making it a UART line won't work because the smaller microcontroller that's connected to the high-speed radio might lose characters because the serial routine will constantly interrupt data flow.
If my idea of using two micros is best for my situation, then can someone point me to a good asynchronous data protocol I can go for using only three wires?
For clarity in my diagram, S1 through S4 are individual sensors, and RIN and ROUT are connections to the radio module. DIN, DOUT and DCLK are Data In, Data Out, and Clock, but those names could be changed later.
Both micros are run by independent 22.1184Mhz crystals with 33pF ceramic capacitors connected between each crystal pin and ground.