I2c

I am trying to talk to multiple I2C devices on the I2C bus. I get errors when creating the second I2C device. The second device on a different address. Is this a known thing?

Aha! I knew this would come but it took longer than expected :o
Not sure why Microsoft called it I2CDevice. This should have been named I2CBus since this object is for the “bus” and not the “device”. So, you can only create one object since there is only one I2C bus…make sense?

What you need is multiple I2CDevice.Configuraion, one for each device.

Here you go…

// init
I2CDevice I2CBus = new I2CDevice(null);
I2CDevice.Configuration config1 = new I2CDevice.Configuration(0x40, 100);
I2CDevice.Configuration config2 = new I2CDevice.Configuration(0x44, 100);
//use device 1
I2CBus.Config = config1;
//...
//...
//use device 2
I2CBus.Config = config2;
//...
//...

You can have multiple devices (slaves) on the I2C bus, each with an unique address. What errors are you getting ?

Gus replied before I did :slight_smile: ** Please ignore my post

very difficult to keep with the super fast one :slight_smile:

Thanks Gus will work out this into the Wii code so i can do nunchuck and Wii motion plus on same bus along with my other 2 i2c devices.

I hope you might get everything sorted. I believe something is wrong. But I do not know where.

We’ll see :wink:

Yeah my reading were weird using the supplied drivers. I am using a bus pirate to decode some live wii remote testing to help me out.

I hope you get it sorted!

Hi,

Sorry to jump in on this thread. Would this be the same for the SPI bus as well?

I am only able to find 1 reference to connecting several devices to a single SPI bus and that just mentions it in passing…

Also what issues if any are there with bus contention. I am guessing that the framework will buffer the data but as I say I can’t find a thing about it.

Thanks in advance.

Andy

Yes same for SPI. Create one object and assign a new configuration for each SPI slave