Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

NRF_TWI_MNGR use in zephyr

Hello,

I am using nrf52840 MCU.

I am developing a product which have 2 I2C and 2 SPI interfaces. All the interfaces are on different pins.

I developed this thing with the bare-metal FW. In the baremetal SPI using instances 1 and 2. And I2C 0 instance used for both I2C, for that I2C uses the NRF_TWI_MNGR to handle 2 different interfaces on the same I2C instance 0.

I want to port this application to the Zephyr platform. How can I use NRF_TWI_MNGR  in Zephyr? I know that I have instance 3 is still empty, but I want to make it reserved for future scope.

Thanks,
Dinkar

Parents
  • Hello Dinkar,

    You cannot use NRF_TWI_MNGR as-is in Zephyr. The recommended Zephyr approach is to use the Zephyr I2C API and device tree to manage multiple devices on a single I2C bus. For example, if you want to add few multiple I2C devices on a single I2C bus using a device tree overlay,

    &i2c0 {
        compatible = "nordic,nrf-twim";
        status = "okay";
        sda-pin = <30>;
        scl-pin = <31>;
        clock-frequency = <I2C_BITRATE_FAST>;
    
        sensor1@abc {
            compatible = "avago,apds9960";
            label = "APDS9960";
            reg = <0x39>;
        };
        sensor2@def {
            compatible = "ti,hdc", "ti,hdc1010";
            label = "HDC1010";
            reg = <0x43>;
        };
        sensor3@ghi {
            compatible = "nxp,fxos8700", "nxp,mma8652fc";
            label = "MMA8652FC";
            reg = <0x1d>;
        };
    };

    If you want to use nRFX drivers directly and not the Zephyr I2C driver for a particular instance, you can set status = "disabled"; for that I2C instance in the overlay, and then enable and configure the nRFX driver in your project configuration.

    This blog can help to know the set up nrfx driver for TWI(+) TWI/I2C implementation with nRFx TWIS Driver - Peripherals And RF Test - nRF Connect SDK guides - Nordic DevZone

Reply
  • Hello Dinkar,

    You cannot use NRF_TWI_MNGR as-is in Zephyr. The recommended Zephyr approach is to use the Zephyr I2C API and device tree to manage multiple devices on a single I2C bus. For example, if you want to add few multiple I2C devices on a single I2C bus using a device tree overlay,

    &i2c0 {
        compatible = "nordic,nrf-twim";
        status = "okay";
        sda-pin = <30>;
        scl-pin = <31>;
        clock-frequency = <I2C_BITRATE_FAST>;
    
        sensor1@abc {
            compatible = "avago,apds9960";
            label = "APDS9960";
            reg = <0x39>;
        };
        sensor2@def {
            compatible = "ti,hdc", "ti,hdc1010";
            label = "HDC1010";
            reg = <0x43>;
        };
        sensor3@ghi {
            compatible = "nxp,fxos8700", "nxp,mma8652fc";
            label = "MMA8652FC";
            reg = <0x1d>;
        };
    };

    If you want to use nRFX drivers directly and not the Zephyr I2C driver for a particular instance, you can set status = "disabled"; for that I2C instance in the overlay, and then enable and configure the nRFX driver in your project configuration.

    This blog can help to know the set up nrfx driver for TWI(+) TWI/I2C implementation with nRFx TWIS Driver - Peripherals And RF Test - nRF Connect SDK guides - Nordic DevZone

Children
No Data
Related