5 years, 2 months ago.

Nucleo STM32L053 with I2C Pressure Sensor 89BSD-006BA-A

I'm trying to read the calibration coefficients off a pressure sensor via I2C: The sensor is the 89BSD-006BA-A: https://www.digikey.com/product-detail/en/te-connectivity-measurement-specialties/89BSD-006BA-A/223-1506-5-ND/5277619

I'm using the Nucleo board STM32L053 for temperature and pressure measurements. After reading off the registers and storing in the array C[], this code snippet is meant to extract the 14-bit C0 and C1 and 10-bit C3-C6 and A0-A2. Can someone help to explain how this is done? /media/uploads/andycph/memory2.jpg

//Calculate the coefficients from the PROM array 
void Get_Coefficients(unsigned int16 array[])
{ 

C0 = (array[1] & 0xFFFC) >> 2; 
C0 = FourteenBitConversion(C0); 
C1 = ((array[1] & 0x03) << 12) + ((array[2] & 0xFFF0) >> 4); 
C1 = FourteenBitConversion(C1); 
C2 = (((array[2] & 0xF) << 6) + (array[3] >> 10)) & 0x3FF; 
C2 = TenBitConvertion(C2); 
C3 = array[3] & 0x3FF; 
C3 = TenBitConvertion(C3); 
C4 = (array[4] >> 6) & 0x3FF; 
C4 = TenBitConvertion(C4); 
C5 =  (((array[4] & 0x3F) << 4) + (array[5] >> 12)) & 0x3FF; 
C5 = TenBitConvertion(C5); 
C6 = (array[5] >> 2) & 0x3FF; 
C6 = TenBitConvertion(C6); 
SENA0 = (((array[5] & 0x3) << 8) + (array[6] >> 8)) & 0x3FF; 
SENA0 = TenBitConvertion(SENA0); 
SENA1 = (((array[6] & 0xFF) << 2) + (array[7] >> 14)) & 0x3FF; 
SENA1 = TenBitConvertion(SENA1); 
SENA2 = (array[7] >> 4) & 0x3FF; 
SENA2 = TenBitConvertion(SENA2); 

}

1 Answer

5 years, 2 months ago.

The coefficients are packed into an array of 16bit values. Meaning that some coefficients may fit into one 16 bit array entry and just need to be shifted some bits left or right, while other coefficients may be split across two sequential array entries. The mapping of the coefficients is as shown in the table. So to get C0 you take array[1], mask out the proper 14 bits using 0xFFFC, and then shift out the 2 rightmost bits that are actually part of C1. However, that still needs to consider the fact that the coefficients are represented as 2s-complement. You need to fix the coefficients for negative values. That will be the job of the FourteenBitConversion() function. Similar approach for the other coefficients.

Accepted Answer

Thanks!

posted by Andy C. 29 Jan 2019