Hello,
I'm trying to connect a sensor to the nRF9160 board using the example Asset Tracker v2.
My sensor (SHT30) is connect in I2C to the pins 31 (SCL) and 30 (SDA).
In the nrf9160dk_nrf9160_ns.overlay I added :
&i2c2 {
compatible = "nordic,nrf-twim";
status = "okay";
sda-pin = < 30 >;
scl-pin = < 31 >;
clock-frequency = <I2C_BITRATE_FAST>;
label = "I2C_2" ;
sht30: sht30@44 {
label = "SHT30";
reg = <0x44>;
};
};
In the file prj.conf, I added :
CONFIG_SENSOR=y CONFIG_I2C=y
I also added a file which define the driver :
int sht30_init(const struct device *dev)
{
struct sht30_data *data = dev->data;
data->i2c_master = device_get_binding("SHT30");
if (!data->i2c_master) {
LOG_ERR("I2C master not found");
return -EINVAL;
}
return 0;
}
static struct sht30_data sht30_data;
DEVICE_DEFINE(sht30, "SHT30", sht30_init, NULL, &sht30_data,
NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
NULL);The code build correctly but device_get_binding("SHT30") returns an error. The device is not initialized correctly.
Also, when I look at the signals with Sigrok of pins 30 and 31 on the board, there is nothing. But I will be able to see the clock on the pin 31 even if my sensor is not initialized correctly, no?
In the deviceTree, the bus i2c2 is well configured in the mcuboot with my sht30 node but not in the spm build (it's still the standard configuration of i2c2). I guess the error come from here. Do I need to had a configuration in the prj.conf of the child_image?
Thanks in advance for your help !
Elisa