Demo

Dependencies:   mbed

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

Who changed what in which revision?

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