embedded-software
reusable software modules for embedded systems
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Accelerometer module

Functions

int8_t Accelerometer_Init (uint16_t period, void(*callback)(float x, float y, float z))
 Initialize the accelerometer to read data at a period returning to a callback. More...
 
void Accelerometer_Deinit (void)
 Deinitialize the accelerometer task scheduler. More...
 

Detailed Description

Created on: March 25, 2019 Updated on: April 12, 2019 Author: Stephen Glass, Lonnie Souder

@ brief Code to read data from an accelerometer. Designed for SparkFun Triple Axis Accelerometer Breakout (MMA8452Q)

Author
Stephen Glass
Lonnie Souder
Version
1.0

following macros should be defined project_settings #define I2C_MAX_TX_SIZE 2 #define I2C_MAX_RX_SIZE 6

Function Documentation

void Accelerometer_Deinit ( void  )

Deinitialize the accelerometer task scheduler.

Here is the call graph for this function:

int8_t Accelerometer_Init ( uint16_t  period,
void(*)(float x, float y, float z)  callback 
)

Initialize the accelerometer to read data at a period returning to a callback.

Parameters
periodperiod to check data from accelerometer (milliseconds)
periodfunction pointer for callback where data is returned
Returns
returns success of initialization, (< 0 is error)

Initialize I2C communication with accelerometer

Configure base transaction configuration

Start read of WHO_AM_I register to check if device is online We write the register we want to read in first transaction, while keeping connection active The next transaction we read the value from the previous register and terminate the connection

Reading WHO_AM_I always returns DEVICE_FOUND

Put into STANDBY mode Registers can only be changed on accelerometer while in STANDBY mode Read the CTRL_REG1 value and then write the negated value to CTRL_REG1

Configure scale

Put into ACTIVE mode Read the CTRL_REG1 value and then write the enabled value to CTRL_REG1

Assign callback pointer to data structure

Schedule task to read data

Here is the call graph for this function: