mma7455 library  v0.85
MMA7455 3-Axis Accelerometer configuration and measurement functions. Currently supports SPI only.
Macros | Functions | Variables
mma7455.h File Reference

Simplifies reading Parallax MMA7455 3-Axis Accelerometer Module. More...

#include "simpletools.h"

Go to the source code of this file.

Macros

#define MMA7455_XOUTL   0x00
#define MMA7455_XOUTH   0x01
#define MMA7455_YOUTL   0x02
#define MMA7455_YOUTH   0x03
#define MMA7455_ZOUTL   0x04
#define MMA7455_ZOUTH   0x05
#define MMA7455_XOUT8   0x06
#define MMA7455_YOUT8   0x07
#define MMA7455_ZOUT8   0x08
#define MMA7455_STATUS   0x09
#define MMA7455_DETSRC   0x0A
#define MMA7455_TOUT   0x0B
#define MMA7455_I2CAD   0x0D
#define MMA7455_USRINF   0x0E
#define MMA7455_WHOAMI   0x0F
#define MMA7455_XOFFL   0x10
#define MMA7455_XOFFH   0x11
#define MMA7455_YOFFL   0x12
#define MMA7455_YOFFH   0x13
#define MMA7455_ZOFFL   0x14
#define MMA7455_ZOFFH   0x15
#define MMA7455_MCTL   0x16
#define MMA7455_INTRST   0x17
#define MMA7455_CTL1   0x18
#define MMA7455_CTL2   0x19
#define MMA7455_LDTH   0x1A
#define MMA7455_PDTH   0x1B
#define MMA7455_PW   0x1C
#define MMA7455_LT   0x1D
#define MMA7455_TW   0x1E
#define MMA7455_STANDBY   0b00
#define MMA7455_MEASUREMENT   0b01
#define MMA7455_LEVEL_DETECT   0b10
#define MMA7455_PULSE_DETECT   0b11

Functions

void MMA7455_init (int pinData, int pinClock, int pinEnable)
 Initialize the sensor.
void MMA7455_getxyz8 (signed char *x, signed char *y, signed char *z)
 Get 8 bit x, y, and z axis measurements.
void MMA7455_getxyz10 (signed short *x, signed short *y, signed short *z)
 Get 10 bit x, y, and z axis measurements.
void MMA7455_setOffsetX (signed short offset)
 Set value automatically added to X value measurement. Start with value that's twice the zero offset error, and repeat the test. It may take a several iterations.
void MMA7455_setOffsetY (signed short offset)
 Set value automatically added to Y value measurement. Start with value that's twice the zero offset error, and repeat the test. It may take a several iterations.
void MMA7455_setOffsetZ (signed short offset)
 Set value automatically added to Z value measurement. Start with value that's twice the zero offset error, and repeat the test. It may take a several iterations.
unsigned char MMA7455_getMode ()
 Get the mode of operation: (0) standby, (1) measurement, (2) level error detection, (3) pulse impact detection.
void MMA7455_setMode (unsigned char mode)
 Set the mode of operation: (0) standby, (1) measurement, (2) level error detection, (3) pulse impact detection.
void MMA7455_gRange (unsigned char range)
 Set the g measurement range to +/- 2, +/-4, or +/- 8 g.
void MMA7455_writeByte (unsigned char address, unsigned char value)
 write a byte value to an MMA7455 register
unsigned char MMA7455_readByte (unsigned char address)
 Read a value from an MMA7455 register.

Variables

int MMA7455_pinDat
int MMA7455_pinClk
int MMA7455_pinEn
int MMA7455_gRangeVal

Detailed Description

Simplifies reading Parallax MMA7455 3-Axis Accelerometer Module.

Author
Andy Lindsay
Version
0.5

Macro Definition Documentation

#define MMA7455_CTL1   0x18

MMA7455 CTL1 Register = 0x18.

#define MMA7455_CTL2   0x19

MMA7455 CTL2 Register = 0x19.

#define MMA7455_DETSRC   0x0A

MMA7455 DETSRC Register = 0x0A.

#define MMA7455_I2CAD   0x0D

MMA7455 I2CAD Register = 0x0D.

#define MMA7455_INTRST   0x17

MMA7455 INTRST Register = 0x17.

#define MMA7455_LDTH   0x1A

MMA7455 LDTH Register = 0x1A.

#define MMA7455_LEVEL_DETECT   0b10

MMA7455_LEVEL_DETECT can be used with the MMA7455_setMode and getMode functions. Its value is 2, the level detect mode value.

#define MMA7455_LT   0x1D

MMA7455 LT Register = 0x1D.

#define MMA7455_MCTL   0x16

MMA7455 MCTL Register = 0x16.

#define MMA7455_MEASUREMENT   0b01

MMA7455_MEASUREMENT can be used with the MMA7455_setMode and getMode functions. Its value is 1, the measurement mode value.

#define MMA7455_PDTH   0x1B

MMA7455 PDTH Register = 0x1B.

#define MMA7455_PULSE_DETECT   0b11

MMA7455_PULSE_DETECT can be used with the MMA7455_setMode and getMode functions. Its value is 3, the pulse detect mode value.

#define MMA7455_PW   0x1C

MMA7455 PW Register = 0x1C.

#define MMA7455_STANDBY   0b00

MMA7455_STANDBY can be used with the MMA7455_setMode and getMode functions. Its value is 0, the standby mode value.

#define MMA7455_STATUS   0x09

MMA7455 STATUS Register = 0x09.

#define MMA7455_TOUT   0x0B

MMA7455 TOUT Register = 0x0B.

#define MMA7455_TW   0x1E

MMA7455 TW Register = 0x1E.

#define MMA7455_USRINF   0x0E

MMA7455 USRINF Register = 0x0E.

#define MMA7455_WHOAMI   0x0F

MMA7455 WHOAMI Register = 0x0F.

#define MMA7455_XOFFH   0x11

MMA7455 XOFFH Register = 0x11.

#define MMA7455_XOFFL   0x10

MMA7455 XOFFL Register = 0x10.

#define MMA7455_XOUT8   0x06

MMA7455 XOUT8 Register = 0x06.

#define MMA7455_XOUTH   0x01

MMA7455 XOUTH Register = 0x01.

#define MMA7455_XOUTL   0x00

MMA7455 XOUTL Register = 0x00.

#define MMA7455_YOFFH   0x13

MMA7455 YOFFH Register = 0x13.

#define MMA7455_YOFFL   0x12

MMA7455 YOFFL Register = 0x12.

#define MMA7455_YOUT8   0x07

MMA7455 YOUT8 Register = 0x07.

#define MMA7455_YOUTH   0x03

MMA7455 YOUTH Register = 0x03.

#define MMA7455_YOUTL   0x02

MMA7455 YOUTL Register = 0x02.

#define MMA7455_ZOFFH   0x15

MMA7455 ZOFFH Register = 0x15.

#define MMA7455_ZOFFL   0x14

MMA7455 ZOFFL Register = 0x14.

#define MMA7455_ZOUT8   0x08

MMA7455 ZOUT8 Register = 0x08.

#define MMA7455_ZOUTH   0x05

MMA7455 ZOUTH Register = 0x05.

#define MMA7455_ZOUTL   0x04

MMA7455 ZOUTL Register = 0x04.

Function Documentation

unsigned char MMA7455_getMode ( )

Get the mode of operation: (0) standby, (1) measurement, (2) level error detection, (3) pulse impact detection.

Returns
mode Value from 0 to 3.
void MMA7455_getxyz10 ( signed short *  x,
signed short *  y,
signed short *  z 
)

Get 10 bit x, y, and z axis measurements.

Parameters
*xAddress pointer to a signed short x variable.
*yAddress pointer to a signed short y variable.
*zAddress pointer to a signed short z variable.
void MMA7455_getxyz8 ( signed char *  x,
signed char *  y,
signed char *  z 
)

Get 8 bit x, y, and z axis measurements.

Parameters
*xAddress pointer to a signed char x variable.
*yAddress pointer to a signed char y variable.
*zAddress pointer to a signed char z variable.
void MMA7455_gRange ( unsigned char  range)

Set the g measurement range to +/- 2, +/-4, or +/- 8 g.

Parameters
rangeValid range values are 2, 4, and 8.
void MMA7455_init ( int  pinData,
int  pinClock,
int  pinEnable 
)

Initialize the sensor.

Parameters
pinDataI/O pin connected to the DATA pin.
pinClockI/O pin connected to the CLK pin.
pinEnableI/O pin connected to the /ENABLE pin.
unsigned char MMA7455_readByte ( unsigned char  address)

Read a value from an MMA7455 register.

Parameters
addressMMA7455 register address.
Returns
Value stored by the MMA7455 register.
void MMA7455_setMode ( unsigned char  mode)

Set the mode of operation: (0) standby, (1) measurement, (2) level error detection, (3) pulse impact detection.

Parameters
modeValue from 0 to 3.
void MMA7455_setOffsetX ( signed short  offset)

Set value automatically added to X value measurement. Start with value that's twice the zero offset error, and repeat the test. It may take a several iterations.

Parameters
offsetTwice the value you want the chip to add to the x axis measurement
void MMA7455_setOffsetY ( signed short  offset)

Set value automatically added to Y value measurement. Start with value that's twice the zero offset error, and repeat the test. It may take a several iterations.

Parameters
offsetTwice the value you want the chip to add to the y axis measurement
void MMA7455_setOffsetZ ( signed short  offset)

Set value automatically added to Z value measurement. Start with value that's twice the zero offset error, and repeat the test. It may take a several iterations.

Parameters
offsetTwice the value you want the chip to add to the z axis measurement
void MMA7455_writeByte ( unsigned char  address,
unsigned char  value 
)

write a byte value to an MMA7455 register

Parameters
addressMMA7455 register address.
valueConfiguration value for the register.

Variable Documentation

int MMA7455_gRangeVal

Global variable for MMA7455 module's current gravity range setting.

int MMA7455_pinClk

Global variable for I/O pinconnected to MMA7455 module's CLK pin.

int MMA7455_pinDat

Global variable for I/O pinconnected to MMA7455 module's DATA pin.

int MMA7455_pinEn

Global variable for I/O pinconnected to MMA7455 module's /CS pin.