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 
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 
48 
49  FXOS8700CQ_WriteByte(SYSMOD,0x01); //Set to wake up
50 
52 
53  id = FXOS8700CQ_GetChipMode(); //Setup sensor as accelerometer
54  printf("Chip Mode: 0x%02X. \r\n",id);
55 
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 driver header.
char FXOS8700CQ_GetChipMode(void)
Returns current mode of the chip.
Definition: FXOS8700CQ.c:106
#define SYSMOD
Definition: MemoryMap.h:41
#define FXOS8700CQ_ADDRESS
Definition: FXOS8700CQ.h:35
Accelerometer / Magnetometer driver header.
void I2C_Close(void)
Closes the I2C peripheral.
Definition: i2c.c:174
Structure encapsulating triple axis raw data.
Definition: FXOS8700CQ.h:544
int16_t y
Definition: FXOS8700CQ.h:547
int16_t x
Definition: FXOS8700CQ.h:546
void FXOS8700CQ_ActiveMode(void)
Starts up the sensor in Active mode.
Definition: FXOS8700CQ.c:69
int16_t z
Definition: FXOS8700CQ.h:548
void I2C_Initialize(unsigned char address)
Initializes the I2C peripheral.
Definition: i2c.c:36
char FXOS8700CQ_ReadStatusReg(void)
Return the value of the status register.
Definition: FXOS8700CQ.c:60
I2C driver header.
void FXOS8700CQ_Initialize(void)
Initialize FXOS8700CQ, configure for an output rate of 200Hz with a +/- 2g scale. ...
Definition: FXOS8700CQ.c:42
int main(int argc, char **argv)
Definition: main.c:34
char FXOS8700CQ_ReadByte(char reg)
Starts up the sensor in Active mode.
Definition: FXOS8700CQ.c:539
void FXOS8700CQ_WriteByte(char reg, char value)
Writes a value to a register.
Definition: FXOS8700CQ.c:517
void FXOS8700CQ_GetData(rawdata_t *accel_data, rawdata_t *magn_data)
Get raw data from both accelerometer and magnetometer.
Definition: FXOS8700CQ.c:240
#define PL_BF_ZCOMP
Definition: MemoryMap.h:49
char FXOS8700CQ_StandbyMode(void)
Starts up the sensor in Active mode.
Definition: FXOS8700CQ.c:79
char FXOS8700CQ_ID(void)
Returns the chip ID.
Definition: FXOS8700CQ.c:116