17 #include "clock_config.h" 19 #include "fsl_lptmr.h" 20 #include "fsl_debug_console.h" 23 #include "Driver_SPI.h" 26 #include "issdk_hal.h" 27 #include "gpio_driver.h" 34 #define SAMPLING_RATE_ms (100) 35 #define MMA9553_ACCEL_DATA_SIZE (6) 36 #define mma9553_en_callback LPTMR0_IRQHandler 37 #define MMA9553_SSB_IO3 D10 74 LPTMR_ClearStatusFlags(LPTMR0, kLPTMR_TimerCompareFlag);
84 lptmr_config_t lptmrConfig;
98 LPTMR_GetDefaultConfig(&lptmrConfig);
99 LPTMR_Init(LPTMR0, &lptmrConfig);
100 LPTMR_EnableInterrupts(LPTMR0, kLPTMR_TimerInterruptEnable);
101 LPTMR_SetTimerPeriod(LPTMR0, MSEC_TO_COUNT(
SAMPLING_RATE_ms, CLOCK_GetFreq(kCLOCK_LpoClk)));
102 EnableIRQ(LPTMR0_IRQn);
104 PRINTF(
"\r\n ISSDK MMA9553 sensor driver example for Pedometer Mode. \r\n");
108 if (ARM_DRIVER_OK != status)
110 PRINTF(
"\r\n SPI Initialization Failed\r\n");
115 status = pSPIdriver->PowerControl(ARM_POWER_FULL);
116 if (ARM_DRIVER_OK != status)
118 PRINTF(
"\r\n SPI Power Mode setting Failed\r\n");
123 status = pSPIdriver->Control(ARM_SPI_MODE_MASTER | ARM_SPI_CPOL0_CPHA0,
SPI_S_BAUDRATE);
124 if (ARM_DRIVER_OK != status)
126 PRINTF(
"\r\n SPI Control Mode setting Failed\r\n");
134 PRINTF(
"\r\n Sensor Initialization Failed\r\n");
137 PRINTF(
"\r\n Successfully Initialized Sensor. \r\n");
148 PRINTF(
"\r\n MMA9553 Sensor Configuration Failed, Err = %d \r\n", status);
152 LPTMR_StartTimer(LPTMR0);
153 PRINTF(
"\r\n Successfully Applied MMA9553 Sensor Configuration\r\n");
168 (uint8_t *)&pedometerData);
169 if (ARM_DRIVER_OK != status)
171 PRINTF(
"\r\n Read Failed. \r\n");
176 pedometerData.statusRegister = (pedometerData.statusRegister >> 8) | (pedometerData.statusRegister << 8);
177 pedometerData.stepCount = (pedometerData.stepCount >> 8) | (pedometerData.stepCount << 8);
178 pedometerData.distance = (pedometerData.distance >> 8) | (pedometerData.distance << 8);
179 pedometerData.speed = (pedometerData.speed >> 8) | (pedometerData.speed << 8);
180 pedometerData.calories = (pedometerData.calories >> 8) | (pedometerData.calories << 8);
181 pedometerData.sleepCount = (pedometerData.sleepCount >> 8) | (pedometerData.sleepCount << 8);
183 PRINTF(
"\r\n Steps = %d Distance = %dm Speed = %dm/h Calories = %d \r\n", pedometerData.stepCount,
184 pedometerData.distance, pedometerData.speed, pedometerData.calories);
188 if (ARM_DRIVER_OK != status)
190 PRINTF(
"\r\n Read Failed. \r\n");
194 PRINTF(
"\r\n Accel X = %d Y = %d Z = %d \r\n", rawData.
accel[0], rawData.
accel[1], rawData.
accel[2]);
#define ASK_USER_TO_RESUME(x)
const uint8_t SetSampleRate_30Hz[5]
int32_t MMA9553_SPI_Configure(mma9553_spi_sensorhandle_t *pSensorHandle, const registercommandlist_t *pCommandList)
The interface function to configure he sensor.
const registerreadlist_t cMma9553ReadRawOutput[]
status_t SMC_SetPowerModeVlpr(void *arg)
Configures the system to VLPR power mode. API name used from Kinetis family to maintain compatibility...
const uint8_t ReadPedometerData[4]
Command to Read Pedometer Data.
This structure defines the Size of response for pedometer data read command.
This structure defines the Block command List.
This defines the sensor specific information for SPI.
int32_t MMA9553_SPI_Initialize(mma9553_spi_sensorhandle_t *pSensorHandle, ARM_DRIVER_SPI *pBus, uint8_t index, void *pSlaveSelect, void *pReset)
The interface function to initialize the sensor.
int main(void)
Main function.
#define MMA9553_ACCEL_DATA_SIZE
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
#define SPI_S_BAUDRATE
Transfer baudrate - 500k.
The mma9553_drv.h file describes the MMA9553L driver interface and structures.
const registercommandlist_t cMma9553Config30Hz[]
This structure defines the mma9553 pedometer data buffer.
const registerreadlist_t cMma9553ReadPedometerOutput[]
const registercommandlist_t cMma9553ReadPedometerCommand[]
#define SPI_S_DEVICE_INDEX
const uint8_t SetFSRange_2g[5]
Full-Scale Range Selections.
#define MMA9553_XYZ_DATA_OFFSET
XYZ Data Register Offset.
#define BOARD_BootClockRUN
const uint8_t SetAFEPriority_for30Hz[5]
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
#define __END_READ_DATA__
#define __END_WRITE_CMD__
volatile bool gMma9553DataReady
fxos8700_accelmagdata_t rawData
void MMA9553_SPI_SetIdleTask(mma9553_spi_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the SPI Idle Task.
const uint8_t SetMBoxPriority_for30Hz[5]
void BOARD_SystickEnable(void)
Function to enable systicks framework.
int32_t MMA9553_SPI_CommandResponse(mma9553_spi_sensorhandle_t *pSensorHandle, const registercommandlist_t *pCommandList, const registerreadlist_t *pResponseList, uint8_t *pBuffer)
The interface function to read the sensor data.
This structure defines the Read command List.
#define mma9553_en_callback
#define SPI_S_SIGNAL_EVENT
void BOARD_InitDebugConsole(void)
void BOARD_InitPins(void)
Configures pin routing and optionally pin electrical features.