Hi,
I have question about a project I'm running on nRF connect sdk 2.9.1.
I noticed that whenever an i2c sensor device device_init() is returning a value not equal to 0, the i2c driver (probably) keeps the hfclk active.
For example, if the sensor is not connected, and you try to initialize it, the mcu will not get into a low-power mode.
See the sample code below. After the first call to TEMP_Get(), the mcu will keep its hfclk running
Example code:
static const struct device *dev; void TEMP_Get( struct sensor_value *temp_value ) { int err; dev = DEVICE_DT_GET_ONE(sensirion_shtcx); if (!dev) { printk("Failed to find external temperature sensor\n"); } else { err = device_init(dev); if (err) { printk("Failed to init external temp sensor (%d)\n",err); } else { struct sensor_value temp, hum; int rc = sensor_sample_fetch(dev); if (rc == 0) { rc = sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp); } if (rc == 0) { rc = sensor_channel_get(dev, SENSOR_CHAN_HUMIDITY, &hum); } } } } int main(void) { printk("Hello, World! %d\n", k_cycle_get_32()); for (;;) { k_sleep(K_MSEC(1000)); printk("Temperature value %d\n", TEMP_Get(0)); k_sleep(K_MSEC(1000)); } }
I'm trying on an nRF54L15 DK board.
Configuration is the bare minimum to get the code running.
The .dtsi looks like this.
&i2c21 { compatible = "nordic,nrf-twim"; status = "okay"; pinctrl-0 = <&i2c21_default>; pinctrl-1 = <&i2c21_sleep>; pinctrl-names = "default", "sleep"; zephyr,deferred-init; shtcx1:shtcx@70 { compatible = "sensirion,shtcx"; reg = <0x70>; supply-gpios = <&gpio1 11 GPIO_ACTIVE_HIGH>; measure-mode = "normal"; zephyr,deferred-init; }; };
I use a Sensirion sensor, but it will probably go wrong with any i2c sensor.
What am I doing wrong here.
Thanks,
Renger