cancel
Showing results for 
Search instead for 
Did you mean: 

Read data from gyroscope LSM6DSO using IKS01A1

AJab�
Associate II

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);
}

0690X000006CUonQAG.png

2 REPLIES 2
Miroslav BATEK
ST Employee

The gyroscope in LSM6DS0 cannot work standalone you have to enable also accelerometer.

0690X000006CVBXQA4.png

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.