cancel
Showing results for 
Search instead for 
Did you mean: 

How can set register values of LSM6DSOX from .ucf file without using motherboard

Idede.1
Associate

I convert .ucf file to .h by using unico GUI. But I couldn't set the register values via HAL I2C functions. I couldn't get any decision tree result.

/*
 ******************************************************************************
 * @file    LSM6DSOX_configuration.h
 * @author  Sensors Software Solution Team
 * @brief   This file contains the configuration for LSM6DSOX_configuration.
 *
 ******************************************************************************
 * @attention
 *
 * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
 * All rights reserved.</center></h2>
 *
 * This software component is licensed by ST under BSD 3-Clause license,
 * the "License"; You may not use this file except in compliance with the
 * License. You may obtain a copy of the License at:
 *                        opensource.org/licenses/BSD-3-Clause
 *
 */
 
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef LSM6DSOX_CONFIGURATION_H
#define LSM6DSOX_CONFIGURATION_H
 
#ifdef __cplusplus
  extern "C" {
#endif
 
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
#ifndef MEMS_UCF_SHARED_TYPES
#define MEMS_UCF_SHARED_TYPES
 
/** Common data block definition **/
typedef struct {
  uint8_t address;
  uint8_t data;
} ucf_line_t;
 
#endif /* MEMS_UCF_SHARED_TYPES */
 
/** Configuration array generated from Unico Tool **/
const ucf_line_t LSM6DSOX_configuration[] = {
  {.address = 0x10, .data = 0x00,},
  {.address = 0x11, .data = 0x00,},
  {.address = 0x01, .data = 0x80,},
  {.address = 0x05, .data = 0x00,},
  {.address = 0x17, .data = 0x40,},
  {.address = 0x02, .data = 0x11,},
  {.address = 0x08, .data = 0xEA,},
  {.address = 0x09, .data = 0x52,},
  {.address = 0x09, .data = 0x03,},
  {.address = 0x09, .data = 0x5E,},
  {.address = 0x09, .data = 0x03,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x0A,},
  {.address = 0x02, .data = 0x11,},
  {.address = 0x08, .data = 0xF2,},
  {.address = 0x09, .data = 0x1A,},
  {.address = 0x02, .data = 0x11,},
  {.address = 0x08, .data = 0xFA,},
  {.address = 0x09, .data = 0x3C,},
  {.address = 0x09, .data = 0x03,},
  {.address = 0x09, .data = 0x64,},
  {.address = 0x09, .data = 0x03,},
  {.address = 0x09, .data = 0x70,},
  {.address = 0x09, .data = 0x03,},
  {.address = 0x02, .data = 0x31,},
  {.address = 0x08, .data = 0x3C,},
  {.address = 0x09, .data = 0x01,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x3F,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x0C,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x18,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x01,},
  {.address = 0x09, .data = 0x10,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x1F,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x02, .data = 0x31,},
  {.address = 0x08, .data = 0x64,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x01, .data = 0x00,},
  {.address = 0x12, .data = 0x00,},
  {.address = 0x01, .data = 0x80,},
  {.address = 0x17, .data = 0x40,},
  {.address = 0x02, .data = 0x31,},
  {.address = 0x08, .data = 0x70,},
  {.address = 0x09, .data = 0x00,},
  {.address = 0x09, .data = 0x1A,},
  {.address = 0x09, .data = 0x80,},
  {.address = 0x09, .data = 0xA2,},
  {.address = 0x09, .data = 0xC1,},
  {.address = 0x09, .data = 0xBA,},
  {.address = 0x09, .data = 0x04,},
  {.address = 0x09, .data = 0xE0,},
  {.address = 0x01, .data = 0x80,},
  {.address = 0x17, .data = 0x00,},
  {.address = 0x04, .data = 0x00,},
  {.address = 0x05, .data = 0x10,},
  {.address = 0x02, .data = 0x01,},
  {.address = 0x01, .data = 0x00,},
  {.address = 0x12, .data = 0x44,},
  {.address = 0x01, .data = 0x80,},
  {.address = 0x60, .data = 0x15,},
  {.address = 0x01, .data = 0x00,},
  {.address = 0x10, .data = 0x20,},
  {.address = 0x11, .data = 0x00,},
  {.address = 0x5E, .data = 0x02,},
  {.address = 0x01, .data = 0x80,},
  {.address = 0x0D, .data = 0x01,},
  {.address = 0x01, .data = 0x00,}
};
 
#ifdef __cplusplus
}
#endif
 
#endif /* LSM6DSOX_CONFIGURATION_H */
 
#include <LSM6DSOX_configuration.h>
.
.
.
for(j = 0 ; j < 93 ; j++){
    i2c_buffer[0] = LSM6DSOX_configuration[j].data;
    HAL_I2C_Mem_Write(&hi2c1, 214, LSM6DSOX_configuration[j].address, 1, i2c_buffer, 1, 1000);
 }
.
.
.
HAL_I2C_Mem_Read (&hi2c1, 214, 0x70, 1, data_rec, 1, 1000); //MLC0_SRC Register
Dec_Tree_Result = data_rec[0];

1 ACCEPTED SOLUTION

Accepted Solutions
Eleon BORLINI
ST Employee

Hi @Idede.1​ ,

before writing the MLC configuration in the registers, did you enable the MLC writing the MLC_EN bit in the EMB_FUNC_EN_B (05h) register?

For your reference, a general procedure for LSM6DSOX MLC setting can be found, for example, in the FP-SNS-ALLMEMS1 drivers (attached):

/**
  * @brief  Enable Machine Learning Core.[set]
  *
  * @param  ctx      read / write interface definitions
  * @param  val      change the values of mlc_en in
  *                  reg EMB_FUNC_EN_B and mlc_init
  *                  in EMB_FUNC_INIT_B
  *
  */
int32_t lsm6dsox_mlc_set(stmdev_ctx_t *ctx, uint8_t val)
{
  lsm6dsox_emb_func_en_b_t reg;
  int32_t ret;
 
  ret = lsm6dsox_mem_bank_set(ctx, LSM6DSOX_EMBEDDED_FUNC_BANK);
  if (ret == 0) {
    ret = lsm6dsox_read_reg(ctx, LSM6DSOX_EMB_FUNC_EN_B, (uint8_t*)&reg, 1);
  }
  if (ret == 0) {
    reg.mlc_en = val;
    ret = lsm6dsox_write_reg(ctx, LSM6DSOX_EMB_FUNC_EN_B, (uint8_t*)&reg, 1);
  }
  if ((val != PROPERTY_DISABLE) && (ret == 0)){
    ret = lsm6dsox_read_reg(ctx, LSM6DSOX_EMB_FUNC_INIT_B,
                                 (uint8_t*)&reg, 1);
    if (ret == 0) {
      reg.mlc_en = val;
      ret = lsm6dsox_write_reg(ctx, LSM6DSOX_EMB_FUNC_INIT_B,
                                  (uint8_t*)&reg, 1);
    }
  }
  if (ret == 0) {
    ret = lsm6dsox_mem_bank_set(ctx, LSM6DSOX_USER_BANK);
  }
  return ret;
}

Another thing to check is whether the I2C works correctly, for example reading the WHO_AM_I (0Fh) register and getting the right ID.

If my reply helped you with your question, please click on Select as Best at the bottom of this post. This will allow other users with the same issue to find the answer faster. 

-Eleon

View solution in original post

1 REPLY 1
Eleon BORLINI
ST Employee

Hi @Idede.1​ ,

before writing the MLC configuration in the registers, did you enable the MLC writing the MLC_EN bit in the EMB_FUNC_EN_B (05h) register?

For your reference, a general procedure for LSM6DSOX MLC setting can be found, for example, in the FP-SNS-ALLMEMS1 drivers (attached):

/**
  * @brief  Enable Machine Learning Core.[set]
  *
  * @param  ctx      read / write interface definitions
  * @param  val      change the values of mlc_en in
  *                  reg EMB_FUNC_EN_B and mlc_init
  *                  in EMB_FUNC_INIT_B
  *
  */
int32_t lsm6dsox_mlc_set(stmdev_ctx_t *ctx, uint8_t val)
{
  lsm6dsox_emb_func_en_b_t reg;
  int32_t ret;
 
  ret = lsm6dsox_mem_bank_set(ctx, LSM6DSOX_EMBEDDED_FUNC_BANK);
  if (ret == 0) {
    ret = lsm6dsox_read_reg(ctx, LSM6DSOX_EMB_FUNC_EN_B, (uint8_t*)&reg, 1);
  }
  if (ret == 0) {
    reg.mlc_en = val;
    ret = lsm6dsox_write_reg(ctx, LSM6DSOX_EMB_FUNC_EN_B, (uint8_t*)&reg, 1);
  }
  if ((val != PROPERTY_DISABLE) && (ret == 0)){
    ret = lsm6dsox_read_reg(ctx, LSM6DSOX_EMB_FUNC_INIT_B,
                                 (uint8_t*)&reg, 1);
    if (ret == 0) {
      reg.mlc_en = val;
      ret = lsm6dsox_write_reg(ctx, LSM6DSOX_EMB_FUNC_INIT_B,
                                  (uint8_t*)&reg, 1);
    }
  }
  if (ret == 0) {
    ret = lsm6dsox_mem_bank_set(ctx, LSM6DSOX_USER_BANK);
  }
  return ret;
}

Another thing to check is whether the I2C works correctly, for example reading the WHO_AM_I (0Fh) register and getting the right ID.

If my reply helped you with your question, please click on Select as Best at the bottom of this post. This will allow other users with the same issue to find the answer faster. 

-Eleon