cancel
Showing results for 
Search instead for 
Did you mean: 

How to change LIS3DSH resolution

TrixCZE
Associate II

Hello everyone, 

I am new to STM32 and to Keil. I would like to change the accelerometer resolution from 2G to 16G, but due to my inexperience, I don't know how. My teacher didn't help my and said that I need to figure it out by myself, but I really don't know what to do. Can somebody help me what to do a what to change? 

Here is code that teacher provided: 

I will be very thankful is someone can help me. 

//-----------------------------NASTAVENI AKCELEROMETRU ( Setting)-------------------------
  //Defaultne je rozlišení +-2g
  //SPI Komunikace
  HAL_GPIO_WritePin(GPIOE, ACC_CS_Pin, GPIO_PIN_RESET); //Chip select
  adresaRegistru = 0x20; //CTRL_REG4
  HAL_SPI_Transmit(&hspi1, &adresaRegistru, 1, 50); 
  data = 0x37; //povol osy, 12,5Hz na vystupu
  HAL_SPI_Transmit(&hspi1, &data, 1, 50);
  HAL_GPIO_WritePin(GPIOE, ACC_CS_Pin, GPIO_PIN_SET); //Chip select
  HAL_Delay(20);

1 REPLY 1
Eleon BORLINI
ST Employee

Hi @Jakub Štef�?ek​ ,

>> My teacher didn't help my and said that I need to figure it out by myself, but I really don't know what to do.

That's typical 😉

Consider first that +-2g or +-16g is not the resolution (minimum signal) but the full scale of the accelerometer so it is the maximum signal that the sensor can acquire. So the resolution will be higher for FS +-2g.

In order to configure the +-16g full scale, you have to set into the register b100000 into theCTRL_REG5 (24h).

You can find an example of the overall device setting procedure here on Github --> lis3dsh_read_data_polling.c

  /* Set bdu and if_inc recommended for driver usage */
  lis3dsh_init_set(&dev_ctx, LIS3DSH_DRV_RDY);
  /* Select bus interface */
  bus_mode = LIS3DSH_SEL_BY_HW;
  lis3dsh_bus_mode_set(&dev_ctx, &bus_mode);
  /* Set Output Data Rate */
  lis3dsh_mode_get(&dev_ctx, &md);
  md.fs =  LIS3DSH_4g;
  md.odr = LIS3DSH_25Hz;
  lis3dsh_mode_set(&dev_ctx, &md);

Then, after you have acquired the data, you have to convert the LSB into physical units. You can find the drivers here -->

float_t lis3dsh_from_fs16_to_mg(int16_t lsb)
{
  return ((float_t)lsb) * 0.73f;
}

-Eleon