Nol.A SDK Library 26.11.2
For IoT System Software Development
Loading...
Searching...
No Matches
MMA8452Q Class Reference

MMA8452Q accelerometer register driver with optional interrupt GPIOs. Initialize the I2C bus before begin(); communication errors are not reported. More...

#include <MMA8452Q.hpp>

Public Types

enum  ODR_t {
  ODR_800Hz = 0 , ODR_400Hz = 1 , ODR_200Hz = 2 , ODR_100Hz = 3 ,
  ODR_50Hz = 4 , ODR_12p5Hz = 5 , ODR_6p25Hz = 6 , ODR_1p56Hz = 7
}
 Output data rate selections in hertz. More...
enum  Mode_t { MODE_NORMAL = 0 , MODE_LOW_NOISE_LOW_POWER = 1 , MODE_HIGH_RESOLUTION = 2 , MODE_LOW_POWER = 3 }
 Sampling power/noise mode selections. More...

Public Member Functions

void begin (TwoWire &wire, uint8_t addr, int8_t pinInt1=-1, int8_t pinInt2=-1)
 Bind the bus/address and attach falling-edge interrupt handlers.
uint8_t readSensorId ()
 Return the WHO_AM_I register byte.
void readXYZ (int16_t *x, int16_t *y, int16_t *z)
 Read and assemble signed axis register values without conversion to g.
bool isActive ()
 Return the ACTIVE bit from the control register.
void setActive ()
 Set the ACTIVE bit to enable measurements.
void setStandby ()
 Clear the ACTIVE bit to enter standby.
ODR_t getODR ()
 Return the configured output data rate.
void setODR (ODR_t val)
 Set the output data rate, temporarily entering standby if needed.
void onDetectTransient (void(*func)(MMA8452Q &))
 Register the transient interrupt callback; nullptr disables notification.
void setTransientDetection (bool enableX, bool enableY, bool enableZ, uint16_t thresholdMilliG, uint32_t durationMicros)
 Configure transient detection and restore the previous active state.
void setMode (Mode_t)
 Write the sampling power/noise mode; put the sensor in standby first.
Mode_t getMode ()
 Return the configured sampling power/noise mode.

Detailed Description

MMA8452Q accelerometer register driver with optional interrupt GPIOs. Initialize the I2C bus before begin(); communication errors are not reported.

Author
Jongsoo Jeong (CoXlab)
Date
2016. 6. 13.
Examples
nordic-nrf52-dk/MMA8452Q-3-axis/main.cpp.

Member Enumeration Documentation

◆ Mode_t

Sampling power/noise mode selections.

129 {
130 MODE_NORMAL = 0,
131 MODE_LOW_NOISE_LOW_POWER = 1,
132 MODE_HIGH_RESOLUTION = 2,
133 MODE_LOW_POWER = 3,
134 } Mode_t;
Mode_t
Sampling power/noise mode selections.
Definition MMA8452Q.hpp:129

◆ ODR_t

Output data rate selections in hertz.

89 {
90 ODR_800Hz = 0,
91 ODR_400Hz = 1,
92 ODR_200Hz = 2,
93 ODR_100Hz = 3,
94 ODR_50Hz = 4,
95 ODR_12p5Hz = 5,
96 ODR_6p25Hz = 6,
97 ODR_1p56Hz = 7,
98 } ODR_t;
ODR_t
Output data rate selections in hertz.
Definition MMA8452Q.hpp:89

Member Function Documentation

◆ begin()

void MMA8452Q::begin ( TwoWire & wire,
uint8_t addr,
int8_t pinInt1 = -1,
int8_t pinInt2 = -1 )

Bind the bus/address and attach falling-edge interrupt handlers.

Parameters
wireInitialized I2C bus that outlives the driver.
addr7-bit sensor address.
pinInt1Optional INT1 GPIO; -1 disables attachment.
pinInt2Optional INT2 GPIO; -1 disables attachment.
Examples
nordic-nrf52-dk/MMA8452Q-3-axis/main.cpp.

◆ onDetectTransient()

void MMA8452Q::onDetectTransient ( void(* func )(MMA8452Q &))

Register the transient interrupt callback; nullptr disables notification.

Parameters
funcReceives this driver when a transient interrupt is handled.

◆ readXYZ()

void MMA8452Q::readXYZ ( int16_t * x,
int16_t * y,
int16_t * z )

Read and assemble signed axis register values without conversion to g.

Parameters
xOptional X output; nullptr skips storing it.
yOptional Y output; nullptr skips storing it.
zOptional Z output; nullptr skips storing it. The current implementation combines each high byte shifted by four with the unshifted low byte, then sign-extends bit 11; it does not normalize the low byte.
Examples
nordic-nrf52-dk/MMA8452Q-3-axis/main.cpp.

◆ setODR()

void MMA8452Q::setODR ( ODR_t val)

Set the output data rate, temporarily entering standby if needed.

Parameters
valOutput data rate selection.
Examples
nordic-nrf52-dk/MMA8452Q-3-axis/main.cpp.

◆ setTransientDetection()

void MMA8452Q::setTransientDetection ( bool enableX,
bool enableY,
bool enableZ,
uint16_t thresholdMilliG,
uint32_t durationMicros )

Configure transient detection and restore the previous active state.

Parameters
enableXRequested X-axis enable; currently not applied independently (X follows enableZ).
enableYEnable Y-axis transient detection.
enableZEnable Z-axis detection; also controls X in the current implementation.
thresholdMilliGThreshold in milli-g, clamped to 8000 and quantized in 63 milli-g steps.
durationMicrosDuration in microseconds, clamped and quantized for the current mode/rate.

The documentation for this class was generated from the following file: