Other Parts Discussed in Thread: CC1350STK
Tool/software: Code Composer Studio
Hi all,
I've a CC1310 module and 2 identical sensors hooked up to it using I2C, with the same I2C address.
I need to be able to (sequentially, not at the same time) read a value from each of them.
The CC1310 only has 1 I2C bus, and I am using existing hardware, so a physical I2C multiplexer IC would be undesirable. This is why I am attempting to multiplex the bus in firmware.
There are 2 things I tried:
1. Sharing I2C line, switching power from sensors. When trying this the CC1310 hangs when attempting to access bus (I2C driver crashes I guess) and continues (no reset) when I disconnect one of the senors, probably the sensors aren't properly high-Z when off. Haven't explored this angle any further.
2. 2 sets of I2C lines, and switching configuration code, like below. But this only works for the first initialization.
The switching is implemented as follows in the board config H file:
typedef enum CC1310_LAUNCHXL_I2CName {
CC1310_LAUNCHXL_I2C1 = 0,
CC1310_LAUNCHXL_I2C2,
CC1310_LAUNCHXL_I2CCOUNT
} CC1310_LAUNCHXL_I2CName;
And then in the C:
const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC1310_LAUNCHXL_I2CCOUNT] = {
{ // This struct already was there
.baseAddr = I2C0_BASE,
.powerMngrId = PowerCC26XX_PERIPH_I2C0,
.intNum = INT_I2C_IRQ,
.intPriority = ~0,
.swiPriority = 0,
.sdaPin = Board_I2C0_SDA1,
.sclPin = Board_I2C0_SCL1,
},
{ // I added this one
.baseAddr = I2C0_BASE,
.powerMngrId = PowerCC26XX_PERIPH_I2C0,
.intNum = INT_I2C_IRQ,
.intPriority = ~0,
.swiPriority = 0,
.sdaPin = Board_I2C0_SDA2,
.sclPin = Board_I2C0_SCL2,
}
};
So basically, I just added a 2nd I2C instance with same I2C base, and different pins.
Then, in my application code, I call I2C_open with either of the I2C names to open one of them, then close it using I2C_close when I'm done again, like this:
I2C_Params_init(&i2cParams); i2cParams.transferMode = I2C_MODE_BLOCKING; // Note that my I2C is in blocking mode i2cParams.bitRate = I2C_100kHz; i2cHandle = I2C_open(/*I2C name thingy here */, &i2cParams); if (i2cHandle == NULL) return false; // Do I2C stuff here I2C_close(i2cHandle);
Whereas this works fine for the first I2C name, when I run the exact same code after this for the 2nd sensor, it won't interact with I2C (I don't see any signal on Logic Analyzer).
Note that the sensors are working fine, if I switch the 2 sensors, it reads the other one just fine. Also, if I put the sensor read code in reverse order, they read fine, so HW is fine.
I am suspecting that I2C_close does not fully "undo" I2C_open, can this be the case? Is there some way to "reset" the whole I2C bus?
Maybe this is possible by interacting with power management?
Regards,
Robert