Dear All,
I am trying to interface my nRF9160 sensor with the LIS3DH accelerometer.
What I have done so far are the following:
I am trying to use I2C_2
In my prj.conf I have the following:
... # I2C CONFIG_I2C=y
I have created a nrf9160_pca10090ns.overlay file and I have added the following contents:
...
&i2c2 {
status = "ok";
sda-pin = <16>;
scl-pin = <17>;
};
I have also created a file overlay-nrf52.conf:
CONFIG_I2C_NRFX=y CONFIG_I2C_2=y
So this is all the configuration I have made so far.
In my main code I am doing the following:
#define I2C_DEV_NAME "I2C_2"
...
static struct device *i2c_dev;
...
void getID()
{
i2c_configure(i2c_dev, I2C_SPEED_SET(I2C_SPEED_STANDARD));
printk("-------------------------Get WhoAmI register-----------------------\n");
char whoamI = 0;
i2c_reg_read_byte(i2c_dev, 0x19, 0x0F, &whoamI);
printk("value of WhoAmI: %x\n", whoamI);
}
...
void main(void)
{
...
i2c_dev = device_get_binding(I2C_DEV_NAME);
if (!i2c_dev) {
printk("I2C: Device driver not found.\n");
return;
}
getID();
...
}
The operation will fail, since I will get a 0 as value and the following message:
i2c_nrfx_twim: Error 195952641 occurred for message 0
I read here that the .overlay file fixes the problem, but it didn't solve it for me.
Another issue is that if I try to use another i2c device, let's say i2c_0 doing the same configuration will lead to the device not being initialized exiting from the code.
Any ideas about how to tackle these issues?