cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to write registers for the LSM6DSOX IMU sensor

Reewen
Associate II

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)

Reewen_0-1698771323820.png

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.

Reewen_1-1698771469356.png

(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

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

4 REPLIES 4
Federica Bossi
ST Employee

Hi @Reewen ,

Welcome to ST Community!

Can you share the part of your code in which you make these writings?

Thanks

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

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

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.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

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