This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

I2C example code for nrf5340

Hi ,

my environment details:

  • nrf connect sdk
  • nrf5340 dk
  • segger embedded studio

I have seen I2C example code in below path

\v1.5.0\zephyr\samples\drivers\i2c_fujitsu_fram

please let me know where can I update I2C pin numbers (SDA and SCL) and share with me if you have any more example codes on I2C.

Thanks & Regards,

Srinivas Rao.

  • Hi ,

    I have tested sensor module with nrf52832 using TWIM peripheral . it is working.

    I have tested sensor module with nrf5340 using TWIM peripheral . it is not working

     please check below snippet code.

    uint8_t address = 0x6A;

    uint8_t reg = 0x0f;

    uint8_t reg_data = 0;

    nrfx_twim_t twim_instance = NRFX_TWIM_INSTANCE(2);

    nrfx_twim_config_t twim_config;
    twim_config.scl = 10;
    twim_config.sda = 9;
    twim_config.frequency = NRF_TWIM_FREQ_100K;
    twim_config.interrupt_priority = NRFX_TWIM_DEFAULT_CONFIG_IRQ_PRIORITY;
    twim_config.hold_bus_uninit = false;

    nrfx_twim_init(&twim_instance, &twim_config, &EventHandler, NULL);

     nrfx_twim_enable(&twim_instance);

    nrfx_twim_xfer_desc_t const rx_xfer = NRFX_TWIM_XFER_DESC_TXRX(address, &reg, 1, &reg_data, 1);

    nrfx_twim_xfer(&twim_instance, &rx_xfer, NRFX_TWIM_FLAG_REPEATED_XFER);

    expected output : 0x6C 

    Actual output : 0x00

    Note: sensor module working tested with nrf52832 without any issues.

    please let me know the reason or if you have any tested code with TWIM peripheral . please share to me.

    prj.conf file updated with below lines:

    CONFIG_I2C=y
    CONFIG_I2C_1=y
    CONFIG_NRFX_TWIM1=y
    CONFIG_NRFX_TWIM2=y
    CONFIG_NRFX_TWIM3=y
    CONFIG_I2C_NRFX=y

    Thanks & Regards,

    Srinivas.

  • Hello,

    have you configured the I2C peripheral accordingly for your nRF5340 target? Is the devicetree binding correct?

    Regarding your prj.conf, it should be enough to have the following two I2C commands in v1.5.0

    CONFIG_I2C=y
    CONFIG_NRFX_TWIM=y

    Regards,

    Markus

Related