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!!

Majenko
106k5 gold badges81 silver badges139 bronze badges
asked Jul 1, 2016 at 10:12

1 Answer 1

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:

answered Jul 1, 2016 at 10:31
2
  • Thanks for the heads up regarding Bus arbiteration. Will try this out and hopefully, it works! Commented Jul 4, 2016 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? Commented Jul 4, 2016 at 4:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.