Pages: [1] 2   Go Down
Author Topic: How Are Masters and Slaves designated in I2C and SPI connections?  (Read 1397 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 146
Posts: 5522
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Florida, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Hugo
Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 69
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 47
Posts: 2892
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

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

Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: February 08, 2013, 02:11:48 pm by 012anonymousxyz » Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 69
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Anchorage, AK
Offline Offline
Edison Member
*
Karma: 42
Posts: 1176
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: February 08, 2013, 03:44:49 pm by SirNickity » Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 69
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

*Bows head*

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

Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
« Last Edit: February 08, 2013, 04:02:15 pm by 012anonymousxyz » Logged

Anchorage, AK
Offline Offline
Edison Member
*
Karma: 42
Posts: 1176
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Jr. Member
**
Karma: 2
Posts: 69
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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   smiley
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 129
Posts: 8525
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
It is setting it by default to 100Mhz.
Don't we wish, maybe 100kHz smiley

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: [1] 2   Go Up
Jump to: