MS4525 Pressure Sensor Temperature reading

I've been utilizing an MS4525 pressure sensor over I2C and had a lot of problems reading the 11 bit Temperature contained in the last 2 bytes of a 4 byte read. It seemingly worked, but would become erratic at certain temps. I finally discovered it was due to all the other code examples on here not masking some of the bits. Here's the solution if anyone is interested:
Temp_H is the High byte and Temp_L is the low byte.

Temp_H << 3 | Temp_L & 0xE0 >> 5
1 Like

Thanks for letting us know. It would be nice if you posted a small program showing exactly how you use this.

When Googling for "MS4525" I see the datasheet of a ratiometric analogue pressure sensor. So where does I2C fit in.
Leo..

You posted only the first part of the sensor's part number, post the whole part number from the datasheet, page 14.
https://www.mouser.com/datasheet/2/418/MS4525DO-710170.pdf.

You might want to look here.

@gilshultz - I was succint because I was merely correcting what was already posted in other places I don't want people having to dig through my code to find a solution since it is already posted, albeit with the missing bit mask on the Temp. I write in micropython and have adapted the code to my case. The only two code bases I found online regarding this sensor was an .ino sketch which I ported over but the temp was erratic. I then came across the following c++ repository here: bolderflight repository which mentioned the bit mask. I never wrote an Arduino script with the mask so I have nothing to post really. Just hoping this find can help others.
Wawa - There are many versions of this sensor. The datasheet for the version I am using is HERE It is the I2C version.
JCA34F - I purposely only put the main part of the part number to keep things simple. I've now added the exact datasheet for the part I'm using. Hopefully people find all of these resources helpful.
@JohnRob - I did look there. Those posts are ALL missing the & 0xE0 bit mask which prevents the erratic behavior I was encountering. Hence why I'm posting this. Those discussions are closed already otherwise I would have replied to them with the solution.

If you edit the "MS4525" in title of your thread to "MS4525DO", then Ai might be able to find it in the future.
Leo..