Demo

Dependencies:   mbed

Committer:
nightseas
Date:
Thu May 19 15:52:24 2016 +0000
Revision:
2:0ee90da44162
AirBoxProtoDemo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nightseas 2:0ee90da44162 1 #include "SysConfig.h"
nightseas 2:0ee90da44162 2
nightseas 2:0ee90da44162 3 #define BMP180_ADDR (0x40<<1) //BMP180 address
nightseas 2:0ee90da44162 4 #define BMP180_CMD_TMP_NH (0xF3) //Non-hold temp trigger command
nightseas 2:0ee90da44162 5 #define BMP180_CMD_RH_NH (0xF5) //Non-hold temp trigger command
nightseas 2:0ee90da44162 6
nightseas 2:0ee90da44162 7 #define i2c_bmp180 i2c_sen
nightseas 2:0ee90da44162 8 //#define uart_db uart_pc
nightseas 2:0ee90da44162 9
nightseas 2:0ee90da44162 10 int BMP180_Init(void)
nightseas 2:0ee90da44162 11 {
nightseas 2:0ee90da44162 12 return 0;
nightseas 2:0ee90da44162 13 }
nightseas 2:0ee90da44162 14
nightseas 2:0ee90da44162 15 float BMP180_ReadTemp(void)
nightseas 2:0ee90da44162 16 {
nightseas 2:0ee90da44162 17 char cmd = BMP180_CMD_TMP_NH, data[3];
nightseas 2:0ee90da44162 18 float temp;
nightseas 2:0ee90da44162 19
nightseas 2:0ee90da44162 20 i2c_bmp180.write(BMP180_ADDR, &cmd, 1, 1);
nightseas 2:0ee90da44162 21 wait_us(20);
nightseas 2:0ee90da44162 22 i2c_bmp180.stop();
nightseas 2:0ee90da44162 23
nightseas 2:0ee90da44162 24 wait_ms(100);
nightseas 2:0ee90da44162 25 i2c_bmp180.read(BMP180_ADDR, data, 3);
nightseas 2:0ee90da44162 26 #if defined uart_db
nightseas 2:0ee90da44162 27 uart_db.printf("\n\rBMP180 return 0x%02X 0x%02X 0x%02X\n\r", data[0], data[1], data[2]);
nightseas 2:0ee90da44162 28 #endif
nightseas 2:0ee90da44162 29 temp = (256.0 * data[0] + data[1]) * 175.72 / (0x1 << 16) - 46.85;
nightseas 2:0ee90da44162 30 return temp;
nightseas 2:0ee90da44162 31 }
nightseas 2:0ee90da44162 32
nightseas 2:0ee90da44162 33 float BMP180_ReadRh(void)
nightseas 2:0ee90da44162 34 {
nightseas 2:0ee90da44162 35 char cmd = BMP180_CMD_RH_NH, data[3];
nightseas 2:0ee90da44162 36 float rh;
nightseas 2:0ee90da44162 37
nightseas 2:0ee90da44162 38 i2c_bmp180.write(BMP180_ADDR, &cmd, 1, 1);
nightseas 2:0ee90da44162 39 wait_us(20);
nightseas 2:0ee90da44162 40 i2c_bmp180.stop();
nightseas 2:0ee90da44162 41
nightseas 2:0ee90da44162 42 wait_ms(100);
nightseas 2:0ee90da44162 43 i2c_bmp180.read(BMP180_ADDR, data, 3);
nightseas 2:0ee90da44162 44 #if defined uart_db
nightseas 2:0ee90da44162 45 uart_db.printf("\n\rBMP180 return 0x%02X 0x%02X 0x%02X\n\r", data[0], data[1], data[2]);
nightseas 2:0ee90da44162 46 #endif
nightseas 2:0ee90da44162 47 rh = (256.0 * data[0] + data[1]) * 125 / (0x1 << 16) - 6;
nightseas 2:0ee90da44162 48 return rh;
nightseas 2:0ee90da44162 49 }