Hello world for bm1383glv on mbed classic. Sets up treshold interrupts and makes measurements. Depends on rohm-sensor-hal and rohm-bm1383-glv.

Dependencies:   mbed rohm-bm1383-glv rohm-sensor-hal

Hello world for mbed classic + Rohm BM1383 glv barometer sensor.

Committer:
MikkoZ
Date:
Tue Apr 12 12:56:38 2016 +0000
Revision:
0:9fb407c1232e
Child:
1:6f7979f79aa4
Hello world for bm1383 in mbed classic; ; First version of hello world with bm1383 barometer sensor.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikkoZ 0:9fb407c1232e 1 /* Copyright 2016 Rohm Semiconductor
MikkoZ 0:9fb407c1232e 2
MikkoZ 0:9fb407c1232e 3 Licensed under the Apache License, Version 2.0 (the "License");
MikkoZ 0:9fb407c1232e 4 you may not use this file except in compliance with the License.
MikkoZ 0:9fb407c1232e 5 You may obtain a copy of the License at
MikkoZ 0:9fb407c1232e 6
MikkoZ 0:9fb407c1232e 7 http://www.apache.org/licenses/LICENSE-2.0
MikkoZ 0:9fb407c1232e 8
MikkoZ 0:9fb407c1232e 9 Unless required by applicable law or agreed to in writing, software
MikkoZ 0:9fb407c1232e 10 distributed under the License is distributed on an "AS IS" BASIS,
MikkoZ 0:9fb407c1232e 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MikkoZ 0:9fb407c1232e 12 See the License for the specific language governing permissions and
MikkoZ 0:9fb407c1232e 13 limitations under the License.
MikkoZ 0:9fb407c1232e 14 */
MikkoZ 0:9fb407c1232e 15
MikkoZ 0:9fb407c1232e 16 #include "rohm-sensor-hal/rohm-sensor-hal/rohm_hal.h" //mbed.h, types, DEBUG_print*
MikkoZ 0:9fb407c1232e 17 #include "rohm-sensor-hal/rohm-sensor-hal/I2CCommon.h"
MikkoZ 0:9fb407c1232e 18
MikkoZ 0:9fb407c1232e 19 #include "rohm-bm1383-glv/rohm-bm1383-glv/bm1383_driver.h"
MikkoZ 0:9fb407c1232e 20 #include "rohm-bm1383-glv/rohm-bm1383-glv/bm1383glv.h"
MikkoZ 0:9fb407c1232e 21
MikkoZ 0:9fb407c1232e 22 Serial pc(USBTX, USBRX);
MikkoZ 0:9fb407c1232e 23
MikkoZ 0:9fb407c1232e 24
MikkoZ 0:9fb407c1232e 25 void printTreshodRegStatus(){
MikkoZ 0:9fb407c1232e 26 if(bm1383_is_treshold_high_crossed()){
MikkoZ 0:9fb407c1232e 27 pc.printf("TresHighReg INT");
MikkoZ 0:9fb407c1232e 28 }
MikkoZ 0:9fb407c1232e 29 else{
MikkoZ 0:9fb407c1232e 30 pc.printf("TresHighReg NO INT");
MikkoZ 0:9fb407c1232e 31 }
MikkoZ 0:9fb407c1232e 32 pc.printf("\r\n");
MikkoZ 0:9fb407c1232e 33 if(bm1383_is_treshold_low_crossed()){
MikkoZ 0:9fb407c1232e 34 pc.printf("TresLowReg INT");
MikkoZ 0:9fb407c1232e 35 }
MikkoZ 0:9fb407c1232e 36 else{
MikkoZ 0:9fb407c1232e 37 pc.printf("TresLowReg NO INT");
MikkoZ 0:9fb407c1232e 38 }
MikkoZ 0:9fb407c1232e 39 pc.printf("\r\n");
MikkoZ 0:9fb407c1232e 40 }
MikkoZ 0:9fb407c1232e 41
MikkoZ 0:9fb407c1232e 42
MikkoZ 0:9fb407c1232e 43 void use_treshold_interrupts_to_find_treshold_matching_current_pressure(){
MikkoZ 0:9fb407c1232e 44 pc.printf("\nBM1383 library test program.\n\r");
MikkoZ 0:9fb407c1232e 45 I2CCommonBegin();
MikkoZ 0:9fb407c1232e 46
MikkoZ 0:9fb407c1232e 47 bm1383_wait_until_found();
MikkoZ 0:9fb407c1232e 48 pc.printf("\nSensor found.\n\r");
MikkoZ 0:9fb407c1232e 49 bm1383_mode_poweroff2reset();
MikkoZ 0:9fb407c1232e 50 wait(1);
MikkoZ 0:9fb407c1232e 51 bm1383_mode_reset2standby();
MikkoZ 0:9fb407c1232e 52
MikkoZ 0:9fb407c1232e 53 //setup bm1383 if needed
MikkoZ 0:9fb407c1232e 54 bm1383_set_low_treshold(100);
MikkoZ 0:9fb407c1232e 55 bm1383_enable_interrupt_latching();
MikkoZ 0:9fb407c1232e 56 //bm1383_disable_interrupt_pullup(); //Pullup doesn't work on Japan-shield? Int line stays low(triggered).
MikkoZ 0:9fb407c1232e 57 bm1383_enable_treshold_interrupts();
MikkoZ 0:9fb407c1232e 58 bm1383_clear_interrupt();
MikkoZ 0:9fb407c1232e 59
MikkoZ 0:9fb407c1232e 60 while(1) {
MikkoZ 0:9fb407c1232e 61 float pressure;
MikkoZ 0:9fb407c1232e 62 static uint16_t treshold = 1000;
MikkoZ 0:9fb407c1232e 63
MikkoZ 0:9fb407c1232e 64 pc.printf("\nStart meas. - ");
MikkoZ 0:9fb407c1232e 65
MikkoZ 0:9fb407c1232e 66 bm1383_set_high_treshold(treshold);
MikkoZ 0:9fb407c1232e 67 pc.printf("Treshold: %d \n\r", treshold);
MikkoZ 0:9fb407c1232e 68
MikkoZ 0:9fb407c1232e 69 bm1383_start_measurement_oneshot();
MikkoZ 0:9fb407c1232e 70
MikkoZ 0:9fb407c1232e 71 wait(0.5);
MikkoZ 0:9fb407c1232e 72 //waitActiveLowInterrupt(INTPIN);
MikkoZ 0:9fb407c1232e 73 printTreshodRegStatus();
MikkoZ 0:9fb407c1232e 74
MikkoZ 0:9fb407c1232e 75 pressure = bm1383_read_pressure();
MikkoZ 0:9fb407c1232e 76 pc.printf("Pressure: %f\n\r", pressure);
MikkoZ 0:9fb407c1232e 77
MikkoZ 0:9fb407c1232e 78 pc.printf("Clear int command\n\r");
MikkoZ 0:9fb407c1232e 79 bm1383_clear_interrupt();
MikkoZ 0:9fb407c1232e 80 //waitActiveLowInterruptClear(INTPIN);
MikkoZ 0:9fb407c1232e 81
MikkoZ 0:9fb407c1232e 82 treshold = treshold + 1000;
MikkoZ 0:9fb407c1232e 83
MikkoZ 0:9fb407c1232e 84 }
MikkoZ 0:9fb407c1232e 85 }
MikkoZ 0:9fb407c1232e 86
MikkoZ 0:9fb407c1232e 87
MikkoZ 0:9fb407c1232e 88 int main() {
MikkoZ 0:9fb407c1232e 89 use_treshold_interrupts_to_find_treshold_matching_current_pressure();
MikkoZ 0:9fb407c1232e 90 }
MikkoZ 0:9fb407c1232e 91