天天看點

stm32氣壓傳感器 帶探頭的_BMP180氣壓傳感器的資料處理問題。STM32硬體IIC驅動

stm32氣壓傳感器 帶探頭的_BMP180氣壓傳感器的資料處理問題。STM32硬體IIC驅動

7de9f4d5fd982160b24068e052b44c84_785.png (0 Bytes, 下載下傳次數: 5)

2010-12-14 22:54 上傳

[mw_shl_code=c,true]//??????????

void BMP180_GetPressure(void)

{

u8 buffer[2];

double temp1,temp2,temp3;

//?ò?????????÷????0X34??????4.5ms,?????????????÷??AD??

//?ò?????????÷??????????????,?????±??????,???±??????????????????????????

// 0X34 4.5ms 16??????

// 0x74 7.5 17??????

// 0xb4 13.5 18??????

// 0xf4 25.5 19??????

BMP180_I2C1WriteByte(BMP180_REG_CTRL_MEAS,0X34);

delay_ms(5);

BMP180_I2C2ReadData(BMP180_REG_OUT_MSB,buffer,2);

delay_ms(5);

UP = buffer[0]<<8 | buffer[1];

B6 = B5-4000;

X1 = (B2*(B6*B6>>12))>>11;

X2 = AC2*B6>>11;

X3 = X1+X2;

B3 = ((AC1<<2)+X3+2)>>2;

X1 = AC3*B6>>13;

X2 = (B1*(B6*B6/4096))>>16;

X3 = ((X1+X2)+2)>>2;

B4 = AC4*(u32)(X3+32768)>>15;

B7 = ((u32)UP-B3)*50000;

if(B7<0X80000000)

P = (B7<<1)/B4;

else

P = (B7/B4)<<1;

X1 = (P<<8)*(P<<8);

X1 = (X1*3038)>>16;

X2 = (-7357*P)>>16;

P = P+(X1+X2+3791)/16;//????Pa ??????????????????????×???·¨?????????

Pressure = (float)(P)/1000; //??????KPa ?ó??????

temp1 = P*1.0/Standard_Pressure;

temp2 = (double)pow(temp1,0.2);

temp3 = (double)(1-temp2);

Altitude = 44330*(temp3);

printf("temp1=%f,temp2=%f,temp3=%f\r\n",temp1,temp2,temp3);

printf("UP=%d, P=%d, Pressure=%4.3fKPa Altitude=%4.3fm\r\n",UP,P,Pressure,Altitude);

}[/mw_shl_code]

調試結果如下:使用序列槽将資料輸出。

stm32氣壓傳感器 帶探頭的_BMP180氣壓傳感器的資料處理問題。STM32硬體IIC驅動

0f316a4af7724060bf629e2c7faea004_453.jpg (0 Bytes, 下載下傳次數: 4)

2010-12-14 22:54 上傳