{"record":{"id":"1e9deb4be3a1872b","repo":"embassy-rs/embassy","slug":"error-configuring-i2c","errorCode":null,"errorMessage":"Error configuring i2c: {:?}","messagePattern":"Error configuring i2c: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-rp/src/i2c.rs","lineNumber":524,"sourceCode":"impl<'d, M: Mode> I2c<'d, M> {\n    fn new_inner(info: &'static Info, scl: Peri<'d, AnyPin>, sda: Peri<'d, AnyPin>, config: Config) -> Self {\n        let reset = (info.reset)();\n        crate::reset::reset(reset);\n        crate::reset::unreset_wait(reset);\n\n        // Configure SCL & SDA pins\n        set_up_i2c_pin(&scl, config.scl_pullup);\n        set_up_i2c_pin(&sda, config.sda_pullup);\n\n        let mut me = Self {\n            info,\n            phantom: PhantomData,\n            scl,\n            sda,\n        };\n\n        if let Err(e) = me.set_config_inner(&config) {\n            panic!(\"Error configuring i2c: {:?}\", e);\n        }\n\n        me\n    }\n\n    fn set_config_inner(&mut self, config: &Config) -> Result<(), ConfigError> {\n        if config.frequency.0 > 1_000_000 {\n            return Err(ConfigError::FrequencyTooHigh);\n        }\n\n        let p = self.info.regs;\n\n        p.ic_enable().write(|w| w.set_enable(false));\n\n        // Configure baudrate\n\n        // There are some subtleties to I2C timing which we are completely\n        // ignoring here See:","sourceCodeStart":506,"sourceCodeEnd":542,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-rp/src/i2c.rs#L506-L542","documentation":"`I2C::new_inner` in embassy-rp calls `set_config_inner(&config)` and panics if configuration validation fails. `ConfigError` variants cover invalid clock/pin/parameter combinations for the RP2040/RP235x I2C block, so this panic means the supplied `Config` (or derived pin/addresses) cannot be programmed into the hardware.","triggerScenarios":"Calling `I2c::new(...)` or `new_inner` with a `Config` whose values fail `set_config_inner` — e.g. baudrate/baudrate_enum not valid for the current clk_sys, or conflicting configuration for the selected pins.","commonSituations":"Setting an I2C frequency the hardware divider cannot achieve; running code written for one clock configuration on a board with a different clk_sys frequency; copying a Config from another project without adjusting the baudrate.","solutions":["Print/use the `{:?}` ConfigError in the panic to identify which field is invalid","Choose a supported I2C frequency (e.g. 100 kHz or 400 kHz) matching your clk_sys frequency","Use `Config::default(watchdog)` style derived configs so the baudrate is computed from actual clocks","Switch to the `try_new` / fallible API and handle the error instead of panicking"],"exampleFix":"// before\nlet mut i2c = I2c::new(p.I2C0, scl, sda, Config { frequency: 3_500_000, .. });\n// after\nlet mut i2c = I2c::new(p.I2C0, scl, sda, Config { frequency: 400_000, .. });","handlingStrategy":"validation","validationCode":"// Check frequency is achievable before building I2C\nlet valid = [100_000u32, 400_000u32, 1_000_000u32].contains(&cfg.frequency);\nassert!(valid, \"unsupported i2c frequency {}\", cfg.frequency);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use Config::default derived from the watchdog/clocks so baudrate matches clk_sys","Keep I2C frequencies at standard 100k/400k values","Migrate to try_new-style fallible constructors where available"],"tags":["i2c","embedded","config","rust"],"backgroundTag":"invalid-config-value","analyzedSha":"463a07b963419a1bfe61d5d597c44acb810afb8b","analyzedAt":"2026-09-10T13:38:26.660Z","contentChangedAt":"2026-09-10T13:38:26.660Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}