2025-04-01 1:36 AM
hello
I've been trying to use the LSM6DSV on it's steval-mki239a board with a nucleo board (nucleo-l476rg) via SPI and the lsm6dsv is not answering whatever the configuration of my SPI is.
The sensor is fine since it work with the steval-mki109v3 board ans the MEMS studio
I checked the SPI signal on the steval mki109v3 with a logical analyzer and found several odd things but the sensor is answering
I don't know if it is my analyzer but the MISO line is always stuck at 1 and the level of MOSI are strange but the sensor understand the message and answer with the right value (WHO_AM_I register: MOSI should send 0x0F and MISO answer 0x70)
On the other end I tried to recreate the same configuration on my nucleo board but the sensor doesn't answer any command
I tried:
full duplex master CPOL=1 CPHA=1
with external pull up on MISO
full duplex master CPOL=1 CPHA=0
with external pull up on MISO
I tried in master half duplex
with external pull up on MISO
I tried master half duplex with CPHA =0 (1 edge)
with external pull up on MISO
I've been trying to make this work for more than a week now and tried all possible configuration but nothing works. what could be wrong? did I miss something?
I'm using the LSM6DSV library found here https://github.com/STMicroelectronics/lsm6dsv-pid/tree/7b98628713090244cf14f54d9059938cb00342fd that I adapted following the readme file
I attached my complete project
Solved! Go to Solution.
2025-04-03 1:47 AM
Hi @Eddess,
Your problem here is in the implementation you made of the function platform_read.
Your implementation must first send the register you want to read and then receive a response but if you want the lsm6dsv to know that you want a response you must set the MSB of the register to 1 as stated in documentation.
Exemple :
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, uint16_t len){
reg |= 0x80; // Don't forget this line !
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(handle, ®, 1, 1000);
HAL_SPI_Receive(handle, bufp, len, 1000);
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);
return 0;
}
2025-04-03 1:47 AM
Hi @Eddess,
Your problem here is in the implementation you made of the function platform_read.
Your implementation must first send the register you want to read and then receive a response but if you want the lsm6dsv to know that you want a response you must set the MSB of the register to 1 as stated in documentation.
Exemple :
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, uint16_t len){
reg |= 0x80; // Don't forget this line !
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(handle, ®, 1, 1000);
HAL_SPI_Receive(handle, bufp, len, 1000);
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);
return 0;
}