2023-10-31 10:06 AM
I am currently working with the LSM6DSOX IMU sensor from ST and I am unable to write to registers of the sensor.
I am addressing the sensor via 4 Wire SPI.
For example if I try to set the output data rate which is located in the register CTRL1_XL (0x10) setting the register to 0x40 and read back the register afterwards it is still at 0x00
Here is the data sent as seen by my logic analyzer (Chip Select is not pictured in this screenshot but it is low for the entire 16bit transfer)
First 8 bits is the address 0x10 (+write bit which is 0) and the next 8 is the data I want to write to it but if I read back this exact register after a short delay the register still shows 0x00.
(this is the same address, the first bit indicates read or !write so it looks different)
Reading registers seems to work fine. (registers like the who am I register return the correct data)
Does anyone know what the issue could be
Solved! Go to Solution.
2023-11-10 05:43 AM
Hello again,
The sensor has now inexplicably started accepting the values and it seems to work fine now.
I have not changed the circuit or the code in any way so I suspect that I may be working with a partially defective chip which I will replace with a new one.
In any case, thank you for trying to help
2023-11-03 04:13 AM
Hi @Reewen ,
Welcome to ST Community!
Can you share the part of your code in which you make these writings?
Thanks
2023-11-03 08:38 AM
Hello,
Here is my init method on my host microcontroller
void initLSM()
{
// Set the Accelerometer control register to work at 104 Hz, 2g
PORTA.OUT &= ~PIN4_bm;
SPITransmit(~READ & LSM6DSOX_CTRL1_XL);
SPITransmit(0x40);
PORTA.OUT |= PIN4_bm;
// disable I2C
for (volatile uint16_t i = 0; i < 100; i++);
PORTA.OUT &= ~PIN4_bm;
SPITransmit(~READ & LSM6DSOX_CTRL4_C);
SPITransmit(0x04);
PORTA.OUT |= PIN4_bm;
for (volatile uint16_t i = 0; i < 100; i++);
// set the gyroscope control register to work at 104 Hz, 250 dps and in bypass mode
PORTA.OUT &= ~PIN4_bm;
SPITransmit(~READ & LSM6DSOX_CTRL2_G); // send address
SPITransmit(0x40); // send DATA
PORTA.OUT |= PIN4_bm;
for (volatile uint16_t i = 0; i < 100; i++);
}
The for loops are there for delay purposes.
The ~READ define is essentially 0x7F to ensure that the MSB is 0 indicating a write transfer
Pin 4 on Port A is the Chip Select pin that is connected to the LSM6DSOXs Chip Select pin
2023-11-09 06:47 AM
Hi @Reewen ,
It seems all ok, can you try to eliminate the part in which you disable the I2C communication?
Let me know if this solves.
2023-11-10 05:43 AM
Hello again,
The sensor has now inexplicably started accepting the values and it seems to work fine now.
I have not changed the circuit or the code in any way so I suspect that I may be working with a partially defective chip which I will replace with a new one.
In any case, thank you for trying to help