ISSDK  1.8
IoT Sensing Software Development Kit
fxpq3115_altitude.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 /**
10  * @file fxpq3115_altitude.c
11  * @brief The fxpq3115_altitude.c file implements the ISSDK FXPQ3115BV sensor driver
12  * example demonstration for Altitude mode.
13  */
14 
15 //-----------------------------------------------------------------------
16 // SDK Includes
17 //-----------------------------------------------------------------------
18 #include "pin_mux.h"
19 #include "clock_config.h"
20 #include "board.h"
21 #include "fsl_debug_console.h"
22 
23 //-----------------------------------------------------------------------
24 // CMSIS Includes
25 //-----------------------------------------------------------------------
26 #include "Driver_I2C.h"
27 
28 /* ISSDK Includes */
29 #include "issdk_hal.h"
30 #include "fxpq3115_drv.h"
31 
32 //-----------------------------------------------------------------------
33 // Macros
34 //-----------------------------------------------------------------------
35 #define FXPQ3115_DATA_SIZE (5) /* 3 byte Pressure/Altitude and 2 byte Temperature. */
36 /*! In FXPQ3115 the Auto Acquisition Time Step (ODR) can be set only in powers of 2 (i.e. 2^x, where x is the
37  * SAMPLING_EXPONENT).
38  * This gives a range of 1 second to 2^15 seconds (9 hours). */
39 #define FXPQ3115_SAMPLING_EXPONENT (1) /* 2 seconds */
40 
41 //-----------------------------------------------------------------------
42 // Constants
43 //-----------------------------------------------------------------------
44 /*! @brief Register settings for Altitude readings in Poll (non buffered) mode. */
46  /* Enable Data Ready and Event flags for Altitude, Temperature or either. */
50  /* Enable Altitude output and set Over Sampling Ratio to 128. */
53  /* Set Auto acquisition time step. */
56 
57 /*! @brief Address of Status Register. */
59 
60 /*! @brief Address and size of Raw Altitude+Temperature Data in Poll Mode. */
63 
64 //-----------------------------------------------------------------------
65 // Functions
66 //-----------------------------------------------------------------------
67 /*!
68  * @brief Main function
69  */
70 int main(void)
71 {
72  int16_t tempInDegrees;
73  int32_t altitudeInMeters;
75  uint8_t dataReady;
76  uint8_t data[FXPQ3115_DATA_SIZE];
78 
79  ARM_DRIVER_I2C *I2Cdrv = &I2C_S_DRIVER; // Now using the shield.h value!!!
80  fxpq3115_i2c_sensorhandle_t fxpq3115Driver;
81 
85 
86  PRINTF("\r\n ISSDK FXPQ3115 sensor driver example demonstration with poll mode\r\n");
87 
88  /*! Initialize the I2C driver. */
89  status = I2Cdrv->Initialize(I2C_S_SIGNAL_EVENT);
90  if (ARM_DRIVER_OK != status)
91  {
92  PRINTF("\r\n I2C Initialization Failed\r\n");
93  return -1;
94  }
95 
96  /*! Set the I2C Power mode. */
97  status = I2Cdrv->PowerControl(ARM_POWER_FULL);
98  if (ARM_DRIVER_OK != status)
99  {
100  PRINTF("\r\n I2C Power Mode setting Failed\r\n");
101  return -1;
102  }
103 
104  /*! Set the I2C bus speed. */
105  status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
106  if (ARM_DRIVER_OK != status)
107  {
108  PRINTF("\r\n I2C Control Mode setting Failed\r\n");
109  return -1;
110  }
111 
112  /*! Initialize FXPQ3115 sensor driver. */
115  if (SENSOR_ERROR_NONE != status)
116  {
117  PRINTF("\r\n Sensor Initialization Failed\r\n");
118  return -1;
119  }
120  PRINTF("\r\n Successfully Initiliazed Sensor\r\n");
121 
122  /*! Set the task to be executed while waiting for I2C transactions to complete. */
124 
125  /*! Configure the FXPQ3115 sensor. */
126  status = FXPQ3115_I2C_Configure(&fxpq3115Driver, B3115ConfigAltitude);
127  if (SENSOR_ERROR_NONE != status)
128  {
129  PRINTF("\r\n FXPQ3115 sensor configuration failed.\r\n");
130  return -1;
131  }
132  PRINTF("\r\n Successfully Applied FXPQ3115 Sensor Configuration\r\n");
133 
134  for (;;) /* Forever loop */
135  {
136  /*! Wait for data ready from the FXPQ3115. */
137  status = FXPQ3115_I2C_ReadData(&fxpq3115Driver, B3115Status, &dataReady);
138  if (0 == (dataReady & FXPQ3115_DR_STATUS_PTDR_MASK))
139  { /* Loop, if new sample is not available. */
140  continue;
141  }
142 
143  /*! Read new raw sensor data from the FXPQ3115. */
144  status = FXPQ3115_I2C_ReadData(&fxpq3115Driver, B3115OutputPoll, data);
145  if (ARM_DRIVER_OK != status)
146  {
147  PRINTF("\r\n Read Failed. \r\n");
148  return -1;
149  }
150 
151  /*! Process the sample and convert the raw sensor data. */
152  rawData.altitude = (int32_t)((data[0]) << 24) | ((data[1]) << 16) | ((data[2]) << 8);
153  altitudeInMeters = rawData.altitude / FXPQ3115_ALTITUDE_CONV_FACTOR;
154 
155  rawData.temperature = (int16_t)((data[3]) << 8) | (data[4]);
156  tempInDegrees = rawData.temperature / FXPQ3115_TEMPERATURE_CONV_FACTOR;
157 
158  PRINTF("\r\n Altitude = %d Meters\r\n", altitudeInMeters);
159  PRINTF("\r\n Temperature = %d degC\r\n", tempInDegrees);
160  ASK_USER_TO_RESUME(8); /* Ask for user input after processing 8 samples. */
161  }
162 }
int main(void)
Main function.
const registerreadlist_t B3115Status[]
Address of Status Register.
This structure defines the Write command List.
Definition: sensor_drv.h:68
#define ASK_USER_TO_RESUME(x)
Definition: frdm_k64f.h:106
int32_t status
#define FXPQ3115_DR_STATUS_PTDR_MASK
Definition: fxpq3115.h:195
status_t SMC_SetPowerModeVlpr(void *arg)
Configures the system to VLPR power mode. API name used from Kinetis family to maintain compatibility...
Definition: lpc54114.c:169
This structure defines the fxpq3115 data buffer in Altitude Mode.
Definition: fxpq3115_drv.h:54
#define SMC
Definition: lpc54114.h:118
#define FXPQ3115_PT_DATA_CFG_TDEFE_MASK
Definition: fxpq3115.h:550
#define FXPQ3115_PT_DATA_CFG_TDEFE_ENABLED
Definition: fxpq3115.h:564
#define FXPQ3115_ALTITUDE_CONV_FACTOR
Definition: fxpq3115_drv.h:29
#define FXPQ3115_CTRL_REG1_OS_MASK
Definition: fxpq3115.h:855
#define __END_WRITE_DATA__
Definition: sensor_drv.h:45
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
#define FXPQ3115_PT_DATA_CFG_PDEFE_MASK
Definition: fxpq3115.h:553
#define I2C_S_SIGNAL_EVENT
Definition: issdk_hal.h:34
#define I2C_S_DRIVER
Definition: issdk_hal.h:33
#define FXPQ3115_DATA_SIZE
int32_t FXPQ3115_I2C_Configure(fxpq3115_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: fxpq3115_drv.c:61
#define BOARD_BootClockRUN
Definition: clock_config.h:19
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:97
void FXPQ3115_I2C_SetIdleTask(fxpq3115_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: fxpq3115_drv.c:53
int32_t FXPQ3115_I2C_Initialize(fxpq3115_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t whoAmi)
The interface function to initialize the sensor.
Definition: fxpq3115_drv.c:22
const registerwritelist_t B3115ConfigAltitude[]
Register settings for Altitude readings in Poll (non buffered) mode.
#define FXPQ3115_PT_DATA_CFG_DREM_MASK
Definition: fxpq3115.h:556
The fxpq3115_drv.h file describes the fxpq3115 driver interface and structures.
uint8_t data[FXLS8962_DATA_SIZE]
#define __END_READ_DATA__
Definition: sensor_drv.h:51
const registerreadlist_t B3115OutputPoll[]
Address and size of Raw Altitude+Temperature Data in Poll Mode.
#define FXPQ3115_CTRL_REG1_ALT_ALT
Definition: fxpq3115.h:891
#define FXPQ3115_CTRL_REG1_OS_OSR_128
Definition: fxpq3115.h:887
ARM_DRIVER_I2C * I2Cdrv
fxos8700_accelmagdata_t rawData
#define FXPQ3115_CTRL_REG1_ALT_MASK
Definition: fxpq3115.h:861
#define FXPQ3115_PT_DATA_CFG_PDEFE_ENABLED
Definition: fxpq3115.h:567
uint16_t readFrom
Definition: sensor_drv.h:80
#define FXPQ3115_WHOAMI_VALUE
Definition: fxpq3115.h:65
This structure defines the Read command List.
Definition: sensor_drv.h:78
#define FXPQ3115_I2C_ADDR
#define I2C_S_DEVICE_INDEX
Definition: issdk_hal.h:35
This defines the sensor specific information.
Definition: fxpq3115_drv.h:36
void BOARD_InitDebugConsole(void)
Definition: board.c:15
#define FXPQ3115_SAMPLING_EXPONENT
int32_t FXPQ3115_I2C_ReadData(fxpq3115_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: fxpq3115_drv.c:106
void BOARD_InitPins(void)
Configures pin routing and optionally pin electrical features.
Definition: pin_mux.c:47
#define FXPQ3115_PT_DATA_CFG_DREM_ENABLED
Definition: fxpq3115.h:570
#define FXPQ3115_CTRL_REG2_ST_MASK
Definition: fxpq3115.h:919
#define FXPQ3115_TEMPERATURE_CONV_FACTOR
Definition: fxpq3115_drv.h:30