Skip to main content
Visitor II
October 9, 2023
Question

Using LIS25BA with STM32L4 Nucleo Board

  • October 9, 2023
  • 1 reply
  • 1963 views

I am using STM32L452RE Nucleo Board and LIS25BA module.

I2C works fine. I wish to get accelerometer data through TDM now. I am unable to do so. For now, I am using polling mode. The code I am using is given below and the SAI configuration I am using is also attached.

/* USER CODE BEGIN 2 */
int16_t rdat[8];
  uint8_t chipid=0;
  uint8_t cmax=0x7f;
  uint8_t ctrlreg=0;
  uint8_t tdmctrlreg=0x64;
  uint8_t axesctrlreg=0xe0;
  uint8_t rcmax;
uint8_t rctrlreg;
uint8_t rtdmctrlreg;
uint8_t raxesctrlreg;
  HAL_I2C_Mem_Read (&hi2c2, 0x33, 0x0f, 1, &chipid, 1, 100);
  HAL_I2C_Mem_Write(&hi2c2, 0x32, 0x25, 1, &cmax, 1, 100);
  HAL_I2C_Mem_Write(&hi2c2, 0x32, 0x26, 1, &ctrlreg, 1, 100);
  HAL_I2C_Mem_Write(&hi2c2, 0x32, 0x2e, 1, &tdmctrlreg, 1, 100);
  HAL_I2C_Mem_Write(&hi2c2, 0x32, 0x2f, 1, &axesctrlreg, 1, 100);
  HAL_I2C_Mem_Read (&hi2c2, 0x33, 0x25, 1, &rcmax, 1, 100);//read data back
  HAL_I2C_Mem_Read (&hi2c2, 0x33, 0x26, 1, &rctrlreg, 1, 100);//read data back
  HAL_I2C_Mem_Read (&hi2c2, 0x33, 0x2e, 1, &rtdmctrlreg, 1, 100);//read data back
  HAL_I2C_Mem_Read (&hi2c2, 0x33, 0x2f, 1, &raxesctrlreg, 1, 100);//read data back
  /* USER CODE END 2 */
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  HAL_SAI_Receive(&hsai_BlockA1, (uint8_t*)rdat, 8, 100);
    /* USER CODE END WHILE */
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */

 Please let me know if it is possible to get data using SAI or I2S or any other method using this nucleo board or any other board. Thanks.

    This topic has been closed for replies.

    1 reply

    ST Employee
    October 11, 2023
    ArkaAuthor
    Visitor II
    October 13, 2023

    It doesnt work for some reason. I have tried all possible configurations, 8kHz, 16kHz and 24kHz. The first 2 seems to give some random values which do not change based on acceleration. 24kHz mode gives some rapidly changing values but I think the clock is not synchronized properly. I should get three 16 bit values corresponding to x-y-z axes in 3 slots. But the rdat variable is filled up with 4 slots. So probably the 48 bits do not get synced with 16 bit slots of my array.

    RM0394 page 1349 says "In the SAI, the single ratio MCLK/FS = 256 is considered." But for LIS25BA this is impossible as it needs MCLK=12.288MHz and does not support FS at 48kHz. So I tried using PWM to emulate SAI_MCLK as given here STM32 Drive LIS25BA - MEMS Sensors - Electronic Engineering World - Forum (eeworld.com.cn)

    But even this does not work.