ASM330LHHXTR SPI Interface Issue
Hi everyone,
I am currently using an ESP32-S3 development board to read ST's 6-axis IMU sensors via SPI, but I am encountering abnormal values when trying to read the Device ID (WHO_AM_I, 0x0F). After doing some cross-testing, I noticed a very strange hardware phenomenon. I would appreciate any debugging advice or insights.
[Hardware Setup]
-
MCU: ESP32-S3 Devkit
-
Sensors:
-
ASM330LHHXTR
-
STEVAL MKI215V1 (LSM6DSO evaluation board)
-
SparkFun LSM6DSO Breakout
-
-
Power Supply: 3.3V
-
Interface: SPI (I have already tried switching between 3-wire and 4-wire modes)
[Issue Description & Troubleshooting Steps] The expected Device ID is 0x6B, but it fails to read correctly. My debugging process is as follows:
-
ASM330LHHXTR Test: Using the code provided below, the Device ID returns
0x40or0x48. -
STEVAL MKI215V1 Test: Switched to this evaluation board, and the Device ID returns
0x50.-
The Anomaly: If I disconnect the sensor's GND wire and press Reset on the ESP32, the Device ID reads correctly as
0x6B. This doesn't make sense logically.
-
-
SparkFun LSM6DSO Test:
-
First, I tested it using I2C with the official GitHub library, and it worked perfectly.
-
Then, I changed the hardware wiring and code to use SPI, and the exact same issue from Step 2 occurred.
-
-
Reproducing the GND Anomaly: On the SparkFun module, the same phenomenon happens—disconnecting the GND wire and pressing Reset makes the Device ID read correctly.
[My Questions]
-
Why does the Device ID read normally when the GND wire is unplugged, but return garbage data when connected? Does this imply a blind spot in my hardware wiring (e.g., leakage current, parasitic powering, or an I2C/SPI pin state conflict)?
-
Am I missing something in my ESP32-S3 SPI initialization setup?
Any advice or suggestions for further testing would be greatly appreciated. Thank you!
[Test Code]
#include <SPI.h>
// ESP32-S3 Pin Define
const int PIN_MOSI = 11;
const int PIN_SCK = 12;
const int PIN_MISO = 13;
const int CSPin = 14;
// ==========================================
// Function Prototypes
// ==========================================
void SPI_write(uint8_t WriteAddr, uint8_t WriteData);
uint8_t SPI_read(uint8_t ReadAddr);
void SPI_multi_read(uint8_t ReadAddr, uint8_t *ReadBuf, unsigned int Bytes);
bool ASM330LHH_Initial();
// ==========================================
// Main
// ==========================================
void setup() {
Serial.begin(115200);
delay(500);
pinMode(CSPin, OUTPUT);
digitalWrite(CSPin, HIGH);
delay(10);
// SPI.begin();
// SPI.begin(PIN_SCK, PIN_MISO, PIN_MOSI, -1);
SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
if (!ASM330LHH_Initial()) {
Serial.println("[ERROR] Initial ASM330LHH FAILED.");
while (1) {
delay(100);
}
}
}
void loop() {
uint8_t Device_ID = SPI_read(0x0F);
Serial.print("Device ID 0x");
if (Device_ID < 0x10) Serial.print("0");
Serial.println(Device_ID, HEX);
uint8_t CTRL3_C = SPI_read(0x12);
Serial.print("CTRL3_C 0x");
Serial.println(CTRL3_C, HEX);
uint8_t OUTX_L_A = SPI_read(0x28);
Serial.print("OUTX_L_A 0x");
Serial.println(OUTX_L_A, HEX);
uint8_t OUTX_H_A = SPI_read(0x29);
Serial.print("OUTX_H_A 0x");
Serial.println(OUTX_H_A, HEX);
delay(1000);
}
// ====================================================================================
// Basic SPI R/W Function
// ====================================================================================
uint8_t SPI_read(uint8_t ReadAddr) {
uint8_t val;
digitalWrite(CSPin, LOW);
SPI.transfer(ReadAddr | 0x80);
val = SPI.transfer(0x00);
digitalWrite(CSPin, HIGH);
return val;
}
void SPI_write(uint8_t WriteAddr, uint8_t WriteData) {
digitalWrite(CSPin, LOW);
// Send Address and ensure the write flag (MSb = 0)
SPI.transfer(WriteAddr & 0x7F);
SPI.transfer(WriteData);
digitalWrite(CSPin, HIGH);
}
// ====================================================================================
// ASM330LHH Initial
// ====================================================================================
bool ASM330LHH_Initial() {
uint8_t id = SPI_read(0x0F);
Serial.print("Initial WHO_AM_I = 0x");
Serial.println(id, HEX);
return true;
}
[ASM330LHHXTR Schematic]
Note: R4 NC

