![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
main.cpp@0:2fdc6095d7b4, 2011-09-07 (annotated)
- Committer:
- gbeardall
- Date:
- Wed Sep 07 07:27:01 2011 +0000
- Revision:
- 0:2fdc6095d7b4
- Child:
- 1:d01abb5e6f52
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gbeardall | 0:2fdc6095d7b4 | 1 | #include "mbed.h" |
gbeardall | 0:2fdc6095d7b4 | 2 | |
gbeardall | 0:2fdc6095d7b4 | 3 | DigitalOut myled(LED1); |
gbeardall | 0:2fdc6095d7b4 | 4 | |
gbeardall | 0:2fdc6095d7b4 | 5 | // http://sensing.honeywell.com/index.cfm/ci_id/157750/la_id/1/document/1/re_id/0 |
gbeardall | 0:2fdc6095d7b4 | 6 | // http://sensing.honeywell.com/index.cfm/ci_id/156988/la_id/1/document/1/re_id/0 |
gbeardall | 0:2fdc6095d7b4 | 7 | |
gbeardall | 0:2fdc6095d7b4 | 8 | #define HSC_2A 0x28 |
gbeardall | 0:2fdc6095d7b4 | 9 | |
gbeardall | 0:2fdc6095d7b4 | 10 | int main() { |
gbeardall | 0:2fdc6095d7b4 | 11 | |
gbeardall | 0:2fdc6095d7b4 | 12 | // BMP085 bmp085(p28, p27); //bmp085(p9, p10); // sda, scl |
gbeardall | 0:2fdc6095d7b4 | 13 | |
gbeardall | 0:2fdc6095d7b4 | 14 | printf("\rhsc\n\r"); |
gbeardall | 0:2fdc6095d7b4 | 15 | |
gbeardall | 0:2fdc6095d7b4 | 16 | I2C i2c(p28, p27); |
gbeardall | 0:2fdc6095d7b4 | 17 | |
gbeardall | 0:2fdc6095d7b4 | 18 | int id = HSC_2A; |
gbeardall | 0:2fdc6095d7b4 | 19 | |
gbeardall | 0:2fdc6095d7b4 | 20 | i2c.frequency(100000); // 100k - 400k |
gbeardall | 0:2fdc6095d7b4 | 21 | |
gbeardall | 0:2fdc6095d7b4 | 22 | while(1) { |
gbeardall | 0:2fdc6095d7b4 | 23 | |
gbeardall | 0:2fdc6095d7b4 | 24 | #if 0 |
gbeardall | 0:2fdc6095d7b4 | 25 | i2c.start(); |
gbeardall | 0:2fdc6095d7b4 | 26 | i2c.write((id<<1) | 1); |
gbeardall | 0:2fdc6095d7b4 | 27 | int b1 = i2c.read(1); |
gbeardall | 0:2fdc6095d7b4 | 28 | int b2 = i2c.read(1); |
gbeardall | 0:2fdc6095d7b4 | 29 | int t1 = i2c.read(1); |
gbeardall | 0:2fdc6095d7b4 | 30 | int t2 = i2c.read(0); |
gbeardall | 0:2fdc6095d7b4 | 31 | i2c.stop(); |
gbeardall | 0:2fdc6095d7b4 | 32 | printf("%02X %02X %02X %02X\n\r", b1, b2, t1, t2); |
gbeardall | 0:2fdc6095d7b4 | 33 | #else |
gbeardall | 0:2fdc6095d7b4 | 34 | unsigned char data[4]; |
gbeardall | 0:2fdc6095d7b4 | 35 | i2c.read((id<<1)|1, (char*)data, sizeof(data)); |
gbeardall | 0:2fdc6095d7b4 | 36 | //printf("%02X %02X %02X %02X\n\r", data[0], data[1], data[2], data[3]); |
gbeardall | 0:2fdc6095d7b4 | 37 | int st = data[0]>>6; // status |
gbeardall | 0:2fdc6095d7b4 | 38 | int bd = ((data[0] & 0x3f) << 8) | data[1]; // bridge data |
gbeardall | 0:2fdc6095d7b4 | 39 | int td = ((data[2]<<8) | data[3]) >> 5; // temp data |
gbeardall | 0:2fdc6095d7b4 | 40 | |
gbeardall | 0:2fdc6095d7b4 | 41 | float p = ((float)bd-1638)*(15-0)/(14745-1638)-0; // convert to psi |
gbeardall | 0:2fdc6095d7b4 | 42 | p = p * 68.9475729; // psi to hPa |
gbeardall | 0:2fdc6095d7b4 | 43 | |
gbeardall | 0:2fdc6095d7b4 | 44 | float t = (((float)td*200)/2047)-50; // convert to deg C |
gbeardall | 0:2fdc6095d7b4 | 45 | printf("%d: %.2f hPa %.2f C\n\r", st, p, t); |
gbeardall | 0:2fdc6095d7b4 | 46 | |
gbeardall | 0:2fdc6095d7b4 | 47 | wait(1); |
gbeardall | 0:2fdc6095d7b4 | 48 | #endif |
gbeardall | 0:2fdc6095d7b4 | 49 | |
gbeardall | 0:2fdc6095d7b4 | 50 | myled = 1; |
gbeardall | 0:2fdc6095d7b4 | 51 | wait(0.2); |
gbeardall | 0:2fdc6095d7b4 | 52 | myled = 0; |
gbeardall | 0:2fdc6095d7b4 | 53 | wait(0.2); |
gbeardall | 0:2fdc6095d7b4 | 54 | |
gbeardall | 0:2fdc6095d7b4 | 55 | } // while |
gbeardall | 0:2fdc6095d7b4 | 56 | |
gbeardall | 0:2fdc6095d7b4 | 57 | } // main |