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
29
#include <stdio.h>
30
#include "
Utilities.h
"
31
#include "
FXOS8700CQ.h
"
32
#include "
i2c.h
"
33
34
int
main
(
int
argc,
char
**argv)
35
{
36
unsigned
char
id
= 0;
37
38
rawdata_t
accelerometerBuffer;
39
rawdata_t
magnetometerBuffer;
40
41
I2C_Initialize
(
FXOS8700CQ_ADDRESS
);
//Initialize I2C and setup chip address
42
FXOS8700CQ_Initialize
();
//Setup chip in hybrid mode
43
44
id
=
FXOS8700CQ_ID
();
//Verify chip ID
45
printf(
"Chip ID: 0x%02X. \r\n"
,
id
);
46
47
FXOS8700CQ_StandbyMode
();
48
49
FXOS8700CQ_WriteByte
(
SYSMOD
,0x01);
//Set to wake up
50
51
FXOS8700CQ_ActiveMode
();
52
53
id
=
FXOS8700CQ_GetChipMode
();
//Setup sensor as accelerometer
54
printf(
"Chip Mode: 0x%02X. \r\n"
,
id
);
55
56
id
=
FXOS8700CQ_ReadByte
(
PL_BF_ZCOMP
);
57
printf(
"PL_BF_ZCOMP: 0x%02X. \r\n"
,
id
);
58
59
while
(1)
60
{
61
if
(
FXOS8700CQ_ReadStatusReg
() & 0x80)
62
{
63
FXOS8700CQ_GetData
(&accelerometerBuffer,&magnetometerBuffer);
64
printf(
"Magnetometer data x: %d, y: %d, z: %d \r\n"
, magnetometerBuffer.
x
, magnetometerBuffer.
y
, magnetometerBuffer.
z
);
65
}
66
}
67
68
printf(
"Shutting down"
);
69
I2C_Close
();
//Return I2C pins to default status
70
71
return
0;
72
}
Utilities.h
Utilities driver header.
FXOS8700CQ_GetChipMode
char FXOS8700CQ_GetChipMode(void)
Returns current mode of the chip.
Definition:
FXOS8700CQ.c:106
SYSMOD
#define SYSMOD
Definition:
MemoryMap.h:41
FXOS8700CQ_ADDRESS
#define FXOS8700CQ_ADDRESS
Definition:
FXOS8700CQ.h:35
FXOS8700CQ.h
Accelerometer / Magnetometer driver header.
I2C_Close
void I2C_Close(void)
Closes the I2C peripheral.
Definition:
i2c.c:174
rawdata
Structure encapsulating triple axis raw data.
Definition:
FXOS8700CQ.h:544
rawdata::y
int16_t y
Definition:
FXOS8700CQ.h:547
rawdata::x
int16_t x
Definition:
FXOS8700CQ.h:546
FXOS8700CQ_ActiveMode
void FXOS8700CQ_ActiveMode(void)
Starts up the sensor in Active mode.
Definition:
FXOS8700CQ.c:69
rawdata::z
int16_t z
Definition:
FXOS8700CQ.h:548
I2C_Initialize
void I2C_Initialize(unsigned char address)
Initializes the I2C peripheral.
Definition:
i2c.c:36
FXOS8700CQ_ReadStatusReg
char FXOS8700CQ_ReadStatusReg(void)
Return the value of the status register.
Definition:
FXOS8700CQ.c:60
i2c.h
I2C driver header.
FXOS8700CQ_Initialize
void FXOS8700CQ_Initialize(void)
Initialize FXOS8700CQ, configure for an output rate of 200Hz with a +/- 2g scale. ...
Definition:
FXOS8700CQ.c:42
main
int main(int argc, char **argv)
Definition:
main.c:34
FXOS8700CQ_ReadByte
char FXOS8700CQ_ReadByte(char reg)
Starts up the sensor in Active mode.
Definition:
FXOS8700CQ.c:539
FXOS8700CQ_WriteByte
void FXOS8700CQ_WriteByte(char reg, char value)
Writes a value to a register.
Definition:
FXOS8700CQ.c:517
FXOS8700CQ_GetData
void FXOS8700CQ_GetData(rawdata_t *accel_data, rawdata_t *magn_data)
Get raw data from both accelerometer and magnetometer.
Definition:
FXOS8700CQ.c:240
PL_BF_ZCOMP
#define PL_BF_ZCOMP
Definition:
MemoryMap.h:49
FXOS8700CQ_StandbyMode
char FXOS8700CQ_StandbyMode(void)
Starts up the sensor in Active mode.
Definition:
FXOS8700CQ.c:79
FXOS8700CQ_ID
char FXOS8700CQ_ID(void)
Returns the chip ID.
Definition:
FXOS8700CQ.c:116
FXOS8700CQR1
Example1
main.c
Generated on Sun Jul 12 2015 20:25:27 for Sensorian by
1.8.9.1