I am using ncs version 2.5.0.rc-1, I want to initialize the icm-42670 using nrf52832 zephyr ready made driver for invensense. But i continuously seeing sensor: Device not ready. Do i have to add any other initializations in the main?
Overlay File:
&pinctrl {
spi0_default_alt: spi0_default_alt {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 27)>,
<NRF_PSEL(SPIM_MOSI, 0, 26)>,
<NRF_PSEL(SPIM_MISO, 0, 23)>;
};
};
spi0_sleep_alt: spi0_sleep_alt {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 0, 27)>,
<NRF_PSEL(SPIM_MOSI, 0, 26)>,
<NRF_PSEL(SPIM_MISO, 0, 22)>;
low-power-enable;
};
};
};
&spi0 {
compatible = "nordic,nrf-spi";
status = "okay";
pinctrl-names = "default", "sleep";
icm42670@75 {
compatible = "invensense,icm42670";
accel-hz = <800>;
gyro-hz = <800>;
accel-fs = <16>;
gyro-fs = <2000>;
reg = <0x75>;
spi-max-frequency = <0>;
};
};
Main.c File
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/sensor.h>
#include <stdio.h>
static const char *now_str(void)
{
static char buf[16]; /* ...HH:MM:SS.MMM */
uint32_t now = k_uptime_get_32();
unsigned int ms = now % MSEC_PER_SEC;
unsigned int s;
unsigned int min;
unsigned int h;
now /= MSEC_PER_SEC;
s = now % 60U;
now /= 60U;
min = now % 60U;
now /= 60U;
h = now;
snprintf(buf, sizeof(buf), "%u:%02u:%02u.%03u",
h, min, s, ms);
return buf;
}
static int process_icm42670(const struct device *dev)
{
struct sensor_value temperature;
struct sensor_value accel[3];
struct sensor_value gyro[3];
int rc = sensor_sample_fetch(dev);
if (rc == 0) {
rc = sensor_channel_get(dev, SENSOR_CHAN_ACCEL_XYZ,
accel);
}
if (rc == 0) {
rc = sensor_channel_get(dev, SENSOR_CHAN_GYRO_XYZ,
gyro);
}
if (rc == 0) {
rc = sensor_channel_get(dev, SENSOR_CHAN_DIE_TEMP,
&temperature);
}
if (rc == 0) {
printf("[%s]:% g Cel\n"
" accel % f % f % f m/s/s\n"
" gyro % f % f % f rad/s\n",
now_str(),
sensor_value_to_double(&temperature),
sensor_value_to_double(&accel[0]),
sensor_value_to_double(&accel[1]),
sensor_value_to_double(&accel[2]),
sensor_value_to_double(&gyro[0]),
sensor_value_to_double(&gyro[1]),
sensor_value_to_double(&gyro[2]));
} else {
printf("sample fetch/get failed: %d\n", rc);
}
return rc;
}
int main(void)
{
const struct device *const icm42670 = DEVICE_DT_GET_ONE(invensense_icm42670);
if (!device_is_ready(icm42670)) {
printk("sensor: device not ready.\n");
return 0;
}
process_icm42670(icm42670);
printf("Configured for triggered sampling.\n");
return 0;
}
prj.config:
CONFIG_SPI=y CONFIG_SENSOR=y