Loading...
Searching...
No Matches
MMA7660 Accelerometer

Driver for the Freescale MMA7660 3-Axis accelerometer. More...

Detailed Description

Driver for the Freescale MMA7660 3-Axis accelerometer.

This driver only implements basic functionality.

Files

file  mma7660.h
 Interface definition for the MMA7660 accelerometer driver.
 
file  mma7660_params.h
 Default configuration for MMA7660 accelerometer.
 
file  mma7660_reg.h
 Register definition for the MMA7660 accelerometer driver.
 

Data Structures

struct  mma7660_params_t
 Parameters for an MMA7660 device. More...
 
struct  mma7660_t
 Device descriptor for an MMA7660 device. More...
 
struct  mma7660_data_t
 Data type for the result data. More...
 

Enumerations

enum  {
  MMA7660_OK , MMA7660_I2C_ERR , MMA7660_I2C_READ_ERR , MMA7660_I2C_WRITE_ERR ,
  MMA7660_READ_ERR
}
 Return codes. More...
 

Functions

int mma7660_init (mma7660_t *dev, const mma7660_params_t *params)
 Initialize an MMA7660 device.
 
int mma7660_set_mode (const mma7660_t *dev, uint8_t active, uint8_t autowake, uint8_t autosleep, uint8_t prescale)
 Set the mode register.
 
int mma7660_read_tilt (const mma7660_t *dev, uint8_t *res)
 Read the tilt register.
 
int mma7660_write_sleep_count (const mma7660_t *dev, uint8_t sleep)
 Write the sleep count register.
 
int mma7660_config_interrupts (const mma7660_t *dev, uint8_t isource_flags)
 Configure the interrupt sources.
 
int mma7660_config_samplerate (const mma7660_t *dev, uint8_t amsr, uint8_t awsr, uint8_t filt)
 Configure the sample rate.
 
int mma7660_config_pdet (const mma7660_t *dev, uint8_t pdth, uint8_t enabled_axes)
 Configure the tap detection.
 
int mma7660_config_pd (const mma7660_t *dev, uint8_t pd)
 Configure the tap detection debounce count.
 
int mma7660_read (const mma7660_t *dev, mma7660_data_t *data)
 Read the acceleration counts converted to mG.
 
int mma7660_read_counts (const mma7660_t *dev, int8_t *x, int8_t *y, int8_t *z)
 Read the acceleration counts (unconverted)
 

MMA7660 constants

#define MODE_ACTIVE_SHIFT   (0U)
 
#define MODE_AUTOWAKE_SHIFT   (3U)
 
#define MODE_AUTOSLEEP_SHIFT   (4U)
 
#define MODE_PRESCALE_SHIFT   (5U)
 
#define MODE_INTERRUPT_DEFAULT   (0x40) /* Active low, push-pull */
 
#define MMA7660_INTSOURCE_NONE   (0x00)
 
#define MMA7660_INTSOURCE_FB   (0x01)
 
#define MMA7660_INTSOURCE_UDLR   (0x02)
 
#define MMA7660_INTSOURCE_TAP   (0x04)
 
#define MMA7660_INTSOURCE_AUTOSLEEP   (0x08)
 
#define MMA7660_INTSOURCE_MEASURE   (0x10)
 
#define MMA7660_INTSOURCE_SHX   (0x20)
 
#define MMA7660_INTSOURCE_SHY   (0x40)
 
#define MMA7660_INTSOURCE_SHZ   (0x80)
 
#define MMA7660_SR_AMPD   (0x00)
 
#define MMA7660_SR_AM64   (0x01)
 
#define MMA7660_SR_AM32   (0x02)
 
#define MMA7660_SR_AM16   (0x03)
 
#define MMA7660_SR_AM8   (0x04)
 
#define MMA7660_SR_AM4   (0x05)
 
#define MMA7660_SR_AM2   (0x06)
 
#define MMA7660_SR_AM1   (0x07)
 
#define MMA7660_SR_AW32   (0x00)
 
#define MMA7660_SR_AW16   (0x08)
 
#define MMA7660_SR_AW8   (0x10)
 
#define MMA7660_SR_AW1   (0x18)
 
#define MMA7660_PDET_X   (0x20)
 
#define MMA7660_PDET_Y   (0x40)
 
#define MMA7660_PDET_Z   (0x80)
 
#define MMA7660_ADDR   (0x4C)
 
#define MMA7660_MG_PER_COUNT   (47U)
 

Macro Definition Documentation

◆ MMA7660_ADDR

#define MMA7660_ADDR   (0x4C)

Definition at line 111 of file mma7660.h.

◆ MMA7660_INTSOURCE_AUTOSLEEP

#define MMA7660_INTSOURCE_AUTOSLEEP   (0x08)

Definition at line 89 of file mma7660.h.

◆ MMA7660_INTSOURCE_FB

#define MMA7660_INTSOURCE_FB   (0x01)

Definition at line 86 of file mma7660.h.

◆ MMA7660_INTSOURCE_MEASURE

#define MMA7660_INTSOURCE_MEASURE   (0x10)

Definition at line 90 of file mma7660.h.

◆ MMA7660_INTSOURCE_NONE

#define MMA7660_INTSOURCE_NONE   (0x00)

Definition at line 85 of file mma7660.h.

◆ MMA7660_INTSOURCE_SHX

#define MMA7660_INTSOURCE_SHX   (0x20)

Definition at line 91 of file mma7660.h.

◆ MMA7660_INTSOURCE_SHY

#define MMA7660_INTSOURCE_SHY   (0x40)

Definition at line 92 of file mma7660.h.

◆ MMA7660_INTSOURCE_SHZ

#define MMA7660_INTSOURCE_SHZ   (0x80)

Definition at line 93 of file mma7660.h.

◆ MMA7660_INTSOURCE_TAP

#define MMA7660_INTSOURCE_TAP   (0x04)

Definition at line 88 of file mma7660.h.

◆ MMA7660_INTSOURCE_UDLR

#define MMA7660_INTSOURCE_UDLR   (0x02)

Definition at line 87 of file mma7660.h.

◆ MMA7660_MG_PER_COUNT

#define MMA7660_MG_PER_COUNT   (47U)

Definition at line 116 of file mma7660.h.

◆ MMA7660_PDET_X

#define MMA7660_PDET_X   (0x20)

Definition at line 107 of file mma7660.h.

◆ MMA7660_PDET_Y

#define MMA7660_PDET_Y   (0x40)

Definition at line 108 of file mma7660.h.

◆ MMA7660_PDET_Z

#define MMA7660_PDET_Z   (0x80)

Definition at line 109 of file mma7660.h.

◆ MMA7660_SR_AM1

#define MMA7660_SR_AM1   (0x07)

Definition at line 102 of file mma7660.h.

◆ MMA7660_SR_AM16

#define MMA7660_SR_AM16   (0x03)

Definition at line 98 of file mma7660.h.

◆ MMA7660_SR_AM2

#define MMA7660_SR_AM2   (0x06)

Definition at line 101 of file mma7660.h.

◆ MMA7660_SR_AM32

#define MMA7660_SR_AM32   (0x02)

Definition at line 97 of file mma7660.h.

◆ MMA7660_SR_AM4

#define MMA7660_SR_AM4   (0x05)

Definition at line 100 of file mma7660.h.

◆ MMA7660_SR_AM64

#define MMA7660_SR_AM64   (0x01)

Definition at line 96 of file mma7660.h.

◆ MMA7660_SR_AM8

#define MMA7660_SR_AM8   (0x04)

Definition at line 99 of file mma7660.h.

◆ MMA7660_SR_AMPD

#define MMA7660_SR_AMPD   (0x00)

Definition at line 95 of file mma7660.h.

◆ MMA7660_SR_AW1

#define MMA7660_SR_AW1   (0x18)

Definition at line 106 of file mma7660.h.

◆ MMA7660_SR_AW16

#define MMA7660_SR_AW16   (0x08)

Definition at line 104 of file mma7660.h.

◆ MMA7660_SR_AW32

#define MMA7660_SR_AW32   (0x00)

Definition at line 103 of file mma7660.h.

◆ MMA7660_SR_AW8

#define MMA7660_SR_AW8   (0x10)

Definition at line 105 of file mma7660.h.

◆ MODE_ACTIVE_SHIFT

#define MODE_ACTIVE_SHIFT   (0U)

Definition at line 79 of file mma7660.h.

◆ MODE_AUTOSLEEP_SHIFT

#define MODE_AUTOSLEEP_SHIFT   (4U)

Definition at line 81 of file mma7660.h.

◆ MODE_AUTOWAKE_SHIFT

#define MODE_AUTOWAKE_SHIFT   (3U)

Definition at line 80 of file mma7660.h.

◆ MODE_INTERRUPT_DEFAULT

#define MODE_INTERRUPT_DEFAULT   (0x40) /* Active low, push-pull */

Definition at line 83 of file mma7660.h.

◆ MODE_PRESCALE_SHIFT

#define MODE_PRESCALE_SHIFT   (5U)

Definition at line 82 of file mma7660.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Return codes.

Enumerator
MMA7660_OK 

all ok

MMA7660_I2C_ERR 

i2c bus initialization error

MMA7660_I2C_READ_ERR 

i2c bus cannot be read

MMA7660_I2C_WRITE_ERR 

i2c bus cannot be written

MMA7660_READ_ERR 

error when reading counts

Definition at line 38 of file mma7660.h.

Function Documentation

◆ mma7660_config_interrupts()

int mma7660_config_interrupts ( const mma7660_t dev,
uint8_t  isource_flags 
)

Configure the interrupt sources.

Parameters
[in]devdevice descriptor
[in]isource_flagsinterrupt source flags
Returns
MMA7660_OK on success
-MMA7660_I2C_WRITE_ERR on i2c bus write error

◆ mma7660_config_pd()

int mma7660_config_pd ( const mma7660_t dev,
uint8_t  pd 
)

Configure the tap detection debounce count.

Parameters
[in]devdevice descriptor
[in]pdpulse debounce

See page 21 of http://www.nxp.com/files/sensors/doc/data_sheet/MMA7660FC.pdf for details about the debouncer

Returns
MMA7660_OK on success
-MMA7660_I2C_WRITE_ERR on i2c bus write error

◆ mma7660_config_pdet()

int mma7660_config_pdet ( const mma7660_t dev,
uint8_t  pdth,
uint8_t  enabled_axes 
)

Configure the tap detection.

Parameters
[in]devdevice descriptor
[in]pdthpulse detection
[in]enabled_axesenabled axes

See page 21 of http://www.nxp.com/files/sensors/doc/data_sheet/MMA7660FC.pdf for details about the parameters

Returns
MMA7660_OK on success
-MMA7660_I2C_WRITE_ERR on i2c bus write error

◆ mma7660_config_samplerate()

int mma7660_config_samplerate ( const mma7660_t dev,
uint8_t  amsr,
uint8_t  awsr,
uint8_t  filt 
)

Configure the sample rate.

Parameters
[in]devdevice descriptor
[in]amsractive mode sample rate (pg 18 of DS)
[in]awsrauto wake sample rate (pg 19 of DS)
[in]filtfilter samples (pg 19 of DS)

See datasheet http://www.nxp.com/files/sensors/doc/data_sheet/MMA7660FC.pdf for details about the parameters

Returns
MMA7660_OK on success
-MMA7660_I2C_WRITE_ERR on i2c bus write error

◆ mma7660_init()

int mma7660_init ( mma7660_t dev,
const mma7660_params_t params 
)

Initialize an MMA7660 device.

Parameters
[out]devdevice descriptor
[in]paramsdevice configuration parameters
Returns
MMA7660_OK on success
-MMA7660_I2C_ERR on i2c bus initialization error
-MMA7660_I2C_WRITE_ERR on i2c bus write error

◆ mma7660_read()

int mma7660_read ( const mma7660_t dev,
mma7660_data_t data 
)

Read the acceleration counts converted to mG.

Parameters
[in]devdevice descriptor
[out]datathe acceleration data
Returns
MMA7660_OK on success
-MMA7660_I2C_READ_ERR on i2c bus read error

◆ mma7660_read_counts()

int mma7660_read_counts ( const mma7660_t dev,
int8_t *  x,
int8_t *  y,
int8_t *  z 
)

Read the acceleration counts (unconverted)

Parameters
[in]devdevice descriptor
[out]xthe X axis value
[out]ythe Y axis value
[out]zthe Z axis value

See page 28 of http://www.nxp.com/files/sensors/doc/data_sheet/MMA7660FC.pdf for conversion of acceleration counts to angles or G forces.

Returns
MMA7660_OK on success
-MMA7660_I2C_READ_ERR on i2c bus read error
-MMA7660_READ_ERR on general read error

◆ mma7660_read_tilt()

int mma7660_read_tilt ( const mma7660_t dev,
uint8_t *  res 
)

Read the tilt register.

Parameters
[in]devdevice descriptor
[out]restilt register contents
Returns
MMA7660_OK on success
-MMA7660_I2C_READ_ERR on i2c bus read error

◆ mma7660_set_mode()

int mma7660_set_mode ( const mma7660_t dev,
uint8_t  active,
uint8_t  autowake,
uint8_t  autosleep,
uint8_t  prescale 
)

Set the mode register.

Parameters
[in]devdevice descriptor
[in]active0=sleep 1=active
[in]autowakesee datasheet
[in]autosleepsee datasheet
[in]prescalemain clock prescalar

See page 17 of http://www.nxp.com/files/sensors/doc/data_sheet/MMA7660FC.pdf for information about the parameters

Returns
MMA7660_OK on success
-MMA7660_I2C_WRITE_ERR on i2c bus write error

◆ mma7660_write_sleep_count()

int mma7660_write_sleep_count ( const mma7660_t dev,
uint8_t  sleep 
)

Write the sleep count register.

Parameters
[in]devdevice descriptor
[in]sleepsleep count
Returns
MMA7660_OK on success
-MMA7660_I2C_WRITE_ERR on i2c bus write error