ISSDK  1.8
IoT Sensing Software Development Kit
fxls8962_normal_spi.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_spi.c
11  * @brief The fxls8962_normal_spi.c file implements the ISSDK FXLS8962 SPI sensor driver
12  * example demonstration for SPI Mode with polling.
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 // ISSDK Includes
25 //-----------------------------------------------------------------------
26 #include "issdk_hal.h"
27 #include "gpio_driver.h"
28 #include "fxls8962_drv.h"
29 #include "systick_utils.h"
30 
31 //-----------------------------------------------------------------------
32 // CMSIS Includes
33 //-----------------------------------------------------------------------
34 #include "Driver_SPI.h"
35 
36 //-----------------------------------------------------------------------
37 // Macros
38 //-----------------------------------------------------------------------
39 #define FXLS8962_DATA_SIZE (6)
40 
41 //-----------------------------------------------------------------------
42 // Constants
43 //-----------------------------------------------------------------------
44 /*! @brief Register settings for Normal (non buffered) mode. */
46  /* Set Full-scale range as 2G. */
48  /* Set Wake Mode ODR Rate as 6.25Hz. */
51 
52 /*! @brief Address of DATA Ready Status Register. */
54 
55 /*! @brief Address of Raw Accel Data in Normal Mode. */
58 
59 //-----------------------------------------------------------------------
60 // Functions
61 //-----------------------------------------------------------------------
62 /*! -----------------------------------------------------------------------
63  * @brief This is the The main function implementation.
64  * @details This function invokes board initializes routines, then then brings up the sensor and
65  * finally enters an endless loop to continuously read available samples.
66  * @param[in] void This is no input parameter.
67  * @return void There is no return value.
68  * @constraints None
69  * @reeentrant No
70  * -----------------------------------------------------------------------*/
71 int main(void)
72 {
74  uint8_t whoami;
75  uint8_t gFxls8962DataReady;
76  uint8_t data[FXLS8962_DATA_SIZE];
78 
79  ARM_DRIVER_SPI *pSPIdriver = &SPI_S_DRIVER;
81 
82  /*! Initialize the MCU hardware. */
87 
88  PRINTF("\r\n ISSDK FXLS896x sensor driver example demonstration for SPI with Poll Mode.\r\n");
89 
90  /*! Initialize the SPI driver. */
91  status = pSPIdriver->Initialize(SPI_S_SIGNAL_EVENT);
92  if (ARM_DRIVER_OK != status)
93  {
94  PRINTF("\r\n SPI Initialization Failed\r\n");
95  return -1;
96  }
97 
98  /*! Set the SPI Power mode. */
99  status = pSPIdriver->PowerControl(ARM_POWER_FULL);
100  if (ARM_DRIVER_OK != status)
101  {
102  PRINTF("\r\n SPI Power Mode setting Failed\r\n");
103  return -1;
104  }
105 
106  /*! Set the SPI Slave speed. */
107  status = pSPIdriver->Control(ARM_SPI_MODE_MASTER | ARM_SPI_CPOL0_CPHA0, SPI_S_BAUDRATE);
108  if (ARM_DRIVER_OK != status)
109  {
110  PRINTF("\r\n SPI Control Mode setting Failed\r\n");
111  return -1;
112  }
113 
114  /*! Initialize the fxls8962 sensor driver. */
116  &whoami);
117  if (SENSOR_ERROR_NONE != status)
118  {
119  PRINTF("\r\n FXLS896x Sensor Initialization Failed\r\n");
120  return -1;
121  }
122  if ((FXLS8964_WHOAMI_VALUE == whoami) || (FXLS8967_WHOAMI_VALUE == whoami))
123  {
124  PRINTF("\r\n Successfully Initialized Gemini with WHO_AM_I = 0x%X\r\n", whoami);
125  }
126  else if (FXLS8974_WHOAMI_VALUE == whoami)
127  {
128  PRINTF("\r\n Successfully Initialized Timandra with WHO_AM_I = 0x%X\r\n", whoami);
129  }
130  else if (FXLS8962_WHOAMI_VALUE == whoami)
131  {
132  PRINTF("\r\n Successfully Initialized Newstein with WHO_AM_I = 0x%X\r\n", whoami);
133  }
134  else
135  {
136  PRINTF("\r\n Bad WHO_AM_I = 0x%X\r\n", whoami);
137  }
138 
139  /*! Set the task to be executed while waiting for SPI transactions to complete. */
141 
142  /*! Configure the FXLS8962 sensor driver. */
143  status = FXLS8962_SPI_Configure(&fxls8962Driver, cFxls8962ConfigNormal);
144  if (SENSOR_ERROR_NONE != status)
145  {
146  PRINTF("\r\n FXLS896x Sensor Configuration Failed, Err = %d\r\n", status);
147  return -1;
148  }
149  PRINTF("\r\n Successfully Applied FXLS896x Sensor Configuration\r\n");
150 
151  for (;;) /* Forever loop */
152  {
153  /*! Wait for data ready from the FXLS8962. */
154  status = FXLS8962_SPI_ReadData(&fxls8962Driver, cFxls8962DRDYEvent, &gFxls8962DataReady);
155  if (0 == (gFxls8962DataReady & FXLS8962_INT_STATUS_SRC_DRDY_MASK))
156  { /* Loop, if new sample is not available. */
157  continue;
158  }
159 
160  /*! Read the raw sensor data from the FXLS8962. */
161  status = FXLS8962_SPI_ReadData(&fxls8962Driver, cFxls8962OutputNormal, data);
162  if (ARM_DRIVER_OK != status)
163  {
164  PRINTF("\r\nRead Failed.\r\n");
165  return -1;
166  }
167 
168  /*! Convert the raw sensor data for display to the debug port. */
169  rawData.accel[0] = ((int16_t)data[1] << 8) | data[0];
170  rawData.accel[1] = ((int16_t)data[3] << 8) | data[2];
171  rawData.accel[2] = ((int16_t)data[5] << 8) | data[4];
172 
173  /* NOTE: PRINTF is relatively expensive in terms of CPU time, specially when used with-in execution loop. */
174  PRINTF("\r\n X=%5d Y=%5d Z=%5d\r\n", rawData.accel[0], rawData.accel[1], rawData.accel[2]);
175  }
176 }
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
int32_t status
#define FXLS8962_SENS_CONFIG1_FSR_2G
Definition: fxls8962.h:453
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_SPI_ReadData(fxls8962_spi_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: fxls8962_drv.c:176
#define SMC
Definition: lpc54114.h:118
int main(void)
This is the The main function implementation.
const registerreadlist_t cFxls8962DRDYEvent[]
Address of DATA Ready Status Register.
#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 SPI_S_BAUDRATE
Transfer baudrate - 500k.
Definition: frdm_k64f.h:88
#define FXLS8962_SENS_CONFIG3_WAKE_ODR_MASK
Definition: fxls8962.h:551
void FXLS8962_SPI_SetIdleTask(fxls8962_spi_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the SPI Idle Task.
Definition: fxls8962_drv.c:123
#define FXLS8967_WHOAMI_VALUE
Definition: fxls8962.h:89
#define SPI_S_DEVICE_INDEX
Definition: frdm_k64f.h:89
#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
This defines the sensor specific information for SPI.
Definition: fxls8962_drv.h:33
uint8_t data[FXLS8962_DATA_SIZE]
#define __END_READ_DATA__
Definition: sensor_drv.h:51
#define FXLS8962_SENS_CONFIG3_WAKE_ODR_6_25HZ
Definition: fxls8962.h:566
fxos8700_accelmagdata_t rawData
const registerreadlist_t cFxls8962OutputNormal[]
Address of Raw Accel Data in Normal Mode.
int32_t FXLS8962_SPI_Configure(fxls8962_spi_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: fxls8962_drv.c:131
uint16_t readFrom
Definition: sensor_drv.h:80
int32_t FXLS8962_SPI_Initialize(fxls8962_spi_sensorhandle_t *pSensorHandle, ARM_DRIVER_SPI *pBus, uint8_t index, void *pSlaveSelect, uint8_t *whoami)
The interface function to initialize the sensor.
Definition: fxls8962_drv.c:68
void BOARD_SystickEnable(void)
Function to enable systicks framework.
Definition: systick_utils.c:35
This structure defines the Read command List.
Definition: sensor_drv.h:78
ARM Systick Utilities.
#define SPI_S_DRIVER
Definition: frdm_k64f.h:87
#define FXLS8962_SENS_CONFIG1_FSR_MASK
Definition: fxls8962.h:423
#define FXLS8974_WHOAMI_VALUE
Definition: fxls8962.h:90
#define FXLS8962_DATA_SIZE
#define SPI_S_SIGNAL_EVENT
Definition: frdm_k64f.h:90
void BOARD_InitDebugConsole(void)
Definition: board.c:15
#define FXLS8962_WHOAMI_VALUE
Definition: fxls8962.h:87
#define FXLS8962_CS
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
volatile bool gFxls8962DataReady
const registerwritelist_t cFxls8962ConfigNormal[]
Register settings for Normal (non buffered) mode.