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

  • Hello,

    Thanks for the quick revert.

    As I mentioned earlier, I need to port my existing application into the Zephyr base, i.e., the hardware is the same, which will not allow me to create a single instance of I2C0 for two different peripherals. Peripheral 1 is connected to P0.2, P0.3, and Peripheral 2 is connected to P0.4, P0.5 with SDA and SCL, respectively.

    I have two other peripherals that are already using two SPI instances, and I can not use SPI3 due to the known issue of Errata 198. So I only have one option to use I2C0 for two peripherals connected on different SDA and SCL lines. I did this in legacy NRF SDK using nrfx_twim_manager, so it should be possible in Zephyr somehow.

    Can you please suggest a way out of this situation?

    Thanks,
    Dinkar

Reply
  • Hello,

    Thanks for the quick revert.

    As I mentioned earlier, I need to port my existing application into the Zephyr base, i.e., the hardware is the same, which will not allow me to create a single instance of I2C0 for two different peripherals. Peripheral 1 is connected to P0.2, P0.3, and Peripheral 2 is connected to P0.4, P0.5 with SDA and SCL, respectively.

    I have two other peripherals that are already using two SPI instances, and I can not use SPI3 due to the known issue of Errata 198. So I only have one option to use I2C0 for two peripherals connected on different SDA and SCL lines. I did this in legacy NRF SDK using nrfx_twim_manager, so it should be possible in Zephyr somehow.

    Can you please suggest a way out of this situation?

    Thanks,
    Dinkar

Children
No Data
Related