1

I am working on a library for some Arduinos that should talk between each other. The aim is that I can load the same binaries onto each Arduino. The I2C ID will be set by DipSwitches. So far everything works pretty nice but once a while everything gets stuck.

I am not asking you to resolve and debug my code, but I am not sure if i have done something completely wrong:

To make all Arduinos interchangeable I have no Master (Wire.begin()) in my I2C Bus.

I read, that the Master would be responsible for the pulse on the Clock line. As I have no Master in my setup maybe that is the reason for the instability.

Can anyone confirm that connecting some I2C Arduinos without master is something that cannot be done? (or do I have to look for some other reason)

  • 1
    Slaves are just waiting for a Master to ask them something. If there is no Master no slave will ever do something. Note that I2C can have multiple masters on the same bus. So either do something with that, or have the Arduinos wait a certain time (e.g. based on the id), to see if there is a master, and if not assume the role of master themselves. – Gerben Nov 16 '15 at 16:11
3

You have to have a master for an I2C bus to work. Can't you allocate one of the dip switches to define the master?

Edit to be able to remove the downvote Nick his answer seems to imply that you do not need masters but that is wrong. What Nick is saying is that you can swap masters over time.
But each time there is communication there is a master.
So the statement "You have to have a master for an I2C bus to work" is 100% right. As I misunderstood this myself I downvoted this answer. I hope this edit will enable me to remove my downvote and add a upvote.

  • I was still investigating and found some, who had the same demands that I had: actively send data from many Arduinos to the central Arduino and not wait for the Master that pulls the information from the Slaves. Look here or there according to what they say, it is possible to setup I2C Arduinos without Master. But my setup caused me headache. I changed the Concept and pull the data from the Slave. It only takes 2ms to pull from 10 Slaves that is fast enough – Hannes Morgenstern Nov 22 '15 at 15:20
  • As shown in the answer below it is possible. – jantje Apr 20 '16 at 16:59
  • @jantje - I don't think the answer below says you can have a working I2C bus without a master, because you need a master to transmit. I suppose as long as no one on the bus needs to transmit you don't need a master, but if there are no transmissions there isn't much need for the bus. – Code Gorilla Apr 21 '16 at 9:33
  • 1
    @matt - you are right. I can't remove the downvote yet (it states it is only 17 hours ago I voted :-( ) If I forget -> remind me. – jantje Apr 21 '16 at 10:54
2

Can anyone confirm that connecting some I2C Arduinos without master is something that cannot be done? (or do I have to look for some other reason)

There is no master except during transmissions. Thus it is possible to rotate the job of master if you want. You would need some way of deciding when it was a particular board's turn to be master.

I have code here on my RS485 page about how you can set up a rolling master using Serial communications. The same basic idea could be used to make a rolling I2C master.

  • Hi Nick, thank you for your reply, I was hoping that you find this question once. – Hannes Morgenstern Feb 10 '16 at 7:56
  • Hi Nick, thank you for your reply, I was hoping that you find this question once. I have read a lot about I2C on your invaluable website. Yes, a rolling master would have been a solution, but due to its complexity I stayed with one dedicated master that polls data from the the slaves. It is so fast, there was no drawback in responsiveness. What I like in your rolling master approach is that the system does not depend on the ONE Mater! I should have found it earlier. – Hannes Morgenstern Feb 10 '16 at 9:14
  • I am planning setup, where would be more Arduinos and more pasive devices (sensors - pure slaves) on the I2C bus. Each Arduino would "sit down" as slave and respond request, until it have something to say/demand. Then it stop being slave, "stands up" and start transmiting as a Master. After sending what had to be send and eventually getting all answers it igain "sits down" and became slave. So most of the time there are only slaves on the bus, sometimes there arise a Master for a moment. Arising 2 or more Masters solves the I2C protocol itself (first sending 0 get the bus) – gilhad Jan 4 '17 at 10:17

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.