Hi,
I'm having trouble converting a very simple bit of code from using the Wire.h library to using I2C.h instead.
Here's the background, I'm working with the BMP180 pressure sensor SparkFun Barometric Pressure Sensor Breakout - BMP180 - SEN-11824 - SparkFun Electronics. I've already successfully written a library to work with the module, the library uses I2C.h instead of Wire.h. So far so good.
The I2C address on this device is hardcoded and unchangable, so I've started using an I2C multiplexer to attempt to run three of the modules at the same time. Here's the multiplexer DssCircuits.com is for sale | HugeDomains.
In the example sketch (provided on the above link) it uses this function to select one of the four channels before accessing the selected pressure module....
#define MUX 0x70 //Multiplexer Address
/********************************************************
* When selecting a channel bit2 of the control register
* must be set to a logic 1 to enable channel selection.
* If bit2 is a logic zero then all channels will be disabled.
* If 0xFF is the selected channel it will disable all channels.
********************************************************/
void mux(byte channel)
{
byte controlRegister = 0x04;
controlRegister |= channel;
Wire.beginTransmission(MUX);
if (channel == 0xFF){Wire.send(0x00);} //deselect all channels
else {Wire.send(controlRegister);} //set to selected channel
Wire.endTransmission();
}
My version looks (using I2C instead of wire) looks like this....
void BarographTrio::mux(byte channel)
{
byte controlRegister = 0x04;
controlRegister |= channel;
if (channel == 0xFF)
{
// disable all channels
_i2c.write(MUX,(unsigned int)0x00);
}
else
{
// enable the selected channel
_i2c.write(MUX,(unsigned int)controlRegister);
}
}
It compiles ok, executes ok, but doesn't actually seem to select any of the pressure sensors.
help please!