Using an Output in I2c::new
Posted: Sun Dec 21, 2025 7:07 pm
I'm writing a no_std esp-hal (v1.0.0) Rust application for the ESP32. Here is some existing code that initializes the I2C controller to talk to another device. This is working just fine and I can talk to my existing I2C device just fine.
What I'm trying to do is to add a second I2C device to the bus. This chip (Si7403 radio) needs a few pins to be raised/lowered to initialize it and configure its mode of operation. So, I'm trying to use esp-hal::gpio to bit-bang the pins in order to init this chip before continuing to initialize the I2C controller. So I switch from giving peripherals.GPIO19 to I2c, to instead creating an Output instance. Here is the new code that doesn't work.
When I do this, my existing device fails to respond. I've also tried OpenDrain on the Output, but that has no effect. Anybody know what I'm doing wrong here?
Code: Select all
info!("[main] Initializing I2C");
let i2c = I2c::new(
peripherals.I2C0,
esp_hal::i2c::master::Config::default().with_frequency(Rate::from_khz(100)),
)
.unwrap()
.with_scl(peripherals.GPIO20)
.with_sda(peripherals.GPIO19)
.into_async();Code: Select all
let mut sda_pin = Output::new(
peripherals.GPIO19,
Level::High,
OutputConfig::default().with_drive_mode(DriveMode::OpenDrain),
);
// GPIO initialization will go here:
info!("[main] Initializing I2C");
let i2c = I2c::new(
peripherals.I2C0,
esp_hal::i2c::master::Config::default().with_frequency(Rate::from_khz(100)),
)
.unwrap()
.with_scl(peripherals.GPIO20)
.with_sda(sda_pin)
.into_async();