ISSDK  1.8
IoT Sensing Software Development Kit
dbap_app.c
Go to the documentation of this file.
1 /*
2  * Copyright 2020 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 /**
9  * @file dbap_app.c
10  * @brief The dbap_app.c file implements the DBAP sensor driver example
11  *
12  */
13 
14 //-----------------------------------------------------------------------
15 // SDK Includes
16 //-----------------------------------------------------------------------
17 #include "pin_mux.h"
18 #include "clock_config.h"
19 #include "board.h"
20 #include "fsl_debug_console.h"
21 #include "systick_utils.h"
22 #include "issdk_hal.h"
23 //-----------------------------------------------------------------------
24 // CMSIS Includes
25 //-----------------------------------------------------------------------
26 #include "Driver_I2C.h"
27 #include "dbap_drv.h"
28 //-----------------------------------------------------------------------
29 // Macros
30 //-----------------------------------------------------------------------
31 #define FXPS7250D4 1
32 #define DBAP_I2C_ADDR 0x60
33 #define DBAP_DATA_SIZE 0x3
34 #define TO_LSB 68
35 #define TO_SEN 1
36 #if FXPS7250D4
37 #define PABSOffLSB 28661.6
38 #define PABSSENS 30.42
39 #elif FXPS7115D4
40 #define PABSOffLSB 25538.8
41 #define PABSSENS 69.96
42 #elif FXPS7550D4
43 #define PABSOffLSB 28990
44 #define PABSSENS 14
45 #else
46 #define PABSOffLSB 28661.6
47 #define PABSSENS 30.42
48 #endif
49 //-----------------------------------------------------------------------
50 // Constants
51 //-----------------------------------------------------------------------
52 
53 /*! @brief Register settings for confirmation. */
57 
58 /*! @brief Address of Part Number */
60  {.readFrom = FXPS7250_PN0, .numBytes = 2},
61  //{.readFrom = FXPS7250_P_CAL_ZERO_H, .numBytes = 1},
63 
64 /*! @brief Address and size of Raw Pressure data and TemperatureData */
66  {.readFrom = FXPS7250_SNSDATA0_L, .numBytes = 2},
67  //{.readFrom = FXPS7250_SNSDATA0_H, .numBytes = 1},
68  {.readFrom = FXPS7250_TEMPERATURE, .numBytes = 1},
70 
71 /*! @brief Address of Device Status */
73  {.readFrom = FXPS7250_DEVSTAT_COPY, .numBytes = 1},
75 //-----------------------------------------------------------------------
76 // Functions
77 //-----------------------------------------------------------------------
78 /*!
79  * @brief Main function
80  */
81 int main(void)
82 {
84  int8_t tempInDegrees;
85  float pressureKPa;
87  uint16_t partNumber;
88  uint8_t deviceStatus, data[DBAP_DATA_SIZE];
89  uint8_t data_part[11];
90  dbap_i2c_sensorhandle_t dbapDriver;
91  ARM_DRIVER_I2C *I2Cdrv = &I2C_S_DRIVER;
92 
97 
98  PRINTF("\r\n DBAP Sensor Example !\r\n");
99 
100  /*! Initialize the I2C driver. */
101  status = I2Cdrv->Initialize(I2C_S_SIGNAL_EVENT);
102  if (ARM_DRIVER_OK != status)
103  {
104  PRINTF("\r\n I2C Initialization Failed.\r\n");
105  return -1;
106  }
107 
108  /*! Set the I2C Power mode. */
109  status = I2Cdrv->PowerControl(ARM_POWER_FULL);
110  if (ARM_DRIVER_OK != status)
111  {
112  PRINTF("\r\n I2C Power Mode setting Failed.\r\n");
113  return -1;
114  }
115 
116  /*! Set the I2C bus speed. */
117  status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
118  if (ARM_DRIVER_OK != status)
119  {
120  PRINTF("\r\n I2C Control Mode setting Failed.\r\n");
121  return -1;
122  }
123 
126  if (SENSOR_ERROR_NONE == status)
127  {
128  PRINTF("\r\n Initiliazed DBAP Sensor with WHO_AM_I = [0x%X].\r\n", FXPS7250D4_WHOAMI_VALUE);
129  }
130  DBAP_I2C_ReadData(&dbapDriver, cDBAPPartNumber, data_part);
131  partNumber = (data_part[0]<<8)|data_part[1];
132  PRINTF("\r\n DBAP Part Number = [0x%X].\r\n", partNumber);
133 
134  /*! Set the task to be executed while waiting for I2C transactions to complete. */
136 
137  /*! Configure the DBAP sensor. */
138  status = DBAP_I2C_Configure(&dbapDriver, cDBAPConfig);
139  if (SENSOR_ERROR_NONE != status)
140  {
141  PRINTF("\r\nDBAP now active and entering data read loop...\r\n");
142  return -1;
143  }
144  for (;;) /* Forever loop */
145  {
146  /* Read sensor status register */
147  status = DBAP_I2C_ReadData(&dbapDriver, cDBAPDeviceStatus, &deviceStatus);
148  if (ARM_DRIVER_OK != status)
149  {
150  PRINTF("\r\n Read Failed. \r\n");
151  return -1;
152  }
153 
154  /*! Read new raw sensor data from the DBAP. */
155  status = DBAP_I2C_ReadData(&dbapDriver, cDBAPPTData, data);
156  if (ARM_DRIVER_OK != status)
157  {
158  PRINTF("\r\n Read Failed. \r\n");
159  return -1;
160  }
161 
162  /*! Process the sample and convert the raw sensor data. */
163  rawData.pressure = ((uint16_t)(data[1]) << 8) | data[0];
164  pressureKPa = (rawData.pressure - PABSOffLSB ) / PABSSENS;
165 
166  rawData.temperature = (int8_t)(data[2]);
167  tempInDegrees = (rawData.temperature - TO_LSB)/TO_SEN;
168 
169 
170  PRINTF("\r\n Raw Pressure = %d \r\n", rawData.pressure);
171  PRINTF("\r\n Pressure = %0.3f KPa", pressureKPa);
172  PRINTF("\r\n Temperature = %d in degree\r\n", tempInDegrees);
173 
174  ASK_USER_TO_RESUME(50); /* Ask for user input after processing 50 samples. */
175  }
176 }
const registerreadlist_t cDBAPPartNumber[]
Address of Part Number.
Definition: dbap_app.c:59
int32_t DBAP_I2C_ReadData(dbap_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: dbap_drv.c:86
#define TO_SEN
Definition: dbap_app.c:35
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 PABSSENS
Definition: dbap_app.c:38
This defines the sensor specific information for I2C.
Definition: dbap_drv.h:33
#define DBAP_DATA_SIZE
Definition: dbap_app.c:33
void DBAP_I2C_SetIdleTask(dbap_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: dbap_drv.c:53
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
int8_t temperature
Definition: dbap_drv.h:46
int main(void)
Main function.
Definition: dbap_app.c:81
const registerwritelist_t cDBAPConfig[]
Register settings for confirmation.
Definition: dbap_app.c:54
The dbap_drv.h file describes the DBAP driver interface and structures.
#define SMC
Definition: lpc54114.h:118
#define FXPS7250D4_WHOAMI_VALUE
Definition: dbap.h:15
#define TO_LSB
Definition: dbap_app.c:34
#define __END_WRITE_DATA__
Definition: sensor_drv.h:45
#define DBAP_I2C_ADDR
Definition: dbap_app.c:32
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
#define I2C_S_DRIVER
Definition: issdk_hal.h:33
#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
const registerreadlist_t cDBAPPTData[]
Address and size of Raw Pressure data and TemperatureData.
Definition: dbap_app.c:65
uint8_t data[FXLS8962_DATA_SIZE]
#define FXPS7250_DSP_CFG_U1_LPF_MASK
Definition: dbap.h:735
#define __END_READ_DATA__
Definition: sensor_drv.h:51
ARM_DRIVER_I2C * I2Cdrv
fxos8700_accelmagdata_t rawData
uint16_t readFrom
Definition: sensor_drv.h:80
uint16_t pressure
Definition: dbap_drv.h:45
int32_t DBAP_I2C_Initialize(dbap_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: dbap_drv.c:21
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 FXPS7250_DSP_CFG_U1_LPF_370HZ_2POLE
Definition: dbap.h:741
This structure defines the dbap data buffer in Pressure Mode.
Definition: dbap_drv.h:42
#define I2C_S_DEVICE_INDEX
Definition: issdk_hal.h:35
const registerreadlist_t cDBAPDeviceStatus[]
Address of Device Status.
Definition: dbap_app.c:72
void BOARD_InitDebugConsole(void)
Definition: board.c:15
int32_t DBAP_I2C_Configure(dbap_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: dbap_drv.c:59
void BOARD_InitPins(void)
Configures pin routing and optionally pin electrical features.
Definition: pin_mux.c:47
#define PABSOffLSB
Definition: dbap_app.c:37