Trouble interfacing ADXL345/375 accelerometer


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2009
    Location
    Huntsville, AL
    Posts
    32

    Default Trouble interfacing ADXL345/375 accelerometer

    I'm having trouble interfacing an ADXL375 accelerometer (almost the same as the more widely used ADXL345 from what I can tell). I would appreciate any help!

    The datasheet for the ADXL375 is here:
    http://www.analog.com/media/en/techn...ts/ADXL375.pdf

    I have it connected to a 16F676 with 1k resistors connecting the ADXL375's DQI (input) and DQO (output) pins to the pic. CLK and CS are direct connection to the pic with the ADXL375's two interrupt pins left floating. I'm using a 3.3v regulator.

    I'm trying to interface with it in SPI mode (which is the default if I've read the datasheet correctly). However, all I get are "0-0-0" lines in the terminal. Any suggestions?

    Thanks in advance for any help!

    Code:
    @ device  pic16F676, hs_osc, wdt_off, pwrt_off, mclr_off, protect_off
    cmcon=7
    define osc 8
    ANSEL = %00000000	'AN0 through AN7 are digital
    
    AX1	VAR	WORD  'X-dir accel
    AY1	VAR	WORD  'Y-dir accel
    AZ1	VAR	WORD  'Z-dir accel
    wconfig	var	byte  'ADXL FIFO address write byte
    rconfig	var	byte  'ADXL FIFO address read byte
    'temporary shiftout bytes
    ACDATA1	var	byte
    ACDATA2	var	byte
    ACDATA3	var	byte
    ACDATA4	var	byte
    ACDATA5	var	byte
    ACDATA6	var	byte
    
    CS      var     PORTa.2                ' CHIP SELECT
    SDO     var     PORTc.0                ' DATA OUT FOR ADXL375
    SDI     var     PORTc.1                ' DATA IN FOR ADXL375
    CLK     var     PORTc.2                ' CLOCK PIN
    LED     var     PORTc.4                ' LED PIN
    
    rconfig=50 'first FIFO address register where acceleration values are stored
    rconfig.7=1 'change bit7 to 1 to indicate a read operation
    rconfig.6=1 'change bit6 to 1 to indicate multiple bytes will be read
    
    'write address for the power_ctl byte with bit7=0 (write operation) and bit6=0 (1 byte operation)
    wconfig=45
    
    'blink to verify program is running
    high LED
    pause 100
    low LED
    pause 100
    high LED
    
    high CS
    pause 1
    
    loop:
    low CS
    pause 1
    shiftout SDI,CLK,1,[wconfig\8,%00001000\8]  'write 1 to bit3 of power_ctl register to put ADXL375 in measurement mode
    high CS
    pause 1
    low CS
    shiftout SDI,CLK,1,[rconfig\8] 'shiftout read command and FIFO address
    shiftin SDO,CLK,1,[ACDATA1,ACDATA2,ACDATA3,ACDATA4,ACDATA5,ACDATA6] 'shiftin acceleration values
    high CS
    AX1.highbyte=ACDATA1
    AX1.lowbyte=ACDATA2
    AY1.highbyte=ACDATA3
    AY1.lowbyte=ACDATA4
    AZ1.highbyte=ACDATA5
    AZ1.lowbyte=ACDATA6
    serout2 portc.5,16468,[DEC AX1,"-",DEC AY1,"-",DEC AZ1,10,13]
    
    pause 1000
    
    goto loop
    
    end

  2. #2
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Trouble interfacing ADXL345/375 accelerometer

    Try to set define OSC 8. The OSC needs to be in caps.

  3. #3
    Join Date
    Jan 2009
    Location
    Huntsville, AL
    Posts
    32


    Did you find this post helpful? Yes | No

    Default Re: Trouble interfacing ADXL345/375 accelerometer

    It was communicating with the terminal program at 9600 baud without a problem... wouldn't it have spouted gibberish if it didn't use 8Mhz? I'll use uppercase to be safe.

    But I think I figured out the problem... I was communicating with the clock pin idling low... it should have been idling high. Therefore the pic was not shifting the right data or the right register address to the ADXL375, and so it never got into measurement mode. After I changed it to idle high, I started getting values that looked meaningful (but very noisy!), although I think that's just because I don't have any filtering on the power supply or at the IC pins (just wanted to get it working). I'll try that next.

    Dave

  4. #4
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Trouble interfacing ADXL345/375 accelerometer

    Are you using internal oscillator?

  5. #5
    Join Date
    Jan 2009
    Location
    Huntsville, AL
    Posts
    32


    Did you find this post helpful? Yes | No

    Default Re: Trouble interfacing ADXL345/375 accelerometer

    It's using an external crystal with the "HS" oscillator setting.

    After adding some caps, the output is much better and it's clearly exporting acceleration data correctly. Flipping it around on all axes show the expected +/-1g change. The offsets are rather large (+3g in some axis), but that can be adjusted/calibrated.

Similar Threads

  1. ADXL345 Accelerometer using I2C
    By Terry in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th August 2015, 19:23
  2. Replies: 1
    Last Post: - 12th November 2011, 20:05
  3. accelerometer question
    By griffin in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 27th February 2009, 22:00
  4. ST micro LIS3LV02DL accelerometer interfacing
    By devil6600 in forum Serial
    Replies: 8
    Last Post: - 17th May 2008, 16:29
  5. Adxl213ae Accelerometer
    By DougB in forum mel PIC BASIC
    Replies: 0
    Last Post: - 25th July 2005, 22:32

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts