Can't use second I2C bus on seed

I’m having trouble using peripherals on the seed’s I2C_2 bus. The I2C_1 bus is working just fine, and I’ve verified that the peripheral itself (VL53L0X distance sensor) and its hookups aren’t the problem. Here’s the code where I initialize the I2C config - I’ll pass either 1 or 2 into this function to choose the bus. When I use bus 2, I’m unable to communicate with the sensor.
Am I missing anything? Do I need to explicitly enable the second I2C bus? Are there any address-related differences? Would love to hear if anyone’s been successfully using both I2C busses.

I2CHandle::Config i2c_conf;

if (i2cBus == 2) {
    hw.PrintLine("Using I2C bus 2");
    i2c_conf.periph = I2CHandle::Config::Peripheral::I2C_2;
    i2c_conf.pin_config.scl  = {DSY_GPIOB, 6};
    i2c_conf.pin_config.sda  = {DSY_GPIOB, 7};
}
else {
    hw.PrintLine("Using I2C bus 1");
    i2c_conf.periph = I2CHandle::Config::Peripheral::I2C_1;
    i2c_conf.pin_config.scl  = {DSY_GPIOB, 8};
    i2c_conf.pin_config.sda  = {DSY_GPIOB, 9};
}

i2c_conf.speed  = I2CHandle::Config::Speed::I2C_100KHZ;
i2c_conf.mode   = I2CHandle::Config::Mode::I2C_MASTER;


res = i2c.Init(i2c_conf);
if (res == I2CHandle::Result::ERR) {
    hw.PrintLine("I2C init error");
}

Thank you!

Hi! The reason you can’t initialize I2C_2 is because that one’s already pre-allocated to the CODEC. Even though the MCU has 4 I2C peripherals, only two are exposed. Check this post for more info:

Hope this helps!

1 Like

The Rev 7 Seed doesn’t use I2C for the codec, is I2C_2 available on Rev 7?

Hey, thanks for the reply - I did read through that post, wasn’t entirely clear on the solution. Are you saying I’d just need to change I2C_2 to I2C_4 in my above code for it to work? I could swear I tried that with no luck, but I can try again.

As far as I understand, yes. I2C_1 and I2C_4 are the two peripherals that are exposed on Daisy Seed. They also are both available on pins D11/D12 and D13/D14 if I understand correctly; i.e., you can initialize either peripheral on either sets of SCL/SDA pins. That said, I’m having some trouble myself getting IC_4 working, as explained in this post:

So, try it and see if you have better luck than I’m having. :slight_smile:

Ok yeah, that matches my experience. I was initially trying I2C_4, but switched to trying 2 after I did some digging in the seed source files and found some clues that it might use 2 under the hood. Either way, tried lots of stuff and couldn’t get either one working.

Hi @comatose_llama! I’m really sorry for the delay in response.
We’ll have a closer look at this soon. It’s possible that I2C_4 doesn’t have DMA capabilities.

We’ll provide more details over here (Can't use I2C_4 on Seed) so that we can keep this topic in one location. Thanks!

No worries, thanks! I’ll keep an eye on that thread.

1 Like