Hello,
I am trying to use SPI driver to read BMI270 IMU data on my nRF52840dk. I stucked at verifying the sensor ID step. According to the datasheet, sensor ID is stored at register 0x00 and has a default value of 0x24. But I always read a 0x00.
I have created my own yaml file as shown below to enable interrupt (I understand the built-in bosch,bmi270.yaml has interrupt support. I am trying to understand the procedure here). And I have created my device overlay file:
&spi1 {
cs-gpios = <&gpio0 0 8>;
bmi270: bmi270@0{
compatible = "bosch,bmi270-spi-borus";
reg = <0>;
spi-max-frequency = <10000000>;
int_gpios = <&gpio0 7 GPIO_ACTIVE_HIGH>;
};
};compatible: "bosch,bmi270-spi-borus"
description: BORUS board custom devicetree node
include: spi-device.yaml
properties:
int_gpios:
type: phandle-array
description: interrupt gpio pins
required: trueI can confirm SPI1 is enabled and I2C1 is diabled. In my main.c file, I have declared spi_dt_spec structure, I have configured SPI mode to be mode 0, MSB first and 8 bit size. I have checked if SPI bus is ready without any error. Then I used this function from SPI tutorial static int bmi_read_reg(uint8_t reg, uint8_t *data, uint8_t size)
{
int err;
/* STEP 4.1 - Set the transmit and receive buffers */
uint8_t tx_buffer = reg;
struct spi_buf tx_spi_buf = {.buf = (void *)&tx_buffer, .len = 1};
struct spi_buf_set tx_spi_buf_set = {.buffers = &tx_spi_buf, .count = 1};
struct spi_buf rx_spi_bufs = {.buf = data, .len = size};
struct spi_buf_set rx_spi_buf_set = {.buffers = &rx_spi_bufs, .count = 1};
/* STEP 4.2 - Call the transceive function */
err = spi_transceive_dt(&spispec, &tx_spi_buf_set, &rx_spi_buf_set);
if (err < 0) {
LOG_ERR("spi_transceive_dt() failed, err: %d", err);
return err;
}
return 0;
}to read register value. But the return value is always 0. In the datasheet, it mentions to configure to SPI mode by reading a register value first, then wait for 450us to use SPI communication. I have tried to add a k_usleep(450) after the first call, but still not working. Any idea how can I debug this issue?
I have tried on both windows and macos using nrf connect vs code extension. The version of sdk and toolchain are both 2.7.0.