2018-11-27 12:33 PM
I'm trying to read data from gyroscope. I set ctrl2_g and I'm trying to read 6 bytes from register address 22h. But in result I receive only 0 values.
/* USER CODE BEGIN 2 */
LSM6DSO_CTRL2_G(&hi2c1, LSM6DSO_CTRL2_G_ODR_XL_833Hz, LSM6DSO_CTRL2_G_FS_G_250 ,
LSM6DSO_CTRL2_G_FS_125_NO_SET);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
LSM6DSO_G_OUT(&hi2c1, &read_LSM6DSO_G, LSM6DSO_FS_SENSITIVITY_G_250);
size = sprintf((char*) data, "%.3f, %.3f, %.3f\n", read_LSM6DSO_G[0],
read_LSM6DSO_G[1], read_LSM6DSO_G[2]);
HAL_UART_Transmit(&huart2, data, size, 100);
HAL_Delay(80);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
void LSM6DSO_G_OUT(I2C_HandleTypeDef *hi2c, float *tab, float sensitivity){
uint8_t raw_data[6];
int16_t temp = 0;
float val = 0;
if(HAL_I2C_Mem_Read_IT(hi2c, LSM6DSO_ACC_ADDRESS, LSM6DSO_G_OUT_X_MULTI_BYTE, 1, &raw_data, 6) != HAL_OK){
Error_Handler();
}
while (HAL_I2C_GetState(hi2c) != HAL_I2C_STATE_READY){}
temp = ((raw_data[1] << 8) | raw_data[0]);
tab[0] = ((float)temp*sensitivity)/(float)1000;
temp = ((raw_data[3] << 8) | raw_data[2]);
tab[1] = ((float)temp*sensitivity)/(float)1000;
temp = ((raw_data[5] << 8) | raw_data[4]);
tab[2] = ((float)temp*sensitivity)/(float)1000;
}
void LSM6DSO_CTRL2_G(I2C_HandleTypeDef *hi2c, uint8_t ODR_G, uint8_t FS_G, uint8_t FS_125){
uint8_t result = 0;
result = ODR_G | FS_G | FS_125;
HAL_I2C_Mem_Write(hi2c, LSM6DSO_ACC_ADDRESS, LSM6DSO_CTRL2_G_REG, 1, &result, 1, HAL_MAX_DELAY);
}
2018-11-28 03:03 AM
The gyroscope in LSM6DS0 cannot work standalone you have to enable also accelerometer.
2018-12-07 12:22 AM
Thank you for your answer. Thanks to it, I've realized that there is difference between LSM6DSO and LSM6DS0 and I had used wrong datasheet. Now my program works properly.