Main Site Documentation

Chain Devices on Serial Bus


#1

I want to use a compass and accelerometer.

The accelerometer uses SDA, SCL and an interrupt.

The compass ans gyro are also i2c devices.

Is it possible to chain these devices - hook them to the same i2c bus?


#2

Yes of course this is how i2c works anyway. See i2c tutorial please.


#3

That is one of the I2C strong points multiple devices on same bus. Check code site and wiki.


#4

Sorry, I was not clear.

I have used the i2c bus.

I have a bunch of devices. All the type-I sockest on my spider are full.

I need to have one more i2c device.

Mechanically, how do I do this?


#5

You will have to do some hardware and some software changes but should be easy.

For start you need 2 extender boards to do the needed wiring.


#6

Ah! Thanks.

I wire two extenderboards 1:1 using the breakout pins.

Then, I can connect three i2c devices to one type-I socket.

Then, following the example, I create deviceA, deviceB, and deviceC

To communicate with device B, I use

MyI2C.Config = conDeviceB;


#7

VC# does not like modifications to Program.generated.cs as long as I had the connect file open, when I did a save all, Program.generates.cs reverted.

Hint: to do this, make the initial connections, close Program.gadgeteer then make modifications to Program.cs.


#8

I think this is worry writing tutorials for as it will benefit others.

The Interrupt pin can’t be shared depending on the chips used.


#9

I was just looking at the code on codeplex.

The interrupt will go to the last device initialized.

From the GPS module code,


this.interruptInput = new GTI.InterruptInput(socket, GT.Socket.Pin.Three ...

So, unless the interrupt handler is modified to call service routines for other devices, this seems not possible.

And, the handler selection is dependent on the order of device initialization.

In generable, not manageable.


#10

I think I have a way to do this.

Create a critical section so that only one of
compass.RequestMeasurement
or
accelerometer.RequestMeasurement
may be executed.

The critical section is released in the interrupt handler.

In Program.generates.cs,


extender1 = new GTM.GHIElectronics.Extender(4);
compass = new GTM.Seeed.Compass(extender1.ExtenderSocketNumber);
accelerometer = new GTM.Seeed.Accelerometer(extender1.ExtenderSocketNumber);

In Program.cs


void i2c_handler(void *sender, void *data) 
{
  if (compass) enderSocketNumber);
  else if (accelerometer) accelerometer_MeasurementComplete(sender, data);
   else throw new InvalidOperationException();
 }

Question:
What casts do I need to make this work?

I ordered a couple extenders to test this.


#11

I like us ot test this and make a tutorial for it. We may ave it done by the time you get the extenders.


#12

I have been thinking about chaining devices.

Maybe the most simple way is a cable with N + 1 connectors to chain N devices


#13

Gus,

Any progress on this?

Tom Dean