Who woulda thunk it… While developing a driver for the BMP085 barometric pressure sensor, I found a bug in Visual Studio 2010.
I was getting some pretty wild readings from my sensor, it thought I was 3500m above sea level and last time I checked Albury/Wodonga in Australia is only 165m above sea level. I started getting a little excited, ran outside to play in the snow but unfortunately it was like every other day below the snow line.
I started doing some checking, I passed the sensor values from the sensor’s datasheet into my conversion routines and everything meshed nicely, only the occasional LSB error which went away due to rounding later in the conversion and I got all the right numbers back out the other end.
I was a little puzzled by this time so I started stepping through my code to communicate with the sensor checking the returned data, making sure it was being converted from a byte array into the Int16/32/64 values needed elsewhere. No problem there.
Even more puzzled I checked the code that reads the calibration from the sensor, and puts it into memory for use in the conversion routines. Every chip has its own calibration.
It was here I started seeing something odd.
Where this code…
AC1 = (Int16)(rawData << 8 + rawData); AC2 = (Int16)(rawData << 8 + rawData); AC3 = (Int16)(rawData << 8 + rawData); AC4 = (UInt16)(rawData << 8 + rawData); AC5 = (UInt16)(rawData << 8 + rawData); AC6 = (UInt16)(rawData << 8 + rawData); B1 = (Int16)(rawData << 8 + rawData); MB = (Int16)(rawData << 8 + rawData); MC = (Int16)(rawData << 8 + rawData); MD = (Int16)(rawData << 8 + rawData);
Should have given me these results…
A1 = 0x2825; A2 = 0xfb70; A3 = 0xc82e; A4 = 0x864e; A5 = 0x61ef; A6 = 0x6405; B1 = 0x157a; B2 = 0x003e; MB = 0x8000; MC = 0xd4bd; MD = 0x0980;
I was getting this…
A1 = 0x2825; A2 = 0xfffffb70; A3 = 0xffffc82e; A4 = 0x864e; A5 = 0x61ef; A6 = 0x6405; B1 = 0x157a; B2 = 0x003e; MB = 0xffff8000; MC = 0xffffd4bd; MD = 0x0980;
I tried hard coding my sensor values as constants but Visual Studio complained about the values for A2, A3, MB and MC not being Int32. And every time I try to work with the values, it thinks they are Int32.
Using the same blocks of code, trying projects for Windows and .NET also gives me the same issue.
I submitted the problem to Microsoft and now It’s wait and see.