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:

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


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()
    MS5837 small_sensor = MS5837(PC_1, PC_0, ms5837_addr_no_CS);
    float pressure_small;
    float temp_small;

    while (true) {
        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);


    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.