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

Error in Adding I2C for nRF9160DK

Hi ,

      I need to add an I2C device in project , I referred sample project i2c_scanner .

changes done in nrf9160dk_nrf9160ns.overlay file 

&i2c3 {
	status = "okay";
	//compatible = "nordic,nrf-twim";
	sda-pin = < 12 >;
	scl-pin = < 11 >;
    clock-frequency = <I2C_BITRATE_STANDARD>;  
};

code added in prj.conf

CONFIG_I2C=y
CONFIG_I2C_NRFX=y

CONFIG_I2C_3=y
CONFIG_I2C_3_NRF_TWIM=y

code in main.c

#include <zephyr.h>
#include <stdio.h>
#include <string.h>
#include <drivers/i2c.h>

#define I2C_SLAVE_ADDR 0x46
#define I2C_DEV "I2C_2"


void I2C_test(void)
{
	struct device *i2c_dev;
	struct i2c_msg msgs[1];
        uint8_t dst = 1,error;

        /* Send the address to read from */
        msgs[0].buf = &dst;
        msgs[0].len = 1U;
        msgs[0].flags = I2C_MSG_WRITE | I2C_MSG_STOP;

	printk("Starting i2c device...\n");

	i2c_dev = device_get_binding(I2C_DEV);
	if (!i2c_dev) {
		printk("I2C: Device driver not found.\n");
		return;
	}

        i2c_configure(i2c_dev, I2C_SPEED_SET(I2C_SPEED_STANDARD));

        error = i2c_transfer(i2c_dev, &msgs[0], 1, I2C_SLAVE_ADDR);
		if (error == 0) {
			printk("transfer complete");
		}
		else {
			printk("error %d \n", error);
		}
}

I am facing 2 issues. 

1. I am not able to import the project in Segger Embedded studio after adding following lines in prj.conf

 

CONFIG_I2C_3=y
CONFIG_I2C_3_NRF_TWIM=y

the error message is : 
error: I2C_3_NRF_TWIM (defined at drivers/i2c/Kconfig.nrfx:39) is assigned in a configuration file,
but is not directly user-configurable (has no prompt). It gets its value indirectly from other
symbols. See docs.zephyrproject.org/.../CONFIG_I2C_3_NRF_TWIM.html
and/or look up I2C_3_NRF_TWIM in the menuconfig/guiconfig interface. The Application Development
Primer, Setting Configuration Values, and Kconfig - Tips and Best Practices sections of the manual
might be helpful too.


2. If I dont add the above lines, I am able to import the project .

but getting compilation error as 

static assertion failed: "Only one of the following peripherals can be enabled: SPI2, SPIM2, SPIS2, TWI2, TWIM2, TWIS2, UARTE2. Check nodes with status \"okay\" in zephyr.dts."

What I am doing wrong? what changes should be made in prj.conf file?

Thank you

 

Parents
  • it check by ~/ncs/zephyr/soc/arm/nordic_nrf/validate_enabled_instances.c

    #define CHECK(idx) \
        !(I2C_ENABLED(idx) && SPI_ENABLED(idx)) && \
        !(I2C_ENABLED(idx) && UART_ENABLED(idx)) && \
        !(SPI_ENABLED(idx) && UART_ENABLED(idx))

    #define MSG(idx) \
        "Only one of the following peripherals can be enabled: " \
        "SPI"#idx", SPIM"#idx", SPIS"#idx", TWI"#idx", TWIM"#idx", TWIS"#idx \
        IF_ENABLED(CONFIG_SOC_SERIES_NRF53X, (", UARTE"#idx)) \
        IF_ENABLED(CONFIG_SOC_SERIES_NRF91X, (", UARTE"#idx)) \
        ". Check nodes with status \"okay\" in zephyr.dts."

    #if !IS_ENABLED(CONFIG_SOC_NRF52810)
    BUILD_ASSERT(CHECK(0), MSG(0));
    #endif
    BUILD_ASSERT(CHECK(1), MSG(1));
    BUILD_ASSERT(CHECK(2), MSG(2));
    BUILD_ASSERT(CHECK(3), MSG(3));


    The _idx can not repeat

    ex1: uart_2 can not with i2c_2
    you need remove uart_2 or use i2c_3

    ex1: i2c_3 can not with spi_3
    you need remove i2c_3

  • Thank you for the clarification.
     I am able to add I2C.

Reply Children
No Data
Related