embedded-software
reusable software modules for embedded systems
|
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... | |
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)
following macros should be defined project_settings #define I2C_MAX_TX_SIZE 2 #define I2C_MAX_RX_SIZE 6
void Accelerometer_Deinit | ( | void | ) |
Deinitialize the accelerometer task scheduler.
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.
period | period to check data from accelerometer (milliseconds) |
period | function pointer for callback where data is returned |
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