STMicroelectronics / STMems_Standard_C_drivers

Platform-independent drivers for STMicroelectronics MEMS motion and environmental sensors, based on standard C programming language.
BSD 3-Clause "New" or "Revised" License
705 stars 517 forks source link

i3g4250d: incorrect multiple byte reading in i3g4250d_angular_rate_raw_get() #135

Closed albatron22 closed 3 years ago

albatron22 commented 3 years ago

Device part numbers

i3g4250d

Type of bug

Driver. File i3g4250d_reg.c

Describe the bug

I found an incorrect multiple byte reading in function int32_t i3g4250d_angular_rate_raw_get(stmdev_ctx_t *ctx, int16_t *val):

 ret =  i3g4250d_read_reg(ctx, I3G4250D_OUT_X_L, buff, 6);

I3G4250D datasheets DS10938 page 23:

In order to read multiple bytes, it is necessary to assert the most significant bit of the subaddress field. In other words, SUB(7) must be equal to 1, while SUB(6-0) represents the address of the first register to be read.

The start address of the read (subaddress ) must be I3G4250D_OUT_X_L | 0x80:

ret = i3g4250d_read_reg(ctx, I3G4250D_OUT_X_L | 0x80, buff, 6);

This works in my application.

Note: connection interface - I2C. For transmission used HAL function HAL_I2C_Mem_Write

albezanc commented 3 years ago

Hi albatron22, the bug is in the example files, please see the commit related to this issue. Thanks for your input, really appreciated !