0

Arduino Due with MMA8541 accelerometer gives junk output
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Arduino Due with MMA8541 accelerometer gives junk output

by dbarkats on Fri Jul 26, 2019 12:13 pm

Hi,
Help please.
I just bought an Arduino Due and a few MMA 8541 3-axis accelerometers.
I followed this Adafruit tutorial on how to connect and set up the sensor. I downloaded all the libraries, flashed the MMA8541 Demo code. All worked fine.
Then when I started getting my first readings, they looked like junk. See below.
The X value is stuck at -1, and Y and Z just fluctuate wildly between -7XXX and +7XXX. It looks to me like the readings are not being interpreted with the proper number of bits or something.
Since I read about this failure mode (https://community.nxp.com/thread/478447), I tried switching to another MMA8541 board, but the exact same results happened.
What's going on ?
Help

Code: Select all | TOGGLE FULL SIZE
###Monitor output ####

Adafruit MMA8451 test!
MMA8451 found!
Range = 2G
X:   63   Y:   -7106   Z:   -5616
X:    2.45   Y:    -19.46   Z:    18.43   m/s^2
Portrait Up Front

X:   -1   Y:   -8130   Z:   -7664
X:    2.45   Y:    -17.01   Z:    -12.22   m/s^2
Portrait Up Front

X:   -1   Y:   5694   Z:   -7152
X:    2.45   Y:    -17.01   Z:    -14.67   m/s^2
Portrait Up Front

X:   -1   Y:   6206   Z:   -8176
X:    1.53   Y:    -19.46   Z:    -15.90   m/s^2
Portrait Up Front

X:   -1   Y:   5694   Z:   -6128
X:    2.45   Y:    17.31   Z:    -10.99   m/s^2
Portrait Up Front

X:   -1   Y:   7230   Z:   -4592
X:    2.45   Y:    14.86   Z:    17.20   m/s^2
Portrait Up Front

X:   -1   Y:   5182   Z:   -7664
X:    1.53   Y:    -15.79   Z:    -8.54   m/s^2
Portrait Up Front

X:   -1   Y:   6206   Z:   -6640
X:    2.45   Y:    9.96   Z:    -14.67   m/s^2
Portrait Up Front

X:   -1   Y:   7742   Z:   1040
X:    2.45   Y:    14.86   Z:    -17.12   m/s^2
Portrait Up Front

X:   -1   Y:   5182   Z:   7183
X:    0.15   Y:    16.08   Z:    -6.09   m/s^2

#####
Last edited by adafruit_support_mike on Sat Jul 27, 2019 2:53 am, edited 1 time in total.
Reason: added CODE tags

dbarkats
 
Posts: 5
Joined: Fri Jul 26, 2019 12:06 pm

Re: Arduino Due with MMA8541 accelerometer gives junk output

by adafruit_support_mike on Sat Jul 27, 2019 2:53 am

Post a photo showing your hardware and connections and we'll take a look. 800x600 images usually work best.

adafruit_support_mike
 
Posts: 58886
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduino Due with MMA8541 accelerometer gives junk output

by dbarkats on Mon Jul 29, 2019 4:20 am

Due_MMA8541_setup.JPG
Setup of my Adruino
Due_MMA8541_setup.JPG (286.68 KiB) Viewed 102 times


Hi,
Well, I spent quite some time this week end trying to debug this problem and I am pretty convinced that the MMA8541 has never worked with an Arduino Due.
Above is a photo of the setup. The Arduino Due provides 5V and Gnd to the MMA 8541 board, and is connected via the 2SDA/SCL I2C pins. Pretty basic.
- As I said previously, the results remain unchanged ( same junk output in all 3 X/Y/Z) if I switch to another MMA8541 board
- I tested the same setup with a Arduino UNO and it worked perfectly fine.
- I spend a lot of time trying to mess with the types of the returned x, y, z but nothing worked.
- I even hooked up a logic analyzer on the SDA/SCL pins to analyze the whole communication stream between the MMA8541 and the Arduino Due. My conclusion is that the communication is working fine and exactly all the read/writes done by the library are happening correctly. It's just the output LSB values which are systematically junk. ( ie OUT_X_LSB, OUT_Y_LSB, and
OUT_Z_LSB), the MSB consistently match the the values I read using the Uno.
I used the doc here: https://cdn-shop.adafruit.com/datasheets/MMA8451Q-1.pdf for reference.

So, I look forward to any help you can provide on this problem but I'm starting to think there is a fundamental problem between the Arduino Due and this MMA8541 chip.

Thanks

dbarkats
 
Posts: 5
Joined: Fri Jul 26, 2019 12:06 pm

Re: Arduino Due with MMA8541 accelerometer gives junk output

by dbarkats on Mon Jul 29, 2019 4:22 am

By the way,
Here are 2 .csv files which show a comparitive dump of the whole logic sequence between this setup communicating with a Due (and yielding junk results) and this setup communicating with an Uno (and yielding proper results).

I2C_due.csv
Logic Dump using the Due
(5.69 KiB) Downloaded 3 times

I2C_UNO_OK.csv
Logic Dump using the Uno
(6.43 KiB) Downloaded 3 times

dbarkats
 
Posts: 5
Joined: Fri Jul 26, 2019 12:06 pm

Re: Arduino Due with MMA8541 accelerometer gives junk output

by adafruit_support_mike on Mon Jul 29, 2019 2:34 pm

The Due’s I2C system was always kind of screwy. IIRC, it doesn’t do a repeated-start unless you use a different function or pass an existing function extra parameters.

Many I2C devices use a repeated start to set register addresses before reading values.. you start with a write that sets the address, then do a repeated start before sending any data, then do a simple read command. That simplifies the input state machine, since only the write handler needs to know how to accept and set the current register address, and reduces all reads to simple ‘give me whatever register is active’ operations.

Check the Wire library documentation for info about forcing a repeated start instead of a full-stop/full-start.

adafruit_support_mike
 
Posts: 58886
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduino Due with MMA8541 accelerometer gives junk output

by dbarkats on Tue Jul 30, 2019 6:20 am

Hi Mike,

Your answer doesn't make sense to me.
From looking at the communication between the Due and the MMA8541, the first thing the Due does is to ask the MMA "WHO_AM_I". If the repeated start condition didn't work on the Due, we would just read back 0 and the communication would stop there.
That is not the case and as you can see from the dumps provided, the communication proceeds perfectly fine through all the configuration and then through the data transfer.
Any chance you guys at Adafruit could test this setup of a Due + an MMA8541. Seems like a mystery to me why everything in the configuration works as expected but the data transfer is non-sensical.
I've already moved on and am using a MEGA to continue this project but if the Due is truely ( for an unknown reason) incompatible with the MMA 8541, someone should note that in the MMA8541 details, so others don't run into the same problem.

dbarkats
 
Posts: 5
Joined: Fri Jul 26, 2019 12:06 pm

Re: Arduino Due with MMA8541 accelerometer gives junk output

by adafruit_support_mike on Tue Jul 30, 2019 1:38 pm

I’ll have someone try to duplicate the issue on our own hardware.

adafruit_support_mike
 
Posts: 58886
Joined: Thu Feb 11, 2010 2:51 pm

Re: Arduino Due with MMA8541 accelerometer gives junk output

by dbarkats on Wed Jul 31, 2019 3:37 am

Hi Mike,
thanks a lot. That would be very constructive.
I look forward to the results.
Denis

dbarkats
 
Posts: 5
Joined: Fri Jul 26, 2019 12:06 pm

Please be positive and constructive with your questions and comments.