Code:
char bmp180_get_cal_param(bmp180_calc_t *cal)
{
char ret = 1;
ret &= bmp180_readInt(0xAA, &(cal->AC1));
ret &= bmp180_readInt(0xAC, &(cal->AC2));
ret &= bmp180_readInt(0xAE, &(cal->AC3));
ret &= bmp180_readUInt(0xB0, &(cal->AC4));
ret &= bmp180_readUInt(0xB2, &(cal->AC5));
ret &= bmp180_readUInt(0xB4, &(cal->AC6));
ret &= bmp180_readInt(0xB6, &(cal->B1));
ret &= bmp180_readInt(0xB8, &(cal->B2));
ret &= bmp180_readInt(0xBA, &(cal->MB));
ret &= bmp180_readInt(0xBC, &(cal->MC));
ret &= bmp180_readInt(0xBE, &(cal->MD));
return ret;
}
char bmp180_online(char *id)
{
return bmp180_readByte(0xD0, id);
}
char bmp180_get_temp(bmp180_calc_t cal, long *temperatur)
{
char ret = 1;
int t;
long UT, X1, X2, B5, T;
long AC5, AC6, MC, MD;
AC5 = cal.AC5;
AC6 = cal.AC6;
MC = cal.MC;
MD = cal.MD;
ret &= bmp180_start_temp(&t);
UT = (unsigned int)t;
X1 = (((UT - AC6) * AC5)>>15);
X2 = (MC<<11) / (X1 + MD);
B5 = X1 + X2;
T = ((B5 + 8L)>>4);
*temperatur = T;
return ret;
}
char bmp180_get_druck(bmp180_calc_t cal, long *druck, unsigned char oss, long *temperatur, int *temp, long *press)
{
char ret = 1;
long p;
int t;
long UT, X1, X2, X3, B3, B5, B6, T;
long AC1, AC2, AC3, AC4, AC5, AC6, MB, MC, MD, B1, B2;
unsigned long B4, B7, UP;
AC1 = cal.AC1;
AC2 = cal.AC2;
AC3 = cal.AC3;
AC4 = cal.AC4;
AC5 = cal.AC5;
AC6 = cal.AC6;
MB = cal.MB;
MC = cal.MC;
MD = cal.MD;
B1 = cal.B1;
B2 = cal.B2;
ret &= bmp180_start_temp(&t);
UT = (long)t;
*temp = t;
ret &= bmp180_start_druck(&p, oss);
UP = (long)p;
*press = p;
X1 = (((UT - AC6) * AC5)>>15);
X2 = (MC<<11) / (X1 + MD);
B5 = X1 + X2;
T = ((B5 + 8L)>>4);
*temperatur = T;
B6 = B5 - 4000;
X1 = (B2 * ((B6 * B6) >> 12)) >> 11;
X2 = (AC2 * B6) >> 11;
X3 = X1 + X2;
B3 = (((AC1 * 4 + X3) << oss) + 2) >> 2;
X1 = (AC3 * B6) >> 13;
X2 = (B1 * ((B6 * B6) >> 12)) >> 16;
X3 = ((X1 + X2) + 2) >> 2;
B4 = (AC4 * (unsigned long)(X3 + 32768)) >> 15;
B7 = ((unsigned long)(UP - B3)) * (50000 >> oss);
if (B7 < 0x80000000)
p = (B7 * 2) / B4;
else
p = (B7 / B4) * 2;
X1 = (p >> 8) * (p >> 8);
X1 = (X1 * 3038) >> 16;
X2 = (-7357 * p) >> 16;
*druck= p + ((X1 + X2 + 3791) >> 4);
return ret;
}
char bmp180_start_messung(char address, char command, char statusbit)
{
char status = command;
unsigned int timeout = 65535;
if (bmp180_writeByte(address, command))
{
while((status & statusbit) && (timeout-- > 0))
{
if (!bmp180_readByte(address, &status)) return 0;
}
return 1;
}
return 0;
}
char bmp180_start_temp(int *value)
{
int hi;
if (bmp180_start_messung(0xF4, 0x2E, 0x00 | (1<<BMP180_SCO)))
{
bmp180_readInt(0xF6, &hi);
*value = (int)hi;
return 1;
}
return 0;
}
char bmp180_start_druck(long *value, unsigned char oss)
{
char hi, lo;
char xlsb;
if (bmp180_start_messung(0xF4, 0x34 + (oss<<6), 0x00 | (1<<BMP180_SCO)))
{
bmp180_readByte(0xF6, &hi);
bmp180_readByte(0xF7, &lo);
bmp180_readByte(0xF8, &xlsb);
*value = (long)((((long)hi)<<16) | (((long)lo)<<8) | ((long)xlsb)) >> (8-oss);
return 1;
}
return 0;
}
Habe da bisher noch keinen Fehler festgestellt.
Lesezeichen