I have a custom board with nrf52832 and LIS2DW12. I was trying to poll accelerometer data, but getting "app: fetch failed: -134" error"
My dts file is:
&i2c1 {
compatible = "nordic,nrf-twim";
status = "okay";
clock-frequency = <I2C_BITRATE_FAST>; /* 400 kHz */
pinctrl-0 = <&i2c1_default>;
pinctrl-1 = <&i2c1_sleep>;
pinctrl-names = "default", "sleep";
lis2dw12: lis2dw12@18 {
compatible = "st,lis2dw12";
status = "okay";
reg = <0x18>;
power-mode = < 3 >;
range = <2>;
odr = <1>;
};
};
CODE:
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/i2c.h>
#include <zephyr/drivers/sensor.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(app, LOG_LEVEL_INF);
/* Use the node label from the overlay: lis2dw12 */
#define LIS2DW12_NODE DT_NODELABEL(lis2dw12)
void main(void)
{
const struct device *accel = DEVICE_DT_GET(LIS2DW12_NODE);
if (!device_is_ready(accel))
{
LOG_ERR("LIS2DW12 device not ready");
return;
}
LOG_INF("LIS2DW12 ready, polling @ 1 s");
while (1)
{
int rc = sensor_sample_fetch(accel);
if (rc != 0)
{
LOG_ERR("fetch failed: %d", rc);
k_sleep(K_SECONDS(1));
continue;
}
struct sensor_value xyz[3];
int rc = sensor_channel_get(accel, SENSOR_CHAN_ACCEL_XYZ, xyz);
if (rc)
{
LOG_ERR("channel_get failed: %d", rc);
}
else
{
/* Values are in m/s^2; convert to mg if you prefer */
LOG_INF("Accel: X=%d.%06d Y=%d.%06d Z=%d.%06d (m/s^2)",
xyz[0].val1, xyz[0].val2,
xyz[1].val1, xyz[1].val2,
xyz[2].val1, xyz[2].val2);
}
k_sleep(K_SECONDS(1)); /* 1 Hz polling */
}
}
I am getting following error:
"app: fetch failed: -134"
I have checked i2c, it is okey.
How can i read accelerometer data???