Skip to content

How to use i2c_external with microbit-v2? #121

@felipebalbi

Description

@felipebalbi

Hi,

I'm attempting to read from shtc3 sensor connected to microbit-v2 via i2c external pins. For testing, I'm using a minimal RTIC app with one task which received a local context containing the Twim:<TWIM0> instance which it uses to instantiate shtc3. When attempting to build the application, it results in unsatisfied trait bounds:

error[E0599]: the method `device_identifier` exists for struct `ShtCx<Sht2Gen, &mut Twim<TWIM0>>`, but its trait bounds were not satisfied
   --> app\src\main.rs:157:29
    |
157 |         let device_id = sht.device_identifier().unwrap();
    |                             ^^^^^^^^^^^^^^^^^ method cannot be called on `ShtCx<Sht2Gen, &mut Twim<TWIM0>>` due to unsatisfied trait bounds
    |
    = note: the following trait bounds were not satisfied:
            `<&mut microbit::nrf52833_hal::Twim<microbit::nrf52833_pac::TWIM0> as _embedded_hal_blocking_i2c_Read>::Error = _`
            `<&mut microbit::nrf52833_hal::Twim<microbit::nrf52833_pac::TWIM0> as _embedded_hal_blocking_i2c_Write>::Error = _`
            `&mut microbit::nrf52833_hal::Twim<microbit::nrf52833_pac::TWIM0>: _embedded_hal_blocking_i2c_Read`
            `&mut microbit::nrf52833_hal::Twim<microbit::nrf52833_pac::TWIM0>: _embedded_hal_blocking_i2c_Write`

If I move the code to init(), then it compiles fine, but there is no activity on the i2c external pins (checked with an oscilloscope) and every transaction results in a Nack.

Is there anything else I need to do to get i2c_external to work? Here's a minimal version of my code:

#[app(device = microbit::hal::pac)]
mod app {
    use super::*;

    #[shared]
    struct Shared {}

    #[local]
    struct Local {
        led: P0_21<Output<PushPull>>,
        // i2c: Twim<TWIM0>,
        gpiote: Gpiote,
        state: bool,
    }

    #[init]
    fn init(cx: init::Context) -> (Shared, Local) {
        info!("Hello from RTIC on micro:bit v2");

        let mut board = Board::new(cx.device, cx.core);
        let i2c = Twim::new(board.TWIM0, board.i2c_external.into(), FREQUENCY_A::K100);
        let mut sht = shtcx::shtc3(i2c);
        let device_id = sht.device_identifier().unwrap(); // Fails here with Nack

        (
            Shared {},
            Local {},
        )
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions