Bus Pirate: MMA7455L accelerometer
From DP
Contents |
MMA7455L breakout
The MMA7455L is an inexpensive 3-axis accelerometer with adjustable measurement range of 2/4/8g.
Unfortunately it only comes in a leadless LGA-14 package, so we made our own MMA7455L breakout board.
Get an assembled breakout board for $15.
SPI demo
Connections
| Bus Pirate | Direction | MMA7455L | Description |
|---|---|---|---|
| MOSI | → | SDA/SDI | Master Out, Slave In |
| MISO | ← | SDO | Master In, Slave Out |
| CLK | → | SCL/SPC | Clock signal |
| CS | → | CS | Chip Select |
| +3.3V | → | 3.3V | Power supply |
| GND | ↔ | GND | Ground |
Bus Pirate setup
Connect the Bus Pirate to the chip as shown in the table.
HiZ>m<<<mode command
1. HiZ
...
5. SPI
...
(1)>5<<<SPI mode
Select output type:
1. Open drain (H=Hi-Z, L=GND)
2. Normal (H=3.3V, L=GND)
(1)>2<<<normal pinout
Ready
SPI>
Configure the Bus Pirate for SPI mode. Chose all the default settings except output type. Choose normal pin outputs.
SPI>W<<<enable power supplies
Power supplies ON
SPI>
The chip is powered by the Bus Pirate, enable the power supplies (W).
Interfacing
| Command | Description |
|---|---|
| 0x0D | I2C address |
| 0x16 | Mode control |
| 0x06 | 8bit accel X |
| 0x07 | 8bit accel Y |
| 0x08 | 8bit accel Z |
We'll cover these commands, a complete list is on page 21 of the datasheet. The commands are sent after taking the CS pin to ground ([), transactions end by returning CS high (]).
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|
| r/w | A5 | A4 | A3 | A2 | A1 | A0 | x |
The first byte of SPI commands chooses the register to work with, and selects read or write access. The table shows how the byte is packed. The first bit selects read (0) or write (1) access, the next 6 bits are the register to access, the last bit doesn't matter.
SPI>=0x0d <<<find the binary equivalent
0x0D = 13 = 0b00001101
SPI>[0b00011010 r] <<<pack the address into the command
A quick way to find the command to access a register:
- Use the Bus Pirate to find the binary equivalent (= command)
- Pack the lower six bits of the register address into the command according to the table using the Bus Pirate binary number entry format
Check the connection
Register 0x0D contains the I2C address. This address isn't relevant to SPI mode, but we can grab it to make sure the connection to the chip is functioning.
SPI>[0b00011010 r]
/CS ENABLED
WRITE: 0x1A <<<read I2C address register
READ: 0x1D<<<read value from register
/CS DISABLED
SPI>
Lower chip select ([), then setup the register to access(0x1a), read a byte (r), and raise chip select (]). The reply is 0x1D, the default I2C address according to page 23 of the datasheet.
Setup the mode control register
| D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 | Bit |
|---|---|---|---|---|---|---|---|---|
| - | DRPD | SPI3W | STON | GLVL[1] | GLVL[0] | MODE[1] | Mode[0] | Function |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | Default |
Register 0x16 configures the MMA7455L. The most interesting bits are the GLVL (sensitivity) and Mode control bits. See the complete MMA7455 Mode Control Register reference at the end of this page for a description of each bit.
Configuring the g-Select for 8-bit output using Register $16 with GLVL[1:0] bits
| GLVL[1:0] | g-Range | Sensitivity |
|---|---|---|
| 00 | 8g | 16 LSB/g |
| 01 | 2g | 64 LSB/g |
| 10 | 4g | 32 LSB/g |
The two GLVL bits control the sensitivity and measurement range. We'll use 2g (01) for this demo.
Configuring the Mode using Register $16 with MODE[1:0] bits
| MODE[1:0] | Function |
|---|---|
| 00 | Standby Mode |
| 01 | Measurement Mode |
| 10 | Level Detection Mode |
| 11 | Pulse Detection Mode |
The MMA7455 can sleep, measure on demand, or generate an interrupt at a set level or after a pulse. We'll use continuous measurement mode (01) for this demo.
SPI>[0b10101100 0b101]
/CS ENABLED
WRITE: 0xAC<<<write to reg 0x16
WRITE: 0x05<<<configuration settings
/CS DISABLED
SPI>
Write the configuration command (00000101) to register 0x16 (using 0b10101100).
- Read it back (using 0b00101100 r) to verify the value if you like.
Read accel data
SPI>=0x06
0x06 = 6 = 0b00000110
SPI>[0b00001100 r]
/CS ENABLED
WRITE: 0x0C<<<read X output
READ: 0x03<<<X accel reading
/CS DISABLED
SPI>[0b00001100 r]
An 8bit measure of the X output value is in register 0x06. Don't forget to set the read/write bit to one and pack the command in the 6 middle bits.
The value is near zero because the board is flat.
SPI>[0b00001100 r]
/CS ENABLED
WRITE: 0x0C
READ: 0xE3<<<X accel reading
/CS DISABLED
SPI>
If we tilt the board along the X axis the reading changes.
SPI>[0b00001110 r]
/CS ENABLED
WRITE: 0x0E<<<read Y output
READ: 0xF3<<<Y accel reading
/CS DISABLED
SPI>[0b00010000 r]
/CS ENABLED
WRITE: 0x10<<<read Z output
READ: 0x4C<<<Z accel reading
/CS DISABLED
SPI>
We can also access the Y (0x07) and Z (0x08) output.
I2C demo
- Coming soon.
MMA7455L Control Register reference
| D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 | Bit |
|---|---|---|---|---|---|---|---|---|
| - | DRPD | SPI3W | STON | GLVL[1] | GLVL[0] | MODE[1] | Mode[0] | Function |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | Default |
DRPD
- 0:Data ready status is output to INT1/DRDY PIN
- 1:Data ready status is not output to INT1/DRDY PIN
SPI3W
- 0: SPI is 4 wire mode
- 1: SPI is 3 wire mode
STON
- 0:Self-test is not enabled
- 1:Self-test enabled
Configuring the g-Select for 8-bit output using Register $16 with GLVL[1:0] bits
| GLVL[1:0] | g-Range | Sensitivity |
|---|---|---|
| 00 | 8g | 16 LSB/g |
| 01 | 2g | 64 LSB/g |
| 10 | 4g | 32 LSB/g |
Configuring the Mode using Register $16 with MODE[1:0] bits
| MODE[1:0] | Function |
|---|---|
| 00 | Standby Mode |
| 01 | Measurement Mode |
| 10 | Level Detection Mode |
| 11 | Pulse Detection Mode |

