Mbed os 6.15 MPU9250 SPI

I am new to mbed-os. I am trying to upgrade from mbed-os 5 to mbed-os 6.15 on NUCLEO-STM32F767ZI. I am using MPU 9250 with the library https://os.mbed.com/users/kylongmu/code/MPU9250_SPI//file/084e8ba240c1/MPU9250.cpp/ .
I have changed all the wait function to wait_us() from wait(0.001)and ThisThread::sleep_for() for wait(1) or wait(0.1).

But the imu could not work properly when position changed.

#include “mbed.h”
#include “MPU9250.h” //Include library
#include “swo.h”

DigitalOut myled(PB_11, 1);
SPI spi(PA_7, PA_6, PA_5);
mpu9250_spi imu(spi,PC_4); //define the mpu9250 object
SWO_Channel swo(“channel”);
int main(){
if(imu.init(1,BITS_DLPF_CFG_188HZ)){ //INIT the mpu9250
swo.printf(“\nCouldn’t initialize MPU9250 via SPI!”);
}
swo.printf(“\nWHOAMI=0x%2x\n”,imu.whoami()); //output the I2C address to know if SPI is working, it should be 104
ThisThread::sleep_for(1000);
swo.printf(“Gyro_scale=%u\n”,imu.set_gyro_scale(BITS_FS_2000DPS)); //Set full scale range for gyros
ThisThread::sleep_for(1000);
swo.printf(“Acc_scale=%u\n”,imu.set_acc_scale(BITS_FS_16G)); //Set full scale range for accs
ThisThread::sleep_for(1000);
swo.printf(“AK8963 WHIAM=0x%2x\n”,imu.AK8963_whoami());
ThisThread::sleep_for(100);
imu.AK8963_calib_Magnetometer();
while(1) {
myled = 1;
ThisThread::sleep_for(100);
/*
imu.read_temp();
imu.read_acc();
imu.read_rot();
imu.AK8963_read_Magnetometer();
*/
imu.read_temp();
imu.read_acc();
imu.read_rot();
imu.AK8963_read_Magnetometer();
imu.read_all();
swo.printf(“%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f\n”,
imu.Temperature,
imu.gyroscope_data[0],
imu.gyroscope_data[1],
imu.gyroscope_data[2],
imu.accelerometer_data[0],
imu.accelerometer_data[1],
imu.accelerometer_data[2],
imu.Magnetometer[0],
imu.Magnetometer[1],
imu.Magnetometer[2]
);
myled = 0;
ThisThread::sleep_for(500);
}
}

The Serial Wire Viewer result: (no change when imu get moved)
WHOAMI=0x 0
Gyro_scale=2000
Acc_scale=16
AK8963 WHIAM=0x81
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000
20.937, 0.000, 0.000, 0.000, -15.096, 0.000, 0.000, 0.000, 0.000, 0.000

Hello,

please be so kind, edit your post and place the code between these 3 symbols ``` before and after your code

```
//your code here
```

Just for sure recheck your calculations in delays what you changed.
Did you try original example code with Mbed 2 or Mbed OS5 for result comparison? - MPU9250_SPI_Test - Test for MPU9250_SPI | Mbed

BR, Jan

You are right, the error does not come from the mbed os version.
I tried this library on mbed-os 5 and the result is the same.

I have one piece at home, I think. So will try it today later or during weekend.

BR, Jan

Hello,

ok, it is probably because you use SPI1 (PA_7, PA_6, PA_5) especially the pin PA_7 is the problem. According to Nucleo’s page and also PeripheralPins.c it is connected to the ethernet interface. So it can not be used without some change of onboard SB configuration according to user manual

How you will change the SPI interface then it will be working.

//for example
SPI spi(PE_6, PE_5, PE_2);
mpu9250_spi imu(spi,PE_4);

Result:

WHOAMI=0x71
Gyro_scale=2000
Acc_scale=16
AK8963 WHIAM=0x48
    30.600,     2.195,     0.793,    27.195,    -0.092,    -0.019,    -1.014, -3909.384,    27.311,   -46.922
    30.540,    -0.610,     0.488,    -0.061,    -0.096,     0.011,    -1.021,    53.238,    22.816,   -46.922
    30.465,    -1.037,    -0.183,    -1.646,    -0.103,     0.010,    -1.021,    54.275,    23.854,   -46.587
    30.375,    -0.793,     0.671,     0.610,    -0.097,     0.009,    -1.035,    54.621,    25.236,   -47.257
    30.396,   151.524,    45.122,   -47.561,    -0.067,    -0.162,    -1.001,    55.312,    23.854,   -45.916
    30.330,   -99.329,   299.878,  -200.610,     0.886,    -0.218,    -0.702,    64.301,   -13.137,   -31.505
    30.306,    27.012,   -80.122,    75.183,     0.677,     0.275,    -0.113,    64.301,   -13.137,   -31.505
    30.264,    65.366,  -162.195,    45.244,     0.166,    -0.118,    -1.112,    57.732,    -1.037,   -44.911
    30.231,   -54.634,   285.061,     2.805,     0.050,     0.271,    -1.088,    48.053,    13.137,   -48.598
    30.276,    35.488,    44.695,    -7.927,     0.673,     0.480,    -0.200,    39.237,   -20.569,   -35.359
    30.228,   211.890,  -205.610,    53.902,     0.399,    -0.269,    -2.036,    49.090,   -11.408,   -42.230
    30.192,   -42.683,   405.915,  -209.573,     0.983,     0.112,    -0.363,    48.226,   -22.989,   -27.315
    30.219,   105.305,  -390.671,   207.622,     0.380,     0.031,    -0.570,    38.892,   -29.212,   -15.250
    30.159,     2.378,   410.732,  -225.976,     0.689,    -0.332,    -1.049,    64.992,    11.754,   -41.895
    30.132,   -50.366,  -360.976,    87.561,     0.761,     0.280,    -0.687,    44.769,   -18.495,   -36.364
    30.174,    85.793,  -261.341,    99.878,    -0.396,    -0.061,    -0.740,    50.991,    12.964,   -48.765
    30.183,    -0.488,     1.098,    -0.549,    -0.086,     0.005,    -1.011,    54.275,    24.199,   -46.922
    30.195,    -0.976,     0.671,    -0.366,    -0.082,     0.002,    -1.028,    55.140,    23.681,   -46.419
    30.150,    -0.732,     1.037,    -0.244,    -0.082,     0.007,    -1.034,    53.411,    21.952,   -46.754
    30.147,    -0.793,     0.915,    -0.122,    -0.086,     0.001,    -1.030,    54.448,    23.335,   -48.430
    30.144,    -0.732,     0.793,    -0.183,    -0.079,     0.003,    -1.028,    54.621,    23.508,   -48.263
    30.105,    -0.732,     0.915,    -0.305,    -0.078,     0.010,    -1.039,    53.238,    22.471,   -46.922
    30.084,    -0.732,     0.915,    -0.183,    -0.083,     0.003,    -1.022,    54.794,    24.026,   -47.425
    30.117,    -0.976,     0.854,    -0.488,    -0.092,     0.002,    -1.037,    55.312,    23.508,   -47.257
    30.075,    -0.793,     0.854,    -0.366,    -0.089,     0.007,    -1.032,    54.275,    23.854,   -47.927
  • Win 10 with Edge browser
  • KeilStudio 1.5.47
  • MbedOS 6.16
  • Nucleo-F767ZI with Mpu 9250/6500

BR, Jan

It turns out the board I used has a broken IMU. It took me several days to find a working PCB board. Everything is low in stock due to the supply chain. After I changed the board, everything works well. Even with my old port(PA_7, PA_6, PA_5, PC_4).

Thank you so much.
You help me a lot.

Best, Ailin