ISSDK  1.8
IoT Sensing Software Development Kit
fxos8700_fifo.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - 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 fxos8700_fifo.c
11  * @brief The fxos8700.c file implements the ISSDK FXOS8700 sensor driver
12  * example demonstration with FIFO mode.
13  */
14 
15 /* SDK Includes */
16 #include "pin_mux.h"
17 #include "clock_config.h"
18 #include "board.h"
19 #include "fsl_debug_console.h"
20 
21 /* CMSIS Includes */
22 #include "Driver_I2C.h"
23 
24 /* ISSDK Includes */
25 #include "issdk_hal.h"
26 #include "fxos8700_drv.h"
27 
28 /*******************************************************************************
29  * Macro Definitions
30  ******************************************************************************/
31 /*---------------------------------------------------------------------------*/
32 /*! @def FIFO_SIZE
33  * @brief The watermark value configured for FXAS21002 FIFO Buffer.
34  */
35 #define FIFO_SIZE 4
36 #define RAW_ACCEL_DATA_SIZE (6)
37 
38 /*******************************************************************************
39  * Constants
40  ******************************************************************************/
41 /*! Prepare the register write list to configure FXOS8700 in FIFO mode. */
43  /*! System and Control registers. */
44  /*! Configure the FXOS8700 to 12.5Hz sampling rate. */
46  /*! Prepare the register write list to configure FXOS8700 in FIFO mode. */
50 
51 /*! Command definition to read the Data Ready Status */
53 
54 /*! Command definition to read the FIFO_SIZE Bytes of Accel Data */
57 
58 /*******************************************************************************
59  * Code
60  ******************************************************************************/
61 /*!
62  * @brief Main function
63  */
64 int main(void)
65 {
67  uint8_t fifoEvent;
70 
71  ARM_DRIVER_I2C *I2Cdrv = &I2C_S_DRIVER; // Now using the shield.h value!!!
72  fxos8700_i2c_sensorhandle_t FXOS8700drv;
73 
74  /*! Initialize the MCU hardware. */
78 
79  PRINTF("\r\n ISSDK FXOS8700 sensor driver example demonstration with fifo mode\r\n");
80 
81  /*! Initialize the I2C driver. */
82  status = I2Cdrv->Initialize(I2C_S_SIGNAL_EVENT);
83  if (ARM_DRIVER_OK != status)
84  {
85  PRINTF("\r\n I2C Initialization Failed\r\n");
86  return -1;
87  }
88 
89  /*! Set the I2C Power mode. */
90  status = I2Cdrv->PowerControl(ARM_POWER_FULL);
91  if (ARM_DRIVER_OK != status)
92  {
93  PRINTF("\r\n I2C Power Mode setting Failed\r\n");
94  return -1;
95  }
96 
97  /*! Set the I2C bus speed. */
98  status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
99  if (ARM_DRIVER_OK != status)
100  {
101  PRINTF("\r\n I2C Control Mode setting Failed\r\n");
102  return -1;
103  }
104 
105  /*! Initialize the FXOS8700 sensor driver. */
108  if (SENSOR_ERROR_NONE != status)
109  {
110  PRINTF("\r\n Sensor Initialization Failed\r\n");
111  return -1;
112  }
113  PRINTF("\r\n Successfully Initiliazed Sensor\r\n");
114 
115  /*! Set the task to be executed while waiting for I2C transactions to complete. */
116  //FXOS8700_I2C_SetIdleTask(&FXOS8700drv, (registeridlefunction_t)SMC_SetPowerModeVlpr, SMC);
117 
118  /*! Configure the fxos8700 sensor driver. */
119  status = FXOS8700_I2C_Configure(&FXOS8700drv, fxos8700_Config_with_Fifo);
120  if (SENSOR_ERROR_NONE != status)
121  {
122  PRINTF("\r\n FXOS8700 Sensor Configuration Failed, Err = %d\r\n", status);
123  return -1;
124  }
125  PRINTF("\r\n Successfully Applied FXOS8700 Sensor Configuration\r\n");
126 
127  for (;;) /* Forever loop */
128  {
129  /*! Wait for the FIFO watermark event. */
130  status = FXOS8700_I2C_ReadData(&FXOS8700drv, FXOS8700_STATUS_READ, &fifoEvent);
131  if (0 == (fifoEvent & FXOS8700_F_STATUS_F_WMRK_FLAG_MASK))
132  {
133  continue;
134  }
135 
136  /*! Read the raw sensor data from the fxos8700. */
137  status = FXOS8700_I2C_ReadData(&FXOS8700drv, FXOS8700_ACCEL_FIFO_READ, data);
138  if (ARM_DRIVER_OK != status)
139  {
140  PRINTF("\r\n Read Failed. \r\n");
141  return -1;
142  }
143 
144  for (uint8_t i = 0; i < FIFO_SIZE; i++)
145  {
146  /*! Convert the raw sensor data to signed 16-bit container for display to the debug port. */
147  rawData.accel[0] = ((uint16_t)data[i * RAW_ACCEL_DATA_SIZE + 0] << 8) | data[i * RAW_ACCEL_DATA_SIZE + 1];
148  rawData.accel[0] /= 4;
149  rawData.accel[1] = ((uint16_t)data[i * RAW_ACCEL_DATA_SIZE + 2] << 8) | data[i * RAW_ACCEL_DATA_SIZE + 3];
150  rawData.accel[1] /= 4;
151  rawData.accel[2] = ((uint16_t)data[i * RAW_ACCEL_DATA_SIZE + 4] << 8) | data[i * RAW_ACCEL_DATA_SIZE + 5];
152  rawData.accel[2] /= 4;
153  }
154  /* NOTE: PRINTF is relatively expensive in terms of CPU time, specially when used with-in execution loop. */
155  PRINTF("\r\n Accel X = %d Y = %d Z = %d\r\n", rawData.accel[0], rawData.accel[1], rawData.accel[2]);
156  ASK_USER_TO_RESUME(100 / FIFO_SIZE); /* Ask for user input after processing 100 samples. */
157  }
158 }
int32_t FXOS8700_I2C_Initialize(fxos8700_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: fxos8700_drv.c:222
This structure defines the fxos8700 raw data buffer.
Definition: fxos8700_drv.h:53
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 RAW_ACCEL_DATA_SIZE
Definition: fxos8700_fifo.c:36
#define FXOS8700_WHO_AM_I_PROD_VALUE
Definition: fxos8700.h:146
#define FXOS8700_CTRL_REG1_DR_MASK
Definition: fxos8700.h:1504
#define FXOS8700_CTRL_REG1_DR_SINGLE_12P5_HZ
Definition: fxos8700.h:1523
#define __END_WRITE_DATA__
Definition: sensor_drv.h:45
int main(void)
Main function.
Definition: fxos8700_fifo.c:64
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
#define FIFO_SIZE
The watermark value configured for FXAS21002 FIFO Buffer.
Definition: fxos8700_fifo.c:35
#define I2C_S_SIGNAL_EVENT
Definition: issdk_hal.h:34
#define FXOS8700_F_SETUP_F_WMRK_SHIFT
Definition: fxos8700.h:448
This defines the sensor specific information for I2C.
Definition: fxos8700_drv.h:44
#define FXOS8700_F_STATUS_F_WMRK_FLAG_MASK
Definition: fxos8700.h:250
#define I2C_S_DRIVER
Definition: issdk_hal.h:33
const registerwritelist_t fxos8700_Config_with_Fifo[]
Definition: fxos8700_fifo.c:42
int32_t FXOS8700_I2C_Configure(fxos8700_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: fxos8700_drv.c:260
int32_t FXOS8700_I2C_ReadData(fxos8700_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: fxos8700_drv.c:305
#define BOARD_BootClockRUN
Definition: clock_config.h:19
uint8_t data[FXLS8962_DATA_SIZE]
#define __END_READ_DATA__
Definition: sensor_drv.h:51
#define FXOS8700_F_SETUP_F_WMRK_MASK
Definition: fxos8700.h:447
#define FXOS8700_F_SETUP_F_MODE_FIFO_STOP_OVF
Definition: fxos8700.h:461
ARM_DRIVER_I2C * I2Cdrv
fxos8700_accelmagdata_t rawData
const registerreadlist_t FXOS8700_ACCEL_FIFO_READ[]
Definition: fxos8700_fifo.c:55
uint16_t readFrom
Definition: sensor_drv.h:80
The fxos8700_drv.h file describes the fxos8700 driver interface and structures.
#define FXOS8700_F_SETUP_F_MODE_MASK
Definition: fxos8700.h:450
This structure defines the Read command List.
Definition: sensor_drv.h:78
const registerreadlist_t FXOS8700_STATUS_READ[]
Definition: fxos8700_fifo.c:52
#define I2C_S_DEVICE_INDEX
Definition: issdk_hal.h:35
void BOARD_InitDebugConsole(void)
Definition: board.c:15
#define FXOS8700_I2C_ADDR
void BOARD_InitPins(void)
Configures pin routing and optionally pin electrical features.
Definition: pin_mux.c:47