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

nRF52840-DK I2C - Unable to get device binding - I2C_1 - cpuapp - Segger Embedded Studio

Hi, (Help please)

I'm being struggling to get I2C working on nRF52840-DK, I enabled IC2 and  I2C_1 on prj.conf

main.c

#include <zephyr.h>
#include <device.h>
#include <drivers/gpio.h>
#include <sys/util.h>
#include <sys/printk.h>
#include <inttypes.h>
#include <drivers/i2c.h>

void main(void)
{
    printk("Hello World!\n");
    const struct device *i2c_dev;
    uint8_t cmp_data[16];
    uint8_t data[16];
    int i, ret;

    i2c_dev = device_get_binding("I2C_1");
    if (i2c_dev == NULL)
    {
        printk("Error: didn't find device\n");/*Failing Here*/
        return;
    }
	data[0] =0x29;
	ret = i2c_write(i2c_dev, 0x13, &data[0], 1);
	if (ret) {
		printk("Error writing to FRAM! error code (%d)\n", ret);
		return;
	} else {
		printk("Wrote 0xAE to address 0x00.\n");
	}
}

prj.conf

# GPIO
CONFIG_GPIO=y
# I2C
CONFIG_I2C=y
CONFIG_I2C_1=y
CONFIG_I2C_NRFX=y


Any help is appreciated

  • Hello,

    The naming of the I2C devices start with 0. I would suggest to change the name of the i2c device to "I2C_0" and give it a try.


    Also keep in mind that the "CONFIG_I2C_1" option is not supported by nrf devices. You can check it's dependencies in it's zephyr page.

    As a general rule regarding naming of devices I would suggest to always check the file "zephyr/zephyr.dts" in your build folder. The labels there will show the names of the devices and their status.

    Hope that helps

  • Thanks a lot :D


    /build_nrf5340dk_nrf5340_cpuapp/zephyr.dts


    i2c1: i2c@9000 {
    #address-cells = < 0x1 >;
    #size-cells = < 0x0 >;
    reg = < 0x9000 0x1000 >;
    clock-frequency = < 0x186a0 >;
    interrupts = < 0x9 0x1 >;
    status = "okay";
    label = "I2C_1";
    compatible = "nordic,nrf-twim";
    sda-pin = < 0x22 >;
    scl-pin = < 0x23 >;
    };

Related