cancel
Showing results for 
Search instead for 
Did you mean: 

Question regarding implementation of LIS3DSH Standard C library.

GTS.1
Associate III

Hi,

I was taking a look at the STMems Standard C Library for the LIS3DSH. The implementation of the function lis3dsh_status_get looks a bit weird as there are 2 calls to the lis3dsh_write_reg functions.

int32_t lis3dsh_status_get(stmdev_ctx_t *ctx, lis3dsh_status_var_t *val)
{
  lis3dsh_ctrl_reg3_t ctrl_reg3;
  lis3dsh_ctrl_reg6_t ctrl_reg6;
  lis3dsh_stat_t stat;
  int32_t ret;
 
  ret = lis3dsh_read_reg(ctx, LIS3DSH_STAT, (uint8_t*)&stat, 1);
  if (ret == 0) {
    ret = lis3dsh_write_reg(ctx, LIS3DSH_CTRL_REG3, (uint8_t*)&ctrl_reg3, 1);
  }
  if (ret == 0) {
    ret = lis3dsh_write_reg(ctx, LIS3DSH_CTRL_REG6, (uint8_t*)&ctrl_reg6, 1);
  }
 
  val->sw_reset = ctrl_reg3.strt;
  val->boot     = ctrl_reg6.boot;
  val->drdy_xl  = stat.drdy;
  val->ovrn_xl  = stat.dor;
 
  return ret;
}

Shouldn't lis3dsh_read_reg be called to get the values of the control reg 3 and 6? If the write reg functions are called, wouldn't it populate the ctrl reg with garbage values?

Thanks

4 REPLIES 4
Eleon BORLINI
ST Employee

Hi @GTS.1​ , it seems you are right again ;) Thank you for your reporting, the driver will be fixed by the end of this week. Regards

No problem, I have few more questions regarding the library

  1. Why is the status_get function reading the STAT reg instead of the STATUS_REG?
  2. There is no function to enable/disable BDU and there are no functions to get raw individual axis values. This seems like a lack of functionality in the lib. Any reason why these were not included?

Hi @GTS.1​ , after an internal check with out API expert, I can tell you that we are re-defining the driver APIs at a higher level than before (especially on the newest sensors and on the LIS3DSH), according to the FAQ and the most common requirements from the customers. For these reason, the rational now is not to develop explicitly the low level functions.

To answer your specific questions:

>> Why is the status_get function reading the STAT reg instead of the STATUS_REG?

Actually the STATUS register isn't there because the info in this register are the drdy and the overrun for every axis, and it is not used from the majority of the programmer and user of the current , but we will add it ;)

>> enable/disable BDU

  lis3dsh_reg reg;
  lis3dsh_read_reg(ctx, LIS3DSH_CTRL_REG6, &reg.byte,1);
  reg.ctrl_reg6.bdu = PROPERTY_ENABLE;
   lis3dsh_write_reg(ctx, LIS3DSH_CTRL_REG6, &reg.byte,1);

>> get raw individual axis values

  int16_t raw_data
  lis3dsh_read_reg(ctx, LIS3DSH_OUT_Y_L, (uint8_t*)&raw_data,2); 
  data_mg = lis3dsh_from_fsX_tomg(raw_data)

Regards

GTS.1
Associate III

Thanks, this cleared up my question. I initially assumed that the status_get function reads the STATUS register. That was a wrong assumption on my part.