ESP32 SPI read registers of LSM6DS33 IMU Sensor

Hi. I'm trying to read who am i register of LSM6DS33 IMU sensor ESP32 arduino SPI library. It works when i use Adafruit_SPIDevice and Adafruit_BUSIO_Register library with software SPI. But now i want to use hardware SPI. I tried example HSPI and VSPI code and then Just used SPI.begin() and specified miso mosi clk pins. Transfer function always returns the value that i'm trying to send. What am i missing? Any suggestions?

#include <SPI.h>

static const int spiClk = 100000; // 1 MHz

uint8_t READ_BYTE = 0x01;
uint8_t WRITE_BYTE = 0x00;
uint8_t WHO_AM_I = 0X0F;

void setup() {

  Serial.begin(921600);
  SPI.begin(18, 19, 23); //SCLK, MISO, MOSI

  pinMode(5, OUTPUT); //CS

}

void loop() {


  SPI.beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
  digitalWrite(5, LOW); //pull SS slow to prep other end for transfer
  uint8_t a = SPI.transfer((WHO_AM_I << 1) | READ_BYTE);
  uint8_t b = SPI.transfer(0X00); // Dummy byte
  digitalWrite(5, HIGH); //pull ss high to signify end of data transfer
  SPI.endTransaction();

  Serial.println(a, BIN);
  Serial.println(b, BIN);

  delay(5000);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.