© Freescale Semiconductor, Inc., 2010. All rights reserved.
AN4076
Rev 0, 09/2010
Freescale Semiconductor
Application Note
Data Manipulation and Basic Settings of the
MMA8451, 2, 3Q
by:
Kimberly Tuck
Applications Engineer
1.0 Introduction
It is important to understand how to program the MMA8451,
2, 3Q to extract and manipulate the acceleration data. These
devices have been designed to be compatible with a shared
memory map. For details on the differences of the embedded
features please review our selector guide. The MMA8451Q
has the most embedded features which include eight different
sample rates, 32 different cut-off frequencies for the high pass
filter, 3 dynamic ranges and four oversampling modes. It also
has a 32 sample FIFO for collecting and storing data, which is
the most efficient way to access the data for minimizing the
I
2
C transactions. The FIFO can collect the regular low pass
filtered data as well as the data from the high pass filter. The
manipulation of the data into different formats is important for
algorithm development and for display. This application note
accompanies the MMA8451, 2, 3Q Driver Code and will
explain the following:
• Changing the operational modes (Standby, Active 2g,
Active 4g and Active 8g)
• Changing Oversampling Modes
• Changing the Data Rate
• Changing the High Pass Filter Cut-off Frequency
• 8-bit data vs. 14/12/10-bit data
• Changing Data Formats (hex to counts to decimal
numbers)
• Streaming XYZ data polling vs. Streaming XYZ data with
interrupts
• Using the FIFO in the MMA8451Q
1.1 Key Words
Accelerometer, Output Data Rate, Standby Mode, Active
Mode, High Pass Filter Cut-off Frequency, 8-bit Data, 14-bit
Data, 12-bit Data, 10-bit Data Hexadecimal Numbers,
Decimal Numbers, Data Formats, Streaming Data, Counts,
Polling, Interrupts, FIFO Data, Flush, Sensor Toolbox Demo
Board, Driver Code, High Pass Filtered Data, Low Pass
Filtered Data
TABLE OF CONTENTS
1.0 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
1.1 Key Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
1.2 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.0 MMA845xQ Consumer 3-axis Accelerometers 3 mm x 3 mm x 1 mm . . 2
2.1 Output Data, Sample Rates and Dynamic Ranges of all Three Products . . .3
2.1.1 MMA8451Q . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3
2.1.2 MMA8452Q . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3
2.1.3 MMA8453Q Note: No HPF Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3
2.2 Application Notes for the MMA8451, 2, 3Q . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.0 Changing Modes of the MMA8451, 2, 3Q . . . . . . . . . . . . . . . . . . . . . . . . .4
3.1 Standby and Active Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.2 2g Active Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.3 4g Active Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.4 8g Active Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4.0 Setting the Data Rate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6
5.0 Setting the Oversampling Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7
6.0 Setting the High Pass Filter Cut-off Frequency . . . . . . . . . . . . . . . . . . . .9
6.1 High Pass Filtered Data or Low Pass Filtered Data . . . . . . . . . . . . . . . . . . . 10
7.0 14-bit, 12-bit or 10-bit Data Streaming and Data Conversions. . . . . . . . 10
7.1 Converting 14-bit 2’s Complement Hex Number to Signed Integer (Counts)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
7.2 Converting 14-bit 2’s Complement Hex Number to Signed Decimal Fraction in
g’s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
7.2.1 2g Active Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
7.2.2 4g Active Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
7.2.3 8g Active Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
8.0 8-bit XYZ Data Streaming and Conversions . . . . . . . . . . . . . . . . . . . . . .17
8.1 Converting 8-bit 2’s Complement Hex Number to Signed Integer Number . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
8.2 Converting 8-bit 2’s Complement Hex Number to Signed Decimal Fraction in
g’s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
8.2.1 2g Active Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
9.0 Polling Data vs. Interrupts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20
9.1 Polling Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
9.2 Interrupt Routine to Access Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
10.0 Using the 32 Sample FIFO. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22
11.0 MMA845xQ Driver Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24