![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
main.cpp
- Committer:
- gbeardall
- Date:
- 2011-09-07
- Revision:
- 0:2fdc6095d7b4
- Child:
- 1:d01abb5e6f52
File content as of revision 0:2fdc6095d7b4:
#include "mbed.h" DigitalOut myled(LED1); // http://sensing.honeywell.com/index.cfm/ci_id/157750/la_id/1/document/1/re_id/0 // http://sensing.honeywell.com/index.cfm/ci_id/156988/la_id/1/document/1/re_id/0 #define HSC_2A 0x28 int main() { // BMP085 bmp085(p28, p27); //bmp085(p9, p10); // sda, scl printf("\rhsc\n\r"); I2C i2c(p28, p27); int id = HSC_2A; i2c.frequency(100000); // 100k - 400k while(1) { #if 0 i2c.start(); i2c.write((id<<1) | 1); int b1 = i2c.read(1); int b2 = i2c.read(1); int t1 = i2c.read(1); int t2 = i2c.read(0); i2c.stop(); printf("%02X %02X %02X %02X\n\r", b1, b2, t1, t2); #else unsigned char data[4]; i2c.read((id<<1)|1, (char*)data, sizeof(data)); //printf("%02X %02X %02X %02X\n\r", data[0], data[1], data[2], data[3]); int st = data[0]>>6; // status int bd = ((data[0] & 0x3f) << 8) | data[1]; // bridge data int td = ((data[2]<<8) | data[3]) >> 5; // temp data float p = ((float)bd-1638)*(15-0)/(14745-1638)-0; // convert to psi p = p * 68.9475729; // psi to hPa float t = (((float)td*200)/2047)-50; // convert to deg C printf("%d: %.2f hPa %.2f C\n\r", st, p, t); wait(1); #endif myled = 1; wait(0.2); myled = 0; wait(0.2); } // while } // main