ISSDK  1.8
IoT Sensing Software Development Kit
fxas21002_poll.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 fxas21002_poll.c
11  * @brief The fxas21002_poll.c file implements the ISSDK FXAS21002 sensor driver
12  * example demonstration with polling 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 "fxas21002_drv.h"
27 
28 /*******************************************************************************
29  * Constants
30  ******************************************************************************/
31 /*! Prepare the register write list to configure FXAS21002 in non-FIFO mode. */
33  /*! Configure CTRL_REG1 register to put FXAS21002 to 12.5Hz sampling rate. */
36 
37 /*! Prepare the register read list to read FXAS21002 DataReady status. */
39 
40 /*! Prepare the register read list to read the raw gyro data from the FXAS21002. */
43 
44 /*******************************************************************************
45  * Code
46  ******************************************************************************/
47 /*!
48  * @brief Main function
49  */
50 int main(void)
51 {
53  uint8_t dataReady;
56 
57  ARM_DRIVER_I2C *I2Cdrv = &I2C_S_DRIVER; // Now using the shield.h value!!!
58  fxas21002_i2c_sensorhandle_t FXAS21002drv;
59 
60  /*! Initialize the MCU hardware. */
64 
65  PRINTF("\r\n ISSDK FXAS21002 sensor driver example demonstration with poll mode\r\n");
66 
67  /*! Initialize the I2C driver. */
68  status = I2Cdrv->Initialize(I2C_S_SIGNAL_EVENT);
69  if (ARM_DRIVER_OK != status)
70  {
71  PRINTF("\r\n I2C Initialization Failed\r\n");
72  return -1;
73  }
74 
75  /*! Set the I2C Power mode. */
76  status = I2Cdrv->PowerControl(ARM_POWER_FULL);
77  if (ARM_DRIVER_OK != status)
78  {
79  PRINTF("\r\n I2C Power Mode setting Failed\r\n");
80  return -1;
81  }
82 
83  /*! Set the I2C bus speed. */
84  status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
85  if (ARM_DRIVER_OK != status)
86  {
87  PRINTF("\r\n I2C Control Mode setting Failed\r\n");
88  return -1;
89  }
90 
91  /*! Initialize the FXAS21002 sensor driver. */
94  if (SENSOR_ERROR_NONE != status)
95  {
96  PRINTF("\r\n Sensor Initialization Failed\r\n");
97  return -1;
98  }
99  PRINTF("\r\n Successfully Initiliazed Sensor\r\n");
100 
101  /*! Set the task to be executed while waiting for I2C transactions to complete. */
102  //FXAS21002_I2C_SetIdleTask(&FXAS21002drv, (registeridlefunction_t)SMC_SetPowerModeVlpr, SMC);
103 
104  /*! Configure the FXAS21002 sensor driver. */
105  status = FXAS21002_I2C_Configure(&FXAS21002drv, fxas21002_Config_Normal);
106  if (SENSOR_ERROR_NONE != status)
107  {
108  PRINTF("\r\n FXAS21002 Sensor Configuration Failed, Err = %d\r\n", status);
109  return -1;
110  }
111  PRINTF("\r\n Successfully Applied FXAS21002 Sensor Configuration\r\n");
112 
113  for (;;) /* Forever loop */
114  {
115  /*! Wait for data ready from the FXAS21002. */
116  status = FXAS21002_I2C_ReadData(&FXAS21002drv, fxas21002_DRDY, &dataReady);
117  if (0 == (dataReady & FXAS21002_DR_STATUS_ZYXDR_MASK))
118  {
119  continue;
120  }
121 
122  /*! Read the raw sensor data from the FXAS21002. */
123  status = FXAS21002_I2C_ReadData(&FXAS21002drv, fxas21002_Output_Values, data);
124  if (ARM_DRIVER_OK != status)
125  {
126  PRINTF("\r\n Read Failed. \r\n");
127  return -1;
128  }
129 
130  /*! Convert the raw sensor data to signed 16-bit container for display to the debug port. */
131  rawData.gyro[0] = ((int16_t)data[0] << 8) | data[1];
132  rawData.gyro[1] = ((int16_t)data[2] << 8) | data[3];
133  rawData.gyro[2] = ((int16_t)data[4] << 8) | data[5];
134 
135  /* NOTE: PRINTF is relatively expensive in terms of CPU time, specially when used with-in execution loop. */
136  PRINTF("\r\n Gyro X = %d Y = %d Z = %d\r\n", rawData.gyro[0], rawData.gyro[1], rawData.gyro[2]);
137  ASK_USER_TO_RESUME(100); /* Ask for user input after processing 100 samples. */
138  }
139 }
#define FXAS21002_WHO_AM_I_WHOAMI_PROD_VALUE
Definition: fxas21002.h:402
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
const registerreadlist_t fxas21002_Output_Values[]
int32_t FXAS21002_I2C_Initialize(fxas21002_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t whoAmi)
The interface function to initialize the sensor.
const registerreadlist_t fxas21002_DRDY[]
This structure defines the fxas21002 raw data buffer.
Definition: fxas21002_drv.h:53
#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 I2C_S_SIGNAL_EVENT
Definition: issdk_hal.h:34
int32_t FXAS21002_I2C_Configure(fxas21002_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
#define I2C_S_DRIVER
Definition: issdk_hal.h:33
This defines the sensor specific information for I2C.
Definition: fxas21002_drv.h:44
#define BOARD_BootClockRUN
Definition: clock_config.h:19
#define FXAS21002_I2C_ADDR
uint8_t data[FXLS8962_DATA_SIZE]
#define FXAS21002_DR_STATUS_ZYXDR_MASK
Definition: fxas21002.h:160
#define __END_READ_DATA__
Definition: sensor_drv.h:51
The fxas21002_drv.h file describes the fxas21002 driver interface and structures. ...
int32_t FXAS21002_I2C_ReadData(fxas21002_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
ARM_DRIVER_I2C * I2Cdrv
fxos8700_accelmagdata_t rawData
uint16_t readFrom
Definition: sensor_drv.h:80
#define FXAS21002_GYRO_DATA_SIZE
The size of the FXAS21002 gyro data.
Definition: fxas21002_drv.h:61
#define FXAS21002_CTRL_REG1_DR_MASK
Definition: fxas21002.h:684
int main(void)
Main function.
This structure defines the Read command List.
Definition: sensor_drv.h:78
const registerwritelist_t fxas21002_Config_Normal[]
#define I2C_S_DEVICE_INDEX
Definition: issdk_hal.h:35
#define FXAS21002_CTRL_REG1_DR_12_5HZ
Definition: fxas21002.h:710
void BOARD_InitDebugConsole(void)
Definition: board.c:15
void BOARD_InitPins(void)
Configures pin routing and optionally pin electrical features.
Definition: pin_mux.c:47