MS5837 Pressure Sensor Error

I am trying to use a MS5837-30BA Pressure sensor with a STM32L476RG Nucleo board. I am checking whether the sensor is ok by connecting it to an Arduino and coding via the following library: https://github.com/bluerobotics/BlueRobotics_MS5837_Library

The sensor works and provides accurate readings with the Arduino. However, when I try to use the Mbed MS5837 libraries, namely:

  1. robfish_pressuresensors_encoderQEI - Test for MS5803 and MS5837 pressure sensors (pres… | Mbed
  2. MS5837 - . | Mbed
  3. AUV_MS5837_30BA_WRCE_TSD - Updated MS5837 Library to add support for the MS5… | Mbed

I get wrong readings. Every library just spits out 0 for pressure and 20 for temperature. My pin connections on the Nucleo are same as Arduino: VCC: 3.3V, GND: GND, SDA: A4/PC_1, SCL: A5/PC_0.

Sample code:

#include "mbed.h"
#include "platform/mbed_thread.h"
#include "MS5837.h"
using namespace std;

Serial pc(USBTX, USBRX);


int main()
{
    pc.baud(9600);
    MS5837 small_sensor = MS5837(PC_1, PC_0, ms5837_addr_no_CS);
    small_sensor.MS5837Init();
    float pressure_small;
    float temp_small;

    while (true) {
        small_sensor.Barometer_MS5837();
        pressure_small = small_sensor.MS5837_Pressure();
        temp_small = small_sensor.MS5837_Temperature();
        pc.printf("Small Sensor Pressure: %f\n", pressure_small);
        pc.printf("Small Sensor Temperature: %f\n\n", temp_small);
    }
}

Any idea what’s happening?

I feel like to really debug this you would need to use a logic analyzer or oscilloscope to monitor the communication with the sensor – is it receiving I2C commands? Is it responding?

Also, looking at those drivers (all of them??), I think I noticed a bug with how they handle i2c addresses. Try changing

    MS5837 small_sensor = MS5837(PC_1, PC_0, ms5837_addr_no_CS);

to

    MS5837 small_sensor = MS5837(PC_1, PC_0, ms5837_addr_no_CS >> 1);
1 Like

Hi thanks. Actually after you said I noticed the I2C lines were pulled really low on STM32 Nucleo as it had no internal pullup. So I added pullup resistors on SDA and SCL and now it works.