Author Topic: Debugging i2c to an ADXL345  (Read 5627 times)

Matir

  • Newbie
  • *
  • Posts: 3
Debugging i2c to an ADXL345
« on: January 06, 2013, 07:31:04 pm »
So, I've connected an ADXL345 via i2c using 2 N-channel MOSFETs to perform 5v <-> 3.3v level shifting.  Unfortunately, this is my first experience with i2c, and it doesn't seem to be working all that well.  I adapted the library here: https://github.com/jenschr/Arduino-libraries/tree/master/ADXL345 to use TinyWireM and built a program to just read the values and output them via DigiUSB.  Source for the code here: http://pastebin.com/8j4DD4GN  Unfortunately, the program hangs without giving any output on DigiUSB.  DigiUSB is working, because I can comment out lines 20-30 and get "foo", "foo", "foo", etc.

My mosfet setup is pretty simple, just exactly what the application note here suggests: http://ics.nxp.com/support/documents/interface/pdf/an97055.pdf  I've got 4.7k pullups on both sides on both SDA and SCL, BS170 mosfets in the middle.  My 3v3 rail looks good, but there doesn't seem to be much else I can tell with just a multimeter.

Any suggestions?  I don't think it's the Digispark itself, but hoping someone has ideas...
« Last Edit: January 06, 2013, 07:31:04 pm by Matir »

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Debugging i2c to an ADXL345
« Reply #1 on: January 06, 2013, 09:54:10 pm »
You really jump in with both feet! - I don\'t have this device, so I can\'t test directly but your setup sounds fine to me

The most common things I run into with I2C is that I am using the wrong address, the next most common is that it isn\'t in i2c mode (in SPI?), and the third is that I left off the pullups, but it sounds like you have that last one covered.

For the address I usually check with an arduino and this code: http://www.johngineer.com/blog/?p=455

but I haven\'t converted it over to Digispark yet.

Do you have it on a premade breakout board? If so which one?

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Debugging i2c to an ADXL345
« Reply #2 on: January 06, 2013, 11:45:42 pm »
I ordered a cheap breakout of one of these - but it will take awhile to get to me and that will correspond well with it being a bit before I can get to it. I\'ll be happy to help all I can in the meantime, but thought it looked like a cool device (I\'ve been using an analog out accelerometer) so I picked one up.

Matir

  • Newbie
  • *
  • Posts: 3
Debugging i2c to an ADXL345
« Reply #3 on: January 07, 2013, 12:29:58 am »
I do like to jump in!  Actually, I\'ve been really excited about having the full Arduino suite with USB on something cheap enough to build projects and not care if the MCU stays in the controller.

This is the particular one I\'m using at this time: https://dx.com/p/adxl345-digital-3-axis-gravity-acceleration-sensor-module-blue-149476  It has a 3V3 LDO and pullups on the board, which is actually really nice for a $6 part from DX.  (I love cheap hardware from DX for trying out new things... if you can wait for it come from overseas.)

I\'ll try with a full Arduino both to drive the circuit and to do the I2C sniffer tomorrow.

At some point, I need to get an oscilloscope/logic analyzer to look at the waveforms of things like this... Got any recommendations that don\'t break the bank?

digistump

  • Administrator
  • Hero Member
  • *****
  • Posts: 1465
Debugging i2c to an ADXL345
« Reply #4 on: January 07, 2013, 12:46:16 am »
logic analyzer for I2C or slower, but also totally awesome tool - hand down the bus pirate from dangerous prototypes

their logic shrimp is also a great one

O-scope - I\'m looking to get myself a rigol right now, I like the DSO nano on seeedstudio though others have said it is lacking, the Digispark can be an oscope too! but a very slow and not very useful one, I haven\'t tried to look at I2C with it yet!

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Debugging i2c to an ADXL345
« Reply #5 on: January 08, 2013, 04:49:06 pm »
You guys should definitely check out littlewire.cc - it\'s a little avr chip programmer, but it does so much - it can talk to i2c, onewire, and spi devices so you can play with them on your computer directly - best of all? the hardware is identical to the digispark - it just has a 3x3 pin header on the end arranged in to a standard avr programmer cable. Maybe worth checking out?