LIS2DH12 Sample Not Working on nRF54L15-DK — "Device LIS2DH is not ready"

Hi everyone,

I'm trying to get the LIS2DH12 sensor sample working with the nRF54L15-DK, but I'm running into an issue where the device doesn't seem to initialize properly. Here's what I'm seeing in the console:

-----------------------------------------------------------------------------

*** Booting nRF Connect SDK v3.0.1-9eb5615da66b ***
*** Using Zephyr OS v4.0.99-77f865b8f8d0 ***
Device LIS2DH is not ready

-----------------------------------------------------------------------------

What stands out is the Logic Analyzer data:

This is nothing what looks like the WHO_AM_I which is in fact from the datasheet -> (0x0F). But the response is correct (0x33).

Here my .overlay file


&spi21 {
    compatible = "nordic,nrf-spim";
    status = "okay";
    cs-gpios = <&gpio2 7 GPIO_ACTIVE_LOW>;
    pinctrl-0 = <&spi21_default>;
    pinctrl-names = "default";

    lis2dh12: lis2dh12@0 {
        compatible = "st,lis2dh";
        reg = <0>; /* SPI CS address 0 */
        spi-max-frequency = <1000000>;
        label = "LIS2DH";
        status = "okay";
    };
};


&pinctrl {
    spi21_default: spi21_default {
    group1 {
        psels = <NRF_PSEL(SPIM_SCK, 1, 11)>,
        <NRF_PSEL(SPIM_MOSI, 1, 13)>,
        <NRF_PSEL(SPIM_MISO, 1, 14)>;
        };
    };  
   
    spi21_sleep: spi21_sleep {
    group1 {
        psels = <NRF_PSEL(SPIM_SCK, 1, 11)>,
        <NRF_PSEL(SPIM_MOSI, 1, 13)>,
        <NRF_PSEL(SPIM_MISO, 1, 14)>;
        low-power-enable;
        };
    };
   };
   
   




Included is my main.c file.

Now I hope on some tips that could help me further. Slight smile
I wish you a good day!
Dennis

/*
 * Copyright (c) 2019 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <stdio.h>
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/sensor.h>

static void fetch_and_display(const struct device *sensor)
{
	static unsigned int count;
	struct sensor_value accel[3];
	struct sensor_value temperature;
	const char *overrun = "";
	int rc = sensor_sample_fetch(sensor);

	++count;
	if (rc == -EBADMSG) {
		/* Sample overrun.  Ignore in polled mode. */
		if (IS_ENABLED(CONFIG_LIS2DH_TRIGGER)) {
			overrun = "[OVERRUN] ";
		}
		rc = 0;
	}
	if (rc == 0) {
		rc = sensor_channel_get(sensor,
					SENSOR_CHAN_ACCEL_XYZ,
					accel);
	}
	if (rc < 0) {
		printf("ERROR: Update failed: %d\n", rc);
	} else {
		printf("#%u @ %u ms: %sx %f , y %f , z %f",
		       count, k_uptime_get_32(), overrun,
		       sensor_value_to_double(&accel[0]),
		       sensor_value_to_double(&accel[1]),
		       sensor_value_to_double(&accel[2]));
	}

	if (IS_ENABLED(CONFIG_LIS2DH_MEASURE_TEMPERATURE)) {
		if (rc == 0) {
			rc = sensor_channel_get(sensor, SENSOR_CHAN_DIE_TEMP, &temperature);
			if (rc < 0) {
				printf("\nERROR: Unable to read temperature:%d\n", rc);
			} else {
				printf(", t %f\n", sensor_value_to_double(&temperature));
			}
		}

	} else {
		printf("\n");
	}
}

#ifdef CONFIG_LIS2DH_TRIGGER
static void trigger_handler(const struct device *dev,
			    const struct sensor_trigger *trig)
{
	fetch_and_display(dev);
}
#endif

int main(void)
{
	const struct device *const sensor = DEVICE_DT_GET_ANY(st_lis2dh);

	if (sensor == NULL) {
		printf("No device found\n");
		return 0;
	}

	if (!device_is_ready(sensor)) {
		printf("Device %s is not ready\n", sensor->name);

		//return 0;
	}

#if CONFIG_LIS2DH_TRIGGER
	{
		struct sensor_trigger trig;
		int rc;

		trig.type = SENSOR_TRIG_DATA_READY;
		trig.chan = SENSOR_CHAN_ACCEL_XYZ;

		if (IS_ENABLED(CONFIG_LIS2DH_ODR_RUNTIME)) {
			struct sensor_value odr = {
				.val1 = 1,
			};

			rc = sensor_attr_set(sensor, trig.chan,
					     SENSOR_ATTR_SAMPLING_FREQUENCY,
					     &odr);
			if (rc != 0) {
				printf("Failed to set odr: %d\n", rc);
				return 0;
			}
			printf("Sampling at %u Hz\n", odr.val1);
		}

		rc = sensor_trigger_set(sensor, &trig, trigger_handler);
		if (rc != 0) {
			printf("Failed to set trigger: %d\n", rc);
			return 0;
		}

		printf("Waiting for triggers\n");
		while (true) {
			k_sleep(K_MSEC(2000));
		}
	}
#else /* CONFIG_LIS2DH_TRIGGER */
	printf("Polling at 0.5 Hz\n");
	while (true) {
		fetch_and_display(sensor);
		k_sleep(K_MSEC(200));
	}
#endif /* CONFIG_LIS2DH_TRIGGER */
}

Related