ADXL345 SPI Lib issue (works on i2c)

26 Nov 2012

Hey everyone,

I'm currently working on an ADXL345 accelerometer as part of a university project, I've been having issues with getting the ADXL345 library to work.. although the I2C version works perfectly fine.

Here is a link to the accelerometer I have:

http://babelduck.com/index.php/en/reference/user-manuals/1427-adxl345-3-axis-accelerometer-sensor-module-product-manual

i'm unsure what the issue is but i'm currently only receiving 0,0,0 as a result. my wiring configuration is:

3V3 > Vout GND > GND SDA > P6 SDO > P5 SCL > P7 CS > P8

If anybody has any similar issues and/or insight i'd be very greatful.

Mike

26 Nov 2012

Your code would help (You use the standard ADXL code?)

Anyway considering your I2C version works fine, use it :P. Regarding your problem, since I2C works fine and I assume the library is correct, the most likely problem is still the wiring. If you did what you wrote here you got P5 and P6 mixed up.

27 Nov 2012

Hey i'm SmartBoxingGlove on my personal account.

I've tried the wiring as you've said before and just now and still the same issues, in this instance i'm using the standard ADXL code from the library page. We're making a boxing glove which incorporates an accelerometer/gyro which is then connected over Bluetooth/WiFi to an iPad application (due to apples Bluetooth issues probably WiFi) and we're thinking that I2C will just be too slow for real-time readings, ofcourse this is just a prototype and proof of concept at the moment but getting SPI to work would be much more convenient.

27 Nov 2012

Also it is picking up '0x00' as the ID.

27 Nov 2012

Yeah then there is simply no valid communication happening. If you have a logic analyser or something similar that could help to find out what the issue is. Did you try lowering the frequency set for the SPI in the ADXLs library? Or tried using another SPI port?

Regarding I2C, that should be fast enough too, you dont have too read the accelerometer that often. The official limit on the I2C ports the mbed uses is 100kHz (normal mode), but from my experience 400kHz (fast mode) I2C works fine too. I also have had I2C ICs running at 1MHz without problems. But if you want it on an Ipad application I assume you dont need 200Hz sampling rate, especially with the delays wifi adds, anything above a few Hz is overkill.

If you are really worried about I2C overhead, you can try the MODI2C library. It allows for non-blocking I2C communication, so you can do other stuff at the same time.

27 Nov 2012

Yeah lowering the frequency was the first thing I tried, second was using a different port lol. I don't have my own logic analyzer but I can easily go into the engineering department at university, they are using MBeds as part of coursework (I'm generally a c++ programmer who works mainly on AI and path-finding in games). I'll tinker away and see what I can do, I looked into fast mode actually and found that the blue-tooth ran at about 750kHz (until we looked into apples MFI issues we were hoping to use bt), maybe it will be more important to just get the WiFi and the actual iPad application sorted and use the data from i2c for the time being..

I'll have a look at the MODI2C lib too, thank you very much for your help Erik, if I figure this out i'll let you know :)

24 Sep 2016

So I have one of the cheap ebay modules and had the same issue with i2c working but spi did not.

Finally realized the spi one sck and the led share the same pin.

Moved to spi3 and works like a champ.

Mod the hello world to: ADXL345 accelerometer(PB_5, PB_4, PB_3, PA_8);

for a nucleo 401 or 446

scott