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 13:13:41 2016 +0000
Revision:
1:6f7979f79aa4
Parent:
0:9fb407c1232e
Refactored main program

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 1:6f7979f79aa4 43 void bm1383_init_and_setup(){
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 1:6f7979f79aa4 59 }
MikkoZ 0:9fb407c1232e 60
MikkoZ 1:6f7979f79aa4 61 void bm1383_read_previous_measurement_and_start_new_one(){
MikkoZ 1:6f7979f79aa4 62 float pressure;
MikkoZ 1:6f7979f79aa4 63 static uint16_t treshold = 0;
MikkoZ 1:6f7979f79aa4 64
MikkoZ 1:6f7979f79aa4 65 //waitActiveLowInterrupt(INTPIN);
MikkoZ 1:6f7979f79aa4 66
MikkoZ 1:6f7979f79aa4 67 pressure = bm1383_read_pressure();
MikkoZ 1:6f7979f79aa4 68 pc.printf("Pressure: %f\n\r", pressure);
MikkoZ 1:6f7979f79aa4 69
MikkoZ 1:6f7979f79aa4 70 printTreshodRegStatus();
MikkoZ 1:6f7979f79aa4 71 pc.printf("Clear int command\n\r");
MikkoZ 1:6f7979f79aa4 72 pc.printf("\r\n");
MikkoZ 1:6f7979f79aa4 73 bm1383_clear_interrupt();
MikkoZ 1:6f7979f79aa4 74 //waitActiveLowInterruptClear(INTPIN);
MikkoZ 1:6f7979f79aa4 75
MikkoZ 1:6f7979f79aa4 76 treshold = treshold + 1000;
MikkoZ 1:6f7979f79aa4 77 pc.printf("Treshold: %d \n\r", treshold);
MikkoZ 1:6f7979f79aa4 78 pc.printf("Start meas. - ");
MikkoZ 1:6f7979f79aa4 79 bm1383_set_high_treshold(treshold);
MikkoZ 1:6f7979f79aa4 80 bm1383_start_measurement_oneshot();
MikkoZ 0:9fb407c1232e 81 }
MikkoZ 0:9fb407c1232e 82
MikkoZ 0:9fb407c1232e 83
MikkoZ 0:9fb407c1232e 84 int main() {
MikkoZ 1:6f7979f79aa4 85 while(1){
MikkoZ 1:6f7979f79aa4 86 bm1383_read_previous_measurement_and_start_new_one();
MikkoZ 1:6f7979f79aa4 87 wait(0.5);
MikkoZ 1:6f7979f79aa4 88 }
MikkoZ 0:9fb407c1232e 89 }
MikkoZ 0:9fb407c1232e 90