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