Sensorian
1.0
C API Reference Guide Library
Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
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
39
MPL3115A2_Initialize
();
40
MPL3115A2_ActiveMode
();
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
55
MPL3115A2_StandbyMode
();
56
MPL3115A2_SetTempOffset
(-50);
57
delay_ms
(500);
58
MPL3115A2_ActiveMode
();
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
65
MPL3115A2_StandbyMode
();
66
MPL3115A2_SetTempOffset
(-128);
67
delay_ms
(500);
68
MPL3115A2_ActiveMode
();
69
delay_ms
(500);
70
71
va =
MPL3115A2_ReadByte
(
OFF_T
);
72
printf(
"Reg: %x. \r\n"
, va);
73
}
74
75
return
0;
76
}
77
MPL3115A2_ID
unsigned char MPL3115A2_ID(void)
Returns the Factory Chip ID.
Definition:
MPL3115A2.c:51
MPL3115A2_ReadTemperature
float MPL3115A2_ReadTemperature(void)
Get a temperature reading from the sensor.
Definition:
MPL3115A2.c:282
MPL3115A2.h
MPL3115A2 driver header.
MPL3115A2_ADDRESS
#define MPL3115A2_ADDRESS
The I2C address of the MPL3115A2 barometer altimeter sensor.
Definition:
MPL3115A2.h:40
i2c.h
I2C driver header.
I2C_Initialize
void I2C_Initialize(unsigned char address)
Initializes the I2C peripheral.
Definition:
i2c.c:36
MPL3115A2_SetTempOffset
void MPL3115A2_SetTempOffset(char T_Offset)
Used to correct the measured sensor temeperature by a particular offset.
Definition:
MPL3115A2.c:351
MPL3115A2_Initialize
void MPL3115A2_Initialize(void)
Initialize the sensor and enable interrupts.
Definition:
MPL3115A2.c:40
main
int main(int argc, char **argv)
Definition:
main.c:34
delay_ms
void delay_ms(unsigned int ms)
Delay in ms.
Definition:
Utilities.c:39
OFF_T
#define OFF_T
Definition:
MPL3115A2.h:86
Utilities.h
MPL3115A2_ActiveMode
void MPL3115A2_ActiveMode(void)
Puts the sensor in active mode, needed is the sensor is in standby mode.
Definition:
MPL3115A2.c:82
MPL3115A2_StandbyMode
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
MPL3115A2_ReadByte
unsigned char MPL3115A2_ReadByte(char reg)
Read byte value from register.
Definition:
MPL3115A2.c:467
MPL3115A2
Example3
main.c
Generated on Sun Jul 12 2015 20:25:27 for Sensorian by
1.8.9.1