Go Down

Topic: Need help with MMA7455 using SPI (Read 1 time) previous topic - next topic


Dec 08, 2011, 03:59 pm Last Edit: Dec 08, 2011, 10:12 pm by nagibator_vl Reason: 1
Hi! I want to read data from MMA7455 to my Arduino Mega by SPI, but I have some problems.

I connect MMA7455 to arduino mega by 4-wires:

MMA7455       Arduino Mega

  SDO      ->    pin 50 (MISO)
  SDA      ->    pin 51 (MOSI)
  SCL      ->    pin 52 (SCK)  
  CS        ->    pin 53 (SS)

And wrote this code:
Code: [Select]

#include <SPI.h>

char X_data;

#define SELECT_MODE 0x16 //Register for the mode changing
#define MODE_2G 0x09 //2g mode
#define MODE_4G 0x05 //4g mode
#define MODE_8G 0x01 //8g mode

#define x_axis 0x06 //Register for reading the X-Axis
#define y_axis 0x07 //Register for reading the Y-Axis
#define z_axis 0x08 //Register for reading the Z-Axis

#define SS 53   //SS pin

void writeRegister(char Register, char Value) {

 digitalWrite(SS, LOW);

 SPI.transfer(0x80 | (Register << 1));

 digitalWrite(SS, HIGH);

unsigned char readRegister(char Register) {

 char data;  
 digitalWrite(SS, LOW);
 SPI.transfer(Register << 1);
 data = SPI.transfer(0x00);
 digitalWrite(SS, HIGH);
 return data;

void setup() {

 pinMode(SS, OUTPUT);
 digitalWrite(SS, HIGH);
 writeRegister(SELECT_MODE, MODE_8G);

void loop() {
 X_data = readRegister(x_axis);
  Serial.print(X_data, DEC);

...but this program always gives back zero from all axis (

Please help me, where is my mistake? Thanks a lot.


up... I2C is working good, but SPI is not... (


Hi, I use the MMA7455 with i2c without problem.
I hope that this page can be helpful for you:

Why do you need the SPI connection?



Since the CS pin doubles as a I2C enable pin you need to be I2C clean when CS is high.  Thus I'd make sure SCK and MOSI are LOW before releasing CS.  The datasheet says there's a control bit in one of the registers to disable I2C, probably the first thing to check.

You then need to make sure you are using 4-wire and not 3-wire SPI - this may be why you are getting nothing on MISO....
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131