Skip to content

Commit e1c2f2c

Browse files
Loris Schmitcarlescufi
authored andcommitted
drivers: mpu9250: magnetometer data read fix
The magnetometer data read from AK9863 is assumed to be big endian (like the accelerometer & gyroscope data). However it is in little endian, which means the appropriate byteorder function is sys_le16_to_cpu(). See the MPU925 register map: https://3cfeqx1hf82y3xcoull08ihx-wpengine.netdna-ssl.com/wp-content/uploads/2017/11/RM-MPU-9250A-00-v1.6.pdf At 5.6 HXL to HZH: Measurement Data Signed-off-by: Loris Schmit <[email protected]>
1 parent 3f0e8dd commit e1c2f2c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/sensor/mpu9250/mpu9250.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ static int mpu9250_sample_fetch(const struct device *dev,
210210
drv_data->gyro_y = sys_be16_to_cpu(buf[5]);
211211
drv_data->gyro_z = sys_be16_to_cpu(buf[6]);
212212
#ifdef CONFIG_MPU9250_MAGN_EN
213-
drv_data->magn_x = sys_be16_to_cpu(buf[7]);
214-
drv_data->magn_y = sys_be16_to_cpu(buf[8]);
215-
drv_data->magn_z = sys_be16_to_cpu(buf[9]);
213+
drv_data->magn_x = sys_le16_to_cpu(buf[7]);
214+
drv_data->magn_y = sys_le16_to_cpu(buf[8]);
215+
drv_data->magn_z = sys_le16_to_cpu(buf[9]);
216216
drv_data->magn_st2 = ((uint8_t *)buf)[20];
217217
LOG_DBG("magn_st2: %u", drv_data->magn_st2);
218218
#endif

0 commit comments

Comments
 (0)