2021-03-20 08:27 AM
lis2mdl_reg.c has an error in the function int32_t lis2mdl_mag_user_offset_set(stmdev_ctx_t *ctx, int16_t *val).
The function incorrectly calculates the OFFSET_X_REG_H, OFFSET_Y_REG_H, and the OFFSET_Z_REG_H registers because it converts val[0] to an uint8_t before performing the calculation.
I believe the function should be modified as follows:
int32_t lis2mdl_mag_user_offset_set(stmdev_ctx_t *ctx, int16_t *val)
{
uint8_t buff[6];
int32_t ret;
buff[1] = (uint8_t) (val[0] / 256U);
buff[0] = (uint8_t) (val[0] - (buff[1] * 256U));
buff[3] = (uint8_t) (val[1] / 256U);
buff[2] = (uint8_t) (val[1] - (buff[1] * 256U));
buff[5] = (uint8_t) (val[2] / 256U);
buff[4] = (uint8_t) (val[2] - (buff[1] * 256U));
ret = lis2mdl_write_reg(ctx, LIS2MDL_OFFSET_X_REG_L, buff, 6);
return ret;
}
Solved! Go to Solution.
2021-03-22 05:19 AM
Yes, the change I made does work properly. I will open an issue on the GitHub page.
Thanks for your reply.
2021-03-22 02:49 AM
Hi @Clark Sann ,
thank you for the notification. Does it work properly with your correction?
I suggest you to open an Issue in the Github page of the STMems_Standard_C_drivers.
This will facilitate our experts to fix the code. The typical due date for the correction is 1 week: please let me know if this issue is solved after this timeframe.
-Eleon
2021-03-22 05:19 AM
Yes, the change I made does work properly. I will open an issue on the GitHub page.
Thanks for your reply.