Difference between smt32 black pill and blue pill reading i2c sensor gy-91

Hi, I do have the following issue: I am building an artificial horizon with a gy-91 gyroscope.

The code works fine on my stm32 blue pill, however there is a strange issue on the black pill:

I can upload the code and get the connection running. Also I am sure the wireing is correct because the pressure sensor on the gy-91 is read properly. However the gyro and the accerelometer just always return zeros. There is no error, just the sensor responds that there is no gravity or rotation.
I am using the following library: GitHub - bolderflight/invensense-imu: Arduino and CMake library for communicating with the InvenSense MPU-6500, MPU-9250 and MPU-9255 nine-axis IMUs.
Unfortunately I cannot swap the sensors to check for a hardware issue because the black pill is actually maintained by another person at another location. However I consider a hardware error unlikely because the same behavior occurs on both sensors.
Any ideas what’s going on?

So on the GY-91, which is a MPU-9250 (gyro + accel + compass, 3 D.O.F. each) plus a BMP280 (pressure) in parallel per schematics, just the BMP280 seems to be working.

Please do some basic checks first:

  • run the I2C scanner sketch to verify that you see both devices – since per schematic the AD0 pin of the chip is connected to GND, and per this, the MPU-9250 should be visible as the (7-bit) address 0x68 and the BMP280 as 0x76. If only one device appears, the HW is faulty and the investigation is done.
  • there is also this scanner code which directly looks for MPU type devices (needs library)
  • try another driver code the for the MPU-9250. It may be that the driver you’re using does not work for the faster STM32F4 series chips or has some programming error in them for that series. E.g., try the sketch MPU9250/simple.ino at master · hideakitai/MPU9250 · GitHub which comes from this library.

Ok this is really strange. At both locations we find I2C-Addresses of 0x68 and 0x76 using the i2c scanner. The scanner code looking for the mpu9250 type also returns that I have an MPU9250 connected, however when trying the demo sketch with the hikeakitai library it says “MPU connection failed. Please check your connection with connection_check example.”. Strangely the exact same sensor works perfectly on my blue pill using the bolderflightsystems lib (but only returns zeros on the blackpill using bolderflightsystems)…

This is strange – the second bullet point above is the connection_check.ino sketch. And the output of that sketch said I2C address 0x68 is MPU9250 and ready to use", on both blue- & blackpill?

Can you please use the last example again, but alter the code from

to

    void setup() {
        Serial.begin(115200);
        Wire.begin();
        delay(2000);
        mpu.verbose(true); //output more debug serial stuff
        if (!mpu.setup(0x68)) {  // change to your own address
            while (1) {
                Serial.println("MPU connection failed. Please check your connection with `connection_check` example.");
                delay(5000);
            }
        }
    }

that should hopefully give more information on the serial output.

MPU9250 WHO AM I = 71
I2C ERROR CODE : 3
AK8963 WHO AM I = 0
Could not connect to AK8963
MPU connection failed. Please check your connection with `connection_check` example.

This is the output of the altered sketch.

And yes, this was the exact output…

Hm I see. It’s doing

and

So i2c_err is the return code of wire->endTransmission() and per Wire - Arduino Reference a value of 3 means

  • 3:received NACK on transmit of data

So it seems that the AK8963 sub-device within the MPU-9250 is not responding.

If you run the modified sketch on the known-good bluepill device, what do you get?

The problem is that I ran it on the supposedly known-good blue pill. This was an attempt to try another library that also works on the black pill but does not even work on the blue pill which works with the bolderflightsystems library. Do you think it’s worth a try to test it on the black pill?

Interesting. The other library does the same type of checks

but definitely does different I2C writes – the hideakitai library directly reads the AK8963_WHOAMI register, the bolderflight library sets up a few internal I2C registers first, it seems…

In any case I think if you create an issue in Issues · hideakitai/MPU9250 · GitHub for the I2C ERROR CODE : 3 that is thrown on your GY-91 module, that we good, any maybe something can be fixed.

That doesn’t solve the problem on the F4 though, where none of the two libraries work…

I also see that GitHub - bolderflight/invensense-imu: Arduino and CMake library for communicating with the InvenSense MPU-6500, MPU-9250 and MPU-9255 nine-axis IMUs. is quite active with a commit 3 days ago. You should also try and open a github issue and see if you can get that library to work.