This question is more of a generic question in which I'm seeking an optimized algorithm.
Basically I have two microcontrollers. One runs at a speed 6x slower than the other. Special feature pins of the micros are used up and all I have are two GPIO pins from each one for communication. One pin is the clock and one is data.
What I'm trying to do is have the slow micro request initial information from the faster micro. For example, I'm sending byte 5A to the faster micro and I expect it to return A5 but it does not.
Here's the code I tried:
For Slow micro that wants information
For Fast micro that has information
What am I doing wrong?
Basically I have two microcontrollers. One runs at a speed 6x slower than the other. Special feature pins of the micros are used up and all I have are two GPIO pins from each one for communication. One pin is the clock and one is data.
What I'm trying to do is have the slow micro request initial information from the faster micro. For example, I'm sending byte 5A to the faster micro and I expect it to return A5 but it does not.
Here's the code I tried:
For Slow micro that wants information
;request
set counter to 8
Start loop
rotate right LSB from accumulator to Carry
set GPIO pin to Carry value
lower clock
raise clock
decrement counter
restart loop if counter isn't 0.
;response
set counter to 8
Start loop
lower clock
raise clock
get Carry value from GPIO pin
rotate right Carry into MSB of accumulator
decrement counter
restart loop if counter isn't 0.
For Fast micro that has information
;get request
set counter to 8
Start loop
wait until clock is low
get Carry value from GPIO pin
rotate right Carry into MSB of accumulator
wait until clock is high
decrement counter
restart loop if counter isn't 0.
if accumulator is 5A then
set accumulator to A5
end if
;do response
set counter to 8
Start loop
wait until clock is low
rotate right LSB from accumulator to Carry
set GPIO pin to Carry value
wait until clock is high
decrement counter
restart loop if counter isn't 0.
What am I doing wrong?