0

Can the following scenario exist? enter image description here Microcontroller 1 sends a code to microcontroller 2 to start reading sensor data. Then Microcontroller 2 reads sensor data from sensor and sends it back to microcontroller 1.

If such a scenario is possible, then how would the pseudo code for microcontroller 2 receive-event be?

Need help with this badly!!

1

Can the following scenario exist? Yes. Such a scenario is called Multi-Master.

If such a scenario is possible, then how would the pseudo code for microcontroller 2 receive-event be?

MCU 2 would just be set up as any other slave. It waits, as normal, for an instruction in whatever for you like. Once it receives that instruction in then switches into master mode and makes a normal request exactly as you would from MCU 1 if you wanted it to read the sensor.

  • On receive:
    • Set "run as master flag"
    • Disable slave mode

In loop:

  • If "run as master flag" is set:
    • Perform request to get data from sensor
    • Clear "run as master flag"
    • Enable slave mode

Running a multi-master system does have its own set of caveats and things you have to watch out for. You can read more about it here:

  • Thanks for the heads up regarding Bus arbiteration. Will try this out and hopefully, it works! – Chetan Rao Jul 4 '16 at 1:57
  • Hi again, wanted to try out your soultion, but had this question -How do you enable or disable slave mode on the arduino? – Chetan Rao Jul 4 '16 at 4:37

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.