November 9, 2016, 3:26pm
I have a I2C bus where I have two devices. Single device I can get it work, but a little bit more complicated to configure two devices and get it work. For example_
// OLED display
static I2CDevice.Configuration con = new I2CDevice.Configuration(SSD1306_I2C_ADDRESS, 400);
static I2CDevice I2C = new I2CDevice(con);
static I2CDevice.Configuration config = new I2CDevice.Configuration(0x40, 100); //device address is 0x40 or 1000000 (7 bit address)
static I2CDevice MyI2C = new I2CDevice(config);
but at some point I get and error that reserved pin or similar …
I think the MicroFrameWork consider there can not be two items that can reserve the bus…
Any hot tips how tohandle two or more deviced on same I2C bus?
https://www.ghielectronics.com/docs/12/i2c and scroll down to the Multiple Device section.
November 9, 2016, 4:15pm
You just have to use one config for every device. Then you can change the configs by using
If you access the I2C bus from different threads, remember to lock before you send commands.
I use this technique all the time as my touch panel is I2C and is processed in an interrupt and the ADC’s are all I2C on another thread. No issues as long as you lock before you change the config and then do you read/writes.
November 10, 2016, 3:30am
thank you all for good tips.
Dave has nice idea to split I2C activity on different threads. I was googling the topic and this popped up:
As far I can see, it is a pretty good article.