Fork of original LPS331 library Changed the I2C address to 0xBA

Committer:
yasuyuki
Date:
Sat Oct 04 12:02:25 2014 +0000
Revision:
0:ef4f624dc3ec
Child:
1:f70e671b008f
first release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yasuyuki 0:ef4f624dc3ec 1 //**********************
yasuyuki 0:ef4f624dc3ec 2 // LPS331.cpp for mbed
yasuyuki 0:ef4f624dc3ec 3 //
yasuyuki 0:ef4f624dc3ec 4 // LPS331 barometer(P0_5,P0_4);
yasuyuki 0:ef4f624dc3ec 5 // or
yasuyuki 0:ef4f624dc3ec 6 // I2C i2c(P0_5,P0_4);
yasuyuki 0:ef4f624dc3ec 7 // LPS331 barometer(i2c);
yasuyuki 0:ef4f624dc3ec 8 //
yasuyuki 0:ef4f624dc3ec 9 // (C)Copyright 2014 All rights reserved by Y.Onodera
yasuyuki 0:ef4f624dc3ec 10 // http://einstlab.web.fc2.com
yasuyuki 0:ef4f624dc3ec 11 //**********************
yasuyuki 0:ef4f624dc3ec 12
yasuyuki 0:ef4f624dc3ec 13 #include "mbed.h"
yasuyuki 0:ef4f624dc3ec 14 #include "LPS331.h"
yasuyuki 0:ef4f624dc3ec 15
yasuyuki 0:ef4f624dc3ec 16 LPS331::LPS331 (PinName sda, PinName scl) : _i2c(sda, scl) {
yasuyuki 0:ef4f624dc3ec 17 init();
yasuyuki 0:ef4f624dc3ec 18 }
yasuyuki 0:ef4f624dc3ec 19 LPS331::LPS331 (I2C& p_i2c) : _i2c(p_i2c) {
yasuyuki 0:ef4f624dc3ec 20 init();
yasuyuki 0:ef4f624dc3ec 21 }
yasuyuki 0:ef4f624dc3ec 22
yasuyuki 0:ef4f624dc3ec 23 void LPS331::put(unsigned char a, unsigned char b)
yasuyuki 0:ef4f624dc3ec 24 {
yasuyuki 0:ef4f624dc3ec 25 buf[0]=a;
yasuyuki 0:ef4f624dc3ec 26 buf[1]=b;
yasuyuki 0:ef4f624dc3ec 27 _i2c.write(LPS331_ADDR, buf, 2);
yasuyuki 0:ef4f624dc3ec 28 }
yasuyuki 0:ef4f624dc3ec 29
yasuyuki 0:ef4f624dc3ec 30
yasuyuki 0:ef4f624dc3ec 31 void LPS331::get(unsigned char a)
yasuyuki 0:ef4f624dc3ec 32 {
yasuyuki 0:ef4f624dc3ec 33 buf[0] = a;
yasuyuki 0:ef4f624dc3ec 34 _i2c.write(LPS331_ADDR, buf, 1, true); // no stop, repeated
yasuyuki 0:ef4f624dc3ec 35 _i2c.read( LPS331_ADDR, buf, 1);
yasuyuki 0:ef4f624dc3ec 36
yasuyuki 0:ef4f624dc3ec 37 }
yasuyuki 0:ef4f624dc3ec 38
yasuyuki 0:ef4f624dc3ec 39 long LPS331::value()
yasuyuki 0:ef4f624dc3ec 40 {
yasuyuki 0:ef4f624dc3ec 41
yasuyuki 0:ef4f624dc3ec 42 // get press_high
yasuyuki 0:ef4f624dc3ec 43 get(LPS331_PRESS_OUT_H);
yasuyuki 0:ef4f624dc3ec 44 //press=buf[0]*0x10000;
yasuyuki 0:ef4f624dc3ec 45 press.byte.UB=buf[0];
yasuyuki 0:ef4f624dc3ec 46 // get tpress_low
yasuyuki 0:ef4f624dc3ec 47 get(LPS331_PRESS_OUT_L);
yasuyuki 0:ef4f624dc3ec 48 //press+=buf[0]*0x100;
yasuyuki 0:ef4f624dc3ec 49 press.byte.HB=buf[0];
yasuyuki 0:ef4f624dc3ec 50 // get press_xl
yasuyuki 0:ef4f624dc3ec 51 get(LPS331_PRESS_POUT_XL_REH);
yasuyuki 0:ef4f624dc3ec 52 //press+=buf[0];
yasuyuki 0:ef4f624dc3ec 53 press.byte.LB=buf[0];
yasuyuki 0:ef4f624dc3ec 54 return press.Val;
yasuyuki 0:ef4f624dc3ec 55
yasuyuki 0:ef4f624dc3ec 56 }
yasuyuki 0:ef4f624dc3ec 57
yasuyuki 0:ef4f624dc3ec 58 void LPS331::init()
yasuyuki 0:ef4f624dc3ec 59 {
yasuyuki 0:ef4f624dc3ec 60 // Power ON Cycle=1Hz
yasuyuki 0:ef4f624dc3ec 61 put(LPS331_CTRL_REG1, 0x90);
yasuyuki 0:ef4f624dc3ec 62 }
yasuyuki 0:ef4f624dc3ec 63
yasuyuki 0:ef4f624dc3ec 64