Sensorian  1.0
C API Reference Guide Library
main.c
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (C) 2015 Sensorian
3  * *
4  * This file is part of Sensorian. *
5  * *
6  * Sensorian is free software: you can redistribute it and/or modify it *
7  * under the terms of the GNU Lesser General Public License as published *
8  * by the Free Software Foundation, either version 3 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * Sensorian is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with Sensorian. *
18  * If not, see <http://www.gnu.org/licenses/>. *
19  ****************************************************************************/
20 
21 
30 #include <bcm2835.h>
31 #include <stdio.h>
32 #include "MPL3115A2.h"
33 #include "i2c.h"
34 #include "Utilities.h"
35 
36 int main(int argc, char **argv)
37 {
38  I2C_Initialize(MPL3115A2_ADDRESS); //Initialize I2C and setup chip address
41 
42  printf("MPL3115A2 Temperature Calibration demo.\r\n");
43 
44  unsigned char id = MPL3115A2_ID(); //Verify chip id
45  printf("Chip ID: 0x%02X . \r\n", id);
46  unsigned char va = 0;
47  float temp = 0;
48 
49  while(1)
50  {
51  temp = MPL3115A2_ReadTemperature();//Take a temperature reading
52  printf("Temperature 1 : %0.2f degree Celsius.\r\n", temp);
53  delay_ms(500);
54 
57  delay_ms(500);
59  delay_ms(500);
60 
61  temp = MPL3115A2_ReadTemperature();//Take a new temperature reading
62  printf("Temperature 2 : %0.2f degree Celsius.\r\n", temp);
63  delay_ms(500);
64 
67  delay_ms(500);
69  delay_ms(500);
70 
72  printf("Reg: %x. \r\n", va);
73  }
74 
75 return 0;
76 }
77 
unsigned char MPL3115A2_ID(void)
Returns the Factory Chip ID.
Definition: MPL3115A2.c:51
float MPL3115A2_ReadTemperature(void)
Get a temperature reading from the sensor.
Definition: MPL3115A2.c:282
MPL3115A2 driver header.
#define MPL3115A2_ADDRESS
The I2C address of the MPL3115A2 barometer altimeter sensor.
Definition: MPL3115A2.h:40
I2C driver header.
void I2C_Initialize(unsigned char address)
Initializes the I2C peripheral.
Definition: i2c.c:36
void MPL3115A2_SetTempOffset(char T_Offset)
Used to correct the measured sensor temeperature by a particular offset.
Definition: MPL3115A2.c:351
void MPL3115A2_Initialize(void)
Initialize the sensor and enable interrupts.
Definition: MPL3115A2.c:40
int main(int argc, char **argv)
Definition: main.c:34
void delay_ms(unsigned int ms)
Delay in ms.
Definition: Utilities.c:39
#define OFF_T
Definition: MPL3115A2.h:86
void MPL3115A2_ActiveMode(void)
Puts the sensor in active mode, needed is the sensor is in standby mode.
Definition: MPL3115A2.c:82
void MPL3115A2_StandbyMode(void)
Puts the sensor in standby mode, the user must do this in order to modify the major control registers...
Definition: MPL3115A2.c:71
unsigned char MPL3115A2_ReadByte(char reg)
Read byte value from register.
Definition: MPL3115A2.c:467