Pages: [1]   Go Down
Author Topic: arduino as I2C slave communicate with sensor?  (Read 1014 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using an arduino acting as a slave on an i2c bus request bytes from a i2c sensor that is also a slave?

In my case the arduino is talking to a Lego NXT (which must be set as the master) and the sensor is a three axis magnetometer.

I could have the NXT read the magnetometer and relay it to the arduino, but that would be pretty slow.
Logged

Offline Offline
Edison Member
*
Karma: 3
Posts: 1001
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm using an arduino acting as a slave on an i2c bus request bytes from a i2c sensor that is also a slave?
If the question is, whether a single Arduino can act both as master and slave on the same bus, the answer is - yes. Just call the approriate functions in the wire library and you become a slave, master or both.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm still a bit confused.  If the arduino acts as a master and and a slave at the same time.  Does the master NXT set the clock for the arduino and the arduino set the clock for the i2c sensor?
Logged

Offline Offline
Edison Member
*
Karma: 3
Posts: 1001
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Does the master NXT set the clock for the arduino and the arduino set the clock for the i2c sensor?
Yes - that is the way it works. Support for multiple masters, including bus arbitration is part of the I2C specification.

There may be potential issues however if two masters try to read from the same sensor simultaneusly. This is not due to limitations in the I2C protocol, but the Arduino Wire library.
Logged

Pages: [1]   Go Up
Jump to: