PCA9540 i2c MUX

Has anyone used the PCA9540 mux? I'm having problems with it and can't figure out what's going on. I have several sensors on my AB_i2c bus, which all work great. I need to add a sensor which has the same address as one I'm already using so went to the mux solution. The documentation seems a little different than other i2c devices in that it does not use an address for the control register. All well and good. I used "" for the i2c.read(ADDR_MUX,"",1) and I just blast out the control byte (in this case MUX_VL_CH0 = "\x04") for the i2c.write(ADDR_MUX,MUX_VL_CH0). That works for a while and I can read the sensor on channel 0. But when I send i2c.write(ADDR_MUX,MUX_UV_CH1) it doesn't change channel to "\x05" as it should. Any time I try to read the control register, it reports CH0 (04), even if I read it before I have sent it any channel commands and it should be reading 0. Worse, after some time running like this, the mux takes down the entire i2c bus. I know it's the PCA9540 causing the i2c bus problem because when I pull it, everyone is happy (except me because I can't read my sensor with the duplicate address)

All my sensors are working correctly (checked independently).

Yes I know I can use the second i2c channel, and I have just to verify that the second sensor is working correctly. I may have to resort to that for the final project. But that adds extra wires and connections which I'm trying to avoid.

So any advice from those who have used this chip, or suggestions from those who have had similar issues with other muxes would be appreciated.

Comments

  • Is the write definitely working? Just wondering if you need to disable in the middle, eg write \x00 (to go to "no channel selected") then write \x05 to select channel 1.

    Any error returned by the i2c.write command?
  • According to the docs the 'no channel selected' is the POR default and there is no requirement to first set condition \x00 before issuing the desired channel selection. The docs say to just write the channel byte to the register and you're done. The only thing it emphasizes in the docs is that the channel selection is not implemented until a STOP condition is issued by the i2c master. I'm assuming that the IMP i2c implementation does that after the selection byte is sent (but have no way to confirm).
  • Every i2c transaction ends with a stop, so yes the imp is sending one.

    If you read the multiplexer after powerup, it should return the low 3 bits as zero according to the datasheet. Does it?

    If so, and the first write you do is to select channel 1 (\x05) does that work?
Sign In or Register to comment.