How Are Masters and Slaves designated in I2C and SPI connections?

Hello and thanks a lot! I'm really sorry if this is an annoying question that is obvious but I attempted to google it with no success.
Today is a snow-day here but (on Monday now) I am going to attempt to connect my Arduino to another Arduino.

It depends on how they need to communicate to each other.

Can either of them start a conversation? Only one of them...?

This is a great place to start... I hope it helps.

http://www.i2c-bus.org/i2c-primer/

Hugo

Why not just look at the tutorial on the Arduino website? http://arduino.cc/en/Tutorial/MasterReader

I read that link and..
I Think This phrase is incorrect

iIf powering the Arduinos independently is an issue, connect the 5V output of the Master Arduino to the VIN pin on the slave.

As the Vin porrt is the input to the regulator and would underpower the second Arduino by the inherent I/O differential of the second regulator because of the 5V source, The sentence should read:
If powering the Arduinos independently is an issue, connect the VIN Pin on the Master Arduino to the VIN pin on the slave.
This will work without issue.. as long as you remember to "Connect the Grounds".

Bob

According to what I read, in a scenario where multiple devices have the capability to be a master, or simply just in general, the master is the one which chooses the clock speed.
But I also read the code example in the link provided, and I don't see where the master Arduino set the speed. If in the line:
Wire.begin(); // join i2c bus (address optional for master)
One adds the optional parameter for the master Arduino, the code is practically the same.

012anonymousxyz:
But I also read the code example in the link provided, and I don't see where the master Arduino set the speed. If in the line:

It is setting it by default to 100Mhz. See this post for how to change that http://arduino.cc/forum/index.php/topic,16793.0.html

Denbo:
It is setting it by default to 100Mhz. See this post for how to change that http://arduino.cc/forum/index.php/topic,16793.0.html

Okay, so the Wire.begin(); sets the clock speed. But both Arduinos have a command in their code called Wire.begin(). So whos becomes the master?

The one that starts talking. There isn't any hardware difference. If you speak without being spoken to, you're the master. You can have multiple masters. The slave is merely any device that has been addressed by a/the master. This is why the master doesn't have to assign itself an address. If no one is going to direct communication at you (except in reply), there's no real need for an address.

Contention on i2c is resolved by holding the clock. If you read the data bus after transmitting your data and the line is not high, it's because someone else caused a collision. These are resolved by the bit pattern. The one holding the line low the longest wins.

SPI is different. Electrically, there is a master and one or more slaves. This determines which pin is set as an output and which is an input, and how you deal with slave select -- either listening for it or toggling digital output pins to select other ICs.

012anonymousxyz:
Okay, so the Wire.begin(); sets the clock speed. But both Arduinos have a command in their code called Wire.begin(). So whos becomes the master?

If you read the Wire.begin() reference you would see the following:
Parameters
address: the 7-bit slave address (optional); if not specified, join the bus as a master.

Go look at the link I provided in an earlier post in this thread. It shows both the master and slave code examples.

Bows head

I truly and greatly appreciate your help.
Yes, I skimmed through it, and that was my mistake. I appreciate the help!

SirNickity:
The one that starts talking. There isn't any hardware difference. If you speak without being spoken to, you're the master. You can have multiple masters. The slave is merely any device that has been addressed by a/the master. This is why the master doesn't have to assign itself an address. If no one is going to direct communication at you (except in reply), there's no real need for an address.

Contention on i2c is resolved by holding the clock. If you read the data bus after transmitting your data and the line is not high, it's because someone else caused a collision. These are resolved by the bit pattern. The one holding the line low the longest wins.

SPI is different. Electrically, there is a master and one or more slaves. This determines which pin is set as an output and which is an input, and how you deal with slave select -- either listening for it or toggling digital output pins to select other ICs.

I somehow missed this post! But it makes the most sense. Because if you go ahead and provide the optional parameter to a master, according to the description, it should not join the bus as a master.
But the one that talks is the one that sets the clock speed makes sense. The "master" switches between the two Arduinos.
I appreciate it!

Yep! I find many tutorials to be great at explaining how to accomplish a simple task, but not so great at explaining how it's actually done under the hood. A true understanding of how it all really works goes a long way in making sure your designs will handle corner cases or unique configurations.

I tend to reinvent the wheel a lot as a way of quizzing my own understanding. Writing my own AVR C modules for these things quickly points out the areas I don't know as well as I think I do. Then, it's back to data sheets and blog posts I go. I'm happy to be able to pass on the knowledge that I've collected from so many other incredibly valuable sources along the way.

SirNickity:
Yep! I find many tutorials to be great at explaining how to accomplish a simple task, but not so great at explaining how it's actually done under the hood.

In the case of I2C, a cheap logic analyzer goes a long way as well :slight_smile:

It is setting it by default to 100Mhz.

Don't we wish, maybe 100kHz :slight_smile:


Rob

Graynomad:
Don't we wish, maybe 100kHz :slight_smile:

Hate it when I do that. :blush: