Currently I have two microcontrollers setup in which entire ports are connected to each other (P1.1 connected to P1.1, P1.2 connected to P1.2, etc). I also have two pairs of extra GPIO pins connected as signal lines.
What I want to achieve is a way to send and receive a byte in as little time as possible.
Let's assume that the master requests the slave to add 1 to a number and the slave responds:
Here's my code so far for the slave microcontroller:
SLAVEDATA equ P1
SLAVEACK equ P2.0
SLAVECMD equ P2.1
jnb SLAVECMD,$ ;wait for command
mov SLAVEDATA,#0FFh ;tristate to allow input
nop ;wait how many uS?
mov A,SLAVEDATA ;see what number came in
inc A ;add 1
mov SLAVEDATA,A ;produce result
setb SLAVEACK ;send acknowledgement
jb SLAVECMD,$ ;wait till remote lowers comand line
clr SLAVEACK ;clear acknowledgement
;transaction complete
And here's the code for the master:
MASTERDATA equ P0 ;Master's P0 connects to slave's P1
MASTERACK equ P3.0 ;Master's P3.0 connects to slave's P2.0
MASTERCMD equ P3.1 ;Master's P3.1 connects to slave's P2.1
mov MASTERDATA,#20h ;Set number to 32
setb MASTERCMD ;tell slave to increment
jnb MASTERACK,$ ;wait until its done
mov MASTERDATA,#0FFh ;tristate port to allow input
nop ;delay by how many uS?
mov A,MASTERDATA ;Get result here
clr MASTERCMD ;tell slave were done
jb MASTERACK,$ ;wait until slave understands this
While I believe this code mostly works, I'm just not sure how long to make the program wait between the time the port pins are set to high and the time valid data is read on the pins.
If I don't wait at all, then I will get incorrect data. I believe it has to do with the FET's inside my AT89C4051 and AT89S52 that I am using but the manual does not indicate how long I should wait.
Both micros have the same crystals, capacitors and PCB track arrangements for the crystals and capacitors.
Each capacitor is 33pF ceramic
Each crystal is 22.1184Mhz which came out of the same package
Each PCB track in which the leads of the crystal are connected to is 1.9mm wide.
How do I calculate the minimum number of NOPs in my code so that valid data can be captured on the port pin after tristating it?
Also, because each micro has the same clock driving circuitry, could I replace the stalls (waiting for acknowledgements for example) with three nops? or will I still experience a minor clock drift?