Hello, I want to configure the BMP390 using I2C on my custom board. However, when I try to read the CHIP_ID register, I am unable to get the default value, and the function i2c_reg_read_byte_dt
returns -5. I have already replaced the sensor, but still cannot read any data. What could be the problem? Is there any error that I might be missing?
This is my devicetree file. &i2c0 {
compatible = "nordic,nrf-twi";
status = "okay";
pinctrl-0 = <&i2c0_default>;
pinctrl-1 = <&i2c0_sleep>;
icm42670_device: icm42670@68 {
compatible = "invensense,icm42670";
/* reg is the I2C device address.
* It must match the node's unit address. */
reg = <0x68>;
status = "okay";
/* Configure other I2C device properties as needed.
* Find your device's DT binding for details. */
accel-hz = <400>;
gyro-hz = <400>;
accel-fs = <8>;
gyro-fs = <1000>;
};
bmp388_device: bmp388@76 {
compatible = "bosch,bmp388";
/* reg is the I2C device address.
* It must match the node's unit address. */
reg = <0x76>;
/* Configure other I2C device properties as needed.
* Find your device's DT binding for details. */
status = "okay";
odr = "200";
osr-press = <8>;
osr-temp = <1>;
iir-filter = <3>;
};
clock-frequency = <I2C_BITRATE_STANDARD>;
};
This is my main.c#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio.h>
#include <stdio.h>
#include <stdlib.h>
#include "../bmp388/bmp388.h"
#include "../icm42670/icm42670.h"
const struct i2c_dt_spec icm42670_dev = I2C_DT_SPEC_GET(ICM42670_NODE);
const struct i2c_dt_spec bmp388_dev = I2C_DT_SPEC_GET(BMP388_NODE);
int main()
{
//checking icm42670 bus
if (!device_is_ready(icm42670_dev.bus)) {
blinkSelectedLED(leds,RED_LED_IDX);
printk("ICM42670 device is not ready\n");
return -1;
}
//checking bmp388 bus
if (!device_is_ready(bmp388_dev.bus)) {
printk("BMP388 device is not ready\n");
blinkSelectedLED(leds,RED_LED_IDX);
return -1;
}
bmp388_init(&bmp388_dev);
if(icm42670_init(&icm42670_dev) != ICM42670_OK)
{
return -1;
}
static ICM42670_accelData accel_data = {0};
static ICM42670_gyroData gyro_data = {0};
while(true)
{
icm42670_get_acceldata(&icm42670_dev,&accel_data);
icm42670_get_gyrodata(&icm42670_dev,&gyro_data);
k_msleep(100);
}
return 0;
}
This is my bmp related c file#include "bmp388.h"
BMP388_err_t bmp388_init(const struct i2c_dt_spec* dev_i2c)
{
int ret = 0;
uint8_t data;
if (!device_is_ready(dev_i2c->bus))
{
printk("I2C bus is not ready!\n");
return BMP388_BUS_NOT_RDY;
}
ret = i2c_reg_read_byte_dt(dev_i2c,BMP388_REG_CHIPID,&data);
if(ret != 0){
printk("Failed to read from I2C device address %x \n\r", dev_i2c->addr);
return BMP388_REG_READ_ERR;
}
return BMP388_OK;
}