Reconfigure TWIM so pins can be driven pnis low when not in use

I have a battery application where I power off areas of the circuit. One of which has my I2C/TWIM peripherals. However, the TWIM controller configured on the nRF52832 is pulling the lines high. I want to be able to keep the bluetooth runing, but power off all my external circuits. How can I reconfigure the TWIM pins, so I can diable the TWIM & drive the pins low, then when required enable the TWIM

    /* ======================================
     *	DAC_SCL DAC_SCA
     */
     i2c0_default: i2c0_default {
        group1 {
            psels = <NRF_PSEL(TWIM_SDA, 0, 26)>,
                <NRF_PSEL(TWIM_SCL, 0, 27)>;
                bias-pull-up;
        };
    };

    i2c0_sleep: i2c0_sleep {
        group1 {
            psels = <NRF_PSEL(TWIM_SDA, 0, 26)>,
                <NRF_PSEL(TWIM_SCL, 0, 27)>;
            low-power-enable;
        };
    };

  • Hello,

    so I can diable the TWIM & drive the pins low, then when required enable the TWIM

    Do you want to drive these low externally, or from the nRF? 

    I assume you don't want to backpower something connected to the I2C pins when you don't actively use the I2C?

    If that is the case, you are halfway there. You have defined your sleep state for the I2C pins. You just need to put it in sleep mode, which will disable the pullup, and put them in disconnected input mode. 

    To do this, you can use the device manager:

    // Put the I2C to sleep:
    int rc = pm_device_action_run(i2c_dev, PM_DEVICE_ACTION_SUSPEND);
    if (rc < 0) {
        printf("Could not suspend I2C (%d)\n", rc);
    }
    
    // Enable the I2C again:
    int rc = pm_device_action_run(i2c_dev, PM_DEVICE_ACTION_RESUME);
    if (rc < 0) {
        printf("Could not resume I2C (%d)\n", rc);
    }

    Remember to enable the power management in your prj.conf:

    CONFIG_PM_DEVICE=y

    Best regards,

    Edvin

Related