Go Down

Topic: How Are Masters and Slaves designated in I2C and SPI connections? (Read 1 time) previous topic - next topic

012anonymousxyz

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.

fungus

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

Can either of them start a conversation? Only one of them...?
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)


Denbo


Docedison

I read that link and..
I Think This phrase is incorrect
Quote
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
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

012anonymousxyz

#5
Feb 08, 2013, 08:03 pm Last Edit: Feb 08, 2013, 08:11 pm by 012anonymousxyz Reason: 1
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.

Denbo


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

012anonymousxyz


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?

SirNickity

#8
Feb 08, 2013, 09:40 pm Last Edit: Feb 08, 2013, 09:44 pm by SirNickity Reason: 1
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.

Denbo


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.

http://arduino.cc/en/Reference/WireBegin

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

012anonymousxyz

*Bows head*

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

012anonymousxyz

#11
Feb 08, 2013, 10:00 pm Last Edit: Feb 08, 2013, 10:02 pm by 012anonymousxyz Reason: 1

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!

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

Denbo


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   :)

Graynomad

Quote
It is setting it by default to 100Mhz.

Don't we wish, maybe 100kHz :)

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Go Up