2022-11-10 10:08 PM - last edited on 2025-04-04 1:33 AM by Andrew Neil
I have recently brought a STEVAL-STLKT01V1 SensorTile kit in which LSM6DSM, LSM303AGR & LPS22HB are connected in 3 wire SPI on the SPI2 line of STM32L476. I pulled 4 CS lines to high at the beginning of the program and have set the SPI2 to Half duplex master mode with low data transfer rate. even though using the c command lsm6dsm_spi_mode_set(&dev_ctx, LSM6DSM_AUX_SPI_3_WIRE); I'm getting no response on spi read, so the program is getting struck at lsm6dsm_reset_get(&dev_ctx, &rst).
I was able to use 4 wire SPI with STM32F407 and LSM6DSM, but I still face issues with using 3 Wire mode with STM32F407 and LSM6DSM
i have defined the CS Pin:
#define CS_up_GPIO_Port CS_AG_GPIO_Port
#define CS_up_Pin CS_AG_Pin
my GPIO Configuration:
Sensor Initialization:
/* Initialize mems driver interface */
stmdev_ctx_t dev_ctx;
dev_ctx.write_reg = platform_write;
dev_ctx.read_reg = platform_read;
dev_ctx.handle = &SENSOR_BUS;
/* Wait sensor boot time */
HAL_Delay(15);
lsm6dsm_spi_mode_set(&dev_ctx, LSM6DSM_AUX_SPI_3_WIRE);
lsm6dsm_auto_increment_set(&dev_ctx, 1);
/* Restore default configuration */
lsm6dsm_reset_set(&dev_ctx, PROPERTY_ENABLE);
do {
lsm6dsm_reset_get(&dev_ctx, &rst);
} while (rst);
/* Enable Block Data Update */
lsm6dsm_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);
/* Set Output Data Rate for Acc and Gyro */
lsm6dsm_xl_data_rate_set(&dev_ctx, LSM6DSM_XL_ODR_12Hz5);
lsm6dsm_gy_data_rate_set(&dev_ctx, LSM6DSM_GY_ODR_12Hz5);
/* Set full scale */
lsm6dsm_xl_full_scale_set(&dev_ctx, LSM6DSM_2g);
lsm6dsm_gy_full_scale_set(&dev_ctx, LSM6DSM_2000dps);
/* Configure filtering chain(No aux interface)
* Accelerometer - analog filter
*/
lsm6dsm_xl_filter_analog_set(&dev_ctx, LSM6DSM_XL_ANA_BW_400Hz);
/* Accelerometer - LPF1 path (LPF2 not used) */
//lsm6dsm_xl_lp1_bandwidth_set(&dev_ctx, LSM6DSM_XL_LP1_ODR_DIV_4);
/* Accelerometer - LPF1 + LPF2 path */
lsm6dsm_xl_lp2_bandwidth_set(&dev_ctx, LSM6DSM_XL_LOW_NOISE_LP_ODR_DIV_100);
/* Accelerometer - High Pass / Slope path */
//lsm6dsm_xl_reference_mode_set(&dev_ctx, PROPERTY_DISABLE);
//lsm6dsm_xl_hp_bandwidth_set(&dev_ctx, LSM6DSM_XL_HP_ODR_DIV_100);
/* Gyroscope - filtering chain */
lsm6dsm_gy_band_pass_set(&dev_ctx, LSM6DSM_HP_260mHz_LP1_STRONG);
SPI Read & Write:
static int32_t platform_write(void *handle, uint8_t reg,
uint8_t *bufp,
uint16_t len)
{
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(handle, ®, 1, 1000);
HAL_SPI_Transmit(handle, bufp, len, 1000);
HAL_GPIO_WritePin(CS_up_GPIO_Port, CS_up_Pin, GPIO_PIN_SET);
}
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp,
uint16_t len)
{
reg |= 0x80;
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);
}
kindly reply what's the issue with the above-followed procedure
2022-12-26 9:13 PM
Hi @Soundhar . Can you solved the problem ?
2024-10-07 6:47 AM
Hi,
Can you solved the problem? Because I have know the same problem.
2025-03-30 11:47 PM
Same problem but on 4 wire mode i can read id but stuck at reset