Go Down

Topic: Can't address the MMA8451 via Arduino Due (Read 654 times) previous topic - next topic

ocean

I'm struggling to get the MMA8451 accelerometer from Freescale to work with the Arduino Due. The following code, which is supposed to read the device ID number, doesn't appear to work.

Code: [Select]

#include "Wire.h"

#define mma8451_address 0x1D
#define device_id_address 0x0D

void setup() {
  Serial.begin(9600);
  Wire1.begin();
}

void loop() {
  // Read MMA8451 ID
  Wire1.beginTransmission(mma8451_address);
  Wire1.write(device_id_address);
  Wire1.endTransmission(false);
  Wire1.requestFrom(mma8451_address, 1);
  unsigned char data = Wire1.read();
  Wire1.endTransmission();
  Serial.print("MMA8451 ID # = ");
  Serial.println(data, HEX);   
  delay(1000);
}


The above code retrieves 0x00 from the device_id_address which is obviously incorrect.

I'm using Arduino's Wire library and I believe the device is properly connected to the Due board. I have set the SA0 pin to High and the I2C wires are connected to the SCL1 and SDA1 pins on the Due. Two 10K pull-up resistors are also used.

I wonder if the Wire library is fully compatible with the MMA8451 or if it needs to be modified. Has anyone been able to communicate with this device via Arduino Due? Any help with this issue is appreciated.

Thanks


The last I knew (and perhaps it's been fixed by now), is that endTransmission(false) does not work.  It is simply skipped in the 'wire' library, and you will need to code around it. 

Search the forum for I2C and/or "Repeated Start" to see some past experiences.

Here's one I could remember:
http://forum.arduino.cc/index.php?topic=144700.0

Good luck,

-Chris

Go Up