ISSDK  1.8
IoT Sensing Software Development Kit
fxls8962_normal.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 fxls8962_normal.c
11  * @brief The fxls8962_normal.c file implements the ISSDK FXLS8962 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 "fxls8962_drv.h"
27 #include "systick_utils.h"
28 
29 /*******************************************************************************
30  * Macros
31  ******************************************************************************/
32 #define FXLS8962_DATA_SIZE 6
33 
34 /*******************************************************************************
35  * Constants
36  ******************************************************************************/
37 /*! @brief Register settings for Normal (non buffered) mode. */
39  /* Set Full-scale range as 2G. */
41  /* Set Wake Mode ODR Rate as 6.25Hz. */
44 
45 /*! @brief Address of DATA Ready Status Register. */
47 
48 /*! @brief Address of Raw Accel Data in Normal Mode. */
51 
52 /*******************************************************************************
53  * Code
54  ******************************************************************************/
55 /*!
56  * @brief Main function
57  */
58 int main(void)
59 {
61  uint8_t whoami;
62  uint8_t dataReady;
63  uint8_t data[FXLS8962_DATA_SIZE];
65 
66  ARM_DRIVER_I2C *I2Cdrv = &I2C_S_DRIVER; // Now using the shield.h value!!!
68 
69  /*! Initialize the MCU hardware. */
74 
75  PRINTF("\r\n ISSDK FXLS896x sensor driver example demonstration with poll mode\r\n");
76 
77  /*! Initialize the I2C driver. */
78  status = I2Cdrv->Initialize(I2C_S_SIGNAL_EVENT);
79  if (ARM_DRIVER_OK != status)
80  {
81  PRINTF("\r\n I2C Initialization Failed\r\n");
82  return -1;
83  }
84 
85  /*! Set the I2C Power mode. */
86  status = I2Cdrv->PowerControl(ARM_POWER_FULL);
87  if (ARM_DRIVER_OK != status)
88  {
89  PRINTF("\r\n I2C Power Mode setting Failed\r\n");
90  return -1;
91  }
92 
93  /*! Set the I2C bus speed. */
94  status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
95  if (ARM_DRIVER_OK != status)
96  {
97  PRINTF("\r\n I2C Control Mode setting Failed\r\n");
98  return -1;
99  }
100 
101  /*! Initialize FXLS8962 sensor driver. */
103  &whoami);
104  if (ARM_DRIVER_OK != status)
105  {
106  PRINTF("\r\n Sensor Initialization Failed\r\n");
107  return -1;
108  }
109  if ((FXLS8964_WHOAMI_VALUE == whoami) || (FXLS8967_WHOAMI_VALUE == whoami))
110  {
111  PRINTF("\r\n Successfully Initialized Gemini with WHO_AM_I = 0x%X\r\n", whoami);
112  }
113  else if (FXLS8974_WHOAMI_VALUE == whoami)
114  {
115  PRINTF("\r\n Successfully Initialized Timandra with WHO_AM_I = 0x%X\r\n", whoami);
116  }
117  else if (FXLS8962_WHOAMI_VALUE == whoami)
118  {
119  PRINTF("\r\n Successfully Initialized Newstein with WHO_AM_I = 0x%X\r\n", whoami);
120  }
121  else
122  {
123  PRINTF("\r\n Bad WHO_AM_I = 0x%X\r\n", whoami);
124  }
125 
126  /*! Set the task to be executed while waiting for I2C transactions to complete. */
128 
129  /*! Configure the FXLS8962 sensor. */
130  status = FXLS8962_I2C_Configure(&fxls8962Driver, cFxls8962ConfigNormal);
131  if (ARM_DRIVER_OK != status)
132  {
133  PRINTF("\r\n FXLS896x Sensor Configuration Failed, Err = %d\r\n", status);
134  return -1;
135  }
136  PRINTF("\r\n Successfully Applied FXLS896x Sensor Configuration\r\n");
137 
138  for (;;) /* Forever loop */
139  {
140  /*! Wait for data ready from the FXLS8962. */
141  status = FXLS8962_I2C_ReadData(&fxls8962Driver, cFxls8962DRDYEvent, &dataReady);
142  if (0 == (dataReady & FXLS8962_INT_STATUS_SRC_DRDY_MASK))
143  {
144  continue;
145  }
146 
147  /*! Read new raw sensor data from the FXLS8962. */
148  status = FXLS8962_I2C_ReadData(&fxls8962Driver, cFxls8962OutputNormal, data);
149  if (ARM_DRIVER_OK != status)
150  {
151  PRINTF("\r\n Read Failed. \r\n");
152  return -1;
153  }
154 
155  /*! Convert the raw sensor data to signed 16-bit container for display to the debug port. */
156  rawData.accel[0] = ((int16_t)data[1] << 8) | data[0];
157  rawData.accel[1] = ((int16_t)data[3] << 8) | data[2];
158  rawData.accel[2] = ((int16_t)data[5] << 8) | data[4];
159 
160  /* NOTE: PRINTF is relatively expensive in terms of CPU time, specially when used with-in execution loop. */
161  PRINTF("\r\nX=%5d Y=%5d Z=%5d\r\n", rawData.accel[0], rawData.accel[1], rawData.accel[2]);
162  ASK_USER_TO_RESUME(50); /* Ask for user input after processing 50 samples. */
163  }
164 }
This structure defines the fxls8962 raw data buffer.
Definition: fxls8962_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 FXLS8962_SENS_CONFIG1_FSR_2G
Definition: fxls8962.h:453
const registerreadlist_t cFxls8962DRDYEvent[]
Address of DATA Ready Status Register.
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
The fxls8962_drv.h file describes the FXLS8962AF driver interface and structures. ...
int32_t FXLS8962_I2C_Initialize(fxls8962_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: fxls8962_drv.c:240
#define SMC
Definition: lpc54114.h:118
#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 FXLS8962_INT_STATUS_SRC_DRDY_MASK
Definition: fxls8962.h:147
#define FXLS8962_DATA_SIZE
#define FXLS8962_SENS_CONFIG3_WAKE_ODR_MASK
Definition: fxls8962.h:551
This defines the sensor specific information for I2C.
Definition: fxls8962_drv.h:44
#define FXLS8967_WHOAMI_VALUE
Definition: fxls8962.h:89
#define I2C_S_SIGNAL_EVENT
Definition: issdk_hal.h:34
#define I2C_S_DRIVER
Definition: issdk_hal.h:33
#define BOARD_BootClockRUN
Definition: clock_config.h:19
fxls8962_i2c_sensorhandle_t fxls8962Driver
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:97
uint8_t data[FXLS8962_DATA_SIZE]
#define __END_READ_DATA__
Definition: sensor_drv.h:51
int main(void)
Main function.
int32_t FXLS8962_I2C_ReadData(fxls8962_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: fxls8962_drv.c:331
#define FXLS8962_SENS_CONFIG3_WAKE_ODR_6_25HZ
Definition: fxls8962.h:566
ARM_DRIVER_I2C * I2Cdrv
fxos8700_accelmagdata_t rawData
const registerwritelist_t cFxls8962ConfigNormal[]
Register settings for Normal (non buffered) mode.
uint16_t readFrom
Definition: sensor_drv.h:80
const registerreadlist_t cFxls8962OutputNormal[]
Address of Raw Accel Data in Normal Mode.
void BOARD_SystickEnable(void)
Function to enable systicks framework.
Definition: systick_utils.c:35
int32_t FXLS8962_I2C_Configure(fxls8962_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: fxls8962_drv.c:286
This structure defines the Read command List.
Definition: sensor_drv.h:78
ARM Systick Utilities.
#define FXLS8962_SENS_CONFIG1_FSR_MASK
Definition: fxls8962.h:423
#define FXLS8974_WHOAMI_VALUE
Definition: fxls8962.h:90
#define I2C_S_DEVICE_INDEX
Definition: issdk_hal.h:35
void FXLS8962_I2C_SetIdleTask(fxls8962_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: fxls8962_drv.c:278
#define FXLS8962_I2C_ADDR
void BOARD_InitDebugConsole(void)
Definition: board.c:15
#define FXLS8962_WHOAMI_VALUE
Definition: fxls8962.h:87
void BOARD_InitPins(void)
Configures pin routing and optionally pin electrical features.
Definition: pin_mux.c:47
#define FXLS8964_WHOAMI_VALUE
Definition: fxls8962.h:88