Help reading ADXL312

I am trying to read an ADXL312, and get values of 0x01ff for all the axis.

An am setting register value, and reading them back, and the match, I know the communication is working.

I also don't get anything if the measure bit is turned off.  So there is no problem reading the chip.  Just getting actual values from the measurements.

My C code is shown below.  The CS line is tied to RA6. 

It shows how I initialize the chip, and read 0x31-0x37 in a loop.

Any advice is appreciated.

PORTAbits.RA6 = 0;

WriteSPI(0x2d);                    // Turn off measure

WriteSPI(0x00);

PORTAbits.RA6 = 1;

Delay1KTCYx(100);

PORTAbits.RA6 = 0;

WriteSPI(0x2c);

WriteSPI(0x06);          // Set slow sampling

PORTAbits.RA6 = 1;

Delay1KTCYx(100);

PORTAbits.RA6 = 0;

WriteSPI(0x2e);          // Sett defaults

WriteSPI(0x00);

PORTAbits.RA6 = 1;

Delay1KTCYx(100);

PORTAbits.RA6 = 0;

WriteSPI(0x31);

WriteSPI(0x00);

PORTAbits.RA6 = 1;

Delay1KTCYx(100);

PORTAbits.RA6 = 0;

WriteSPI(0x1E | MULTIBYTE);

WriteSPI(0x00);

WriteSPI(0x00);

WriteSPI(0x00);

PORTAbits.RA6 = 1;

Delay1KTCYx(100);

 

PORTAbits.RA6 = 0;

WriteSPI(0x24 | MULTIBYTE);

WriteSPI(0x00);

WriteSPI(0x00);

WriteSPI(0x00);

WriteSPI(0x00);

PORTAbits.RA6 = 1;

Delay1KTCYx(100);

PORTAbits.RA6 = 0;

WriteSPI(0x38 | MULTIBYTE);

WriteSPI(0x00);

WriteSPI(0x00);

PORTAbits.RA6 = 1;

Delay1KTCYx(100);

PORTAbits.RA6 = 0;

WriteSPI(0x2d);

WriteSPI(0x08);                    // turn on measure

PORTAbits.RA6 = 1;

Delay1KTCYx(100);

do {

     PORTAbits.RA6 = 0;

     WriteSPI(0x2c | READ | MULTIBYTE);

     r2c = ReadSPI( );

     r2d = ReadSPI( );

     r2e = ReadSPI( );

     r2f = ReadSPI( );

     r30 = ReadSPI( );

     r31 = ReadSPI( );          // Read 0x31

     PORTAbits.RA6 = 1;

     if ((r30 & 0x80) == 0) {

               Delay1KTCYx(50);

               continue;

     }

     PORTAbits.RA6 = 0;

     WriteSPI(0x32 | READ | MULTIBYTE);

     xlow = ReadSPI( );          //  Read 0x32

     xhi = ReadSPI( );          //  Read 0x33

     ylow = ReadSPI( );          //  Read 0x34

     yhi = ReadSPI( );          //  Read 0x35

     zlow = ReadSPI( );          //  Read 0x36

     zhi = ReadSPI( );          //  Read 0x37

     PORTAbits.RA6 = 1;

etc....

  • 0
    •  Analog Employees 
    on Dec 21, 2012 11:57 PM

    Hey Scotty,

    have you referenced the ADXL312 quick start guide?  its a great tool for getting up and running with communications between your micro-controller and the ADXL312.  it can be found at:

    http://www.analog.com/static/imported-files/user_guides/UG-281.pdf

    this guide contains the specific commands you need, and the procedures to follow, to get acceleration information out of the device.

    please let me know if what you need isnt in that guide.

    regards,

    -Matt

  • Hi Matt,

    Per the document you sent me to, I have done all of those.

    Page 3 says to confirm communication by reading register 0x00.  I have done that and get the correct device ID.

    Per figure 5, it shows the minimal startup sequence. I have met all those requirements.

    The only difference was that I wasn't using interrupts. I was polling register 0x30 to determine when the data was ready to read. to see if the  I tried it with interrupts and it is the same result.

    I added the interrupt flag to register 0x2e, and it did not solve the problem.

    I am not using FIFO, or interrupts, or anything else.

    Yet, for all axis readings, I still get 0x01FF.  I have to assume the component is defective...?

    Thanks.

    -Christopher 'Scott' Weber

  • 0
    •  Analog Employees 
    on Jan 7, 2013 11:12 PM

    Hey Scott,

    happy new year!  sorry for the delay in my response, but i've been out of the office for the past 2 weeks.

    i'm not sure if this particular device is defective, but if you would like to investigate that further, then my first question would be "have you tried testing another device?"  if you see this same issue across multiple devices and setups, then my guess is that the issue lies somewhere outside the device.

    how are you testing the device?  is it soldered to a PCB?  can you share your schematic?  if not connected properly, the application circuit can cause the device to behave differently than what you would expect.

    using the Inertial Sensor Evaluation System, i see the following contents in all of the device memory registers when i first apply power to the ADXL312.  this is the default condition of the ADXL312, and it would be good to confirm that you read all the same values from the various registers

    After Enabling MEASUREMENT mode, a snapshot of the memory map shows me the following:

    The LabVIEW code sets a couple of other bits, but none of them are critical to retrieving acceleration data from the part.  the routine for collecting the memory map contents is non-interrupt driven, and pays no attention to the INT_SOURCE register.  this is a completely asynchronous routine that collects data on-demand.  Thankfully, i dont see 0x01FF in any of my data registers.

    now, when i disable measurement mode, its important to note that the X, Y and Z data registers will store the last available sample of acceleration data.  these registers do not clear when you disable measurement mode.  So, if you are seeing 0x01FF in these registers when measurement mode is enabled, then you should still see 0x01FF in these registers are disabling measurement mode.

    an email that you sent to our Central Applications group leads me to believe that you are seeing different behavior.  From your email:

         Also if I turn off the measure bit, I don't get anything at all, as      expected.

         So I know when I set the measure bit, it is turned on. But it is but not      giving me valid readings.

    as shown below, when you disable the MEASUREMENT mode, you should read a static acceleration value in each register.  this static value will reflect whatever value was last available at the output of the device.  if you are seeing different behavior than this, then it might be that the current issue lies outside of your code, warranting a review of your test circuit.

    hope this gets you closer to solving your issue.

    Regards,

    -Matt

  • Matt,

    Thanks for your reply.  As a student, I have mounted only one device on a small PCB.  I haven't mounted other devices, so I do not have other devices to compare to.  The PCB is just a pin break out that allows me to put the unit on a bread board.  Mounting by hand is not a lot of fun, so I haven't had the desire to try another one

    Both supplies are connected to the same 3.3V, the ground is connected.  I am using 4 wire SPI, and the INTs are left floating.

    When I say 'I don't get anything' when the unit is off, I mean that the 'Data_Ready' bit (reg 0x30) never turns on, so the little test program I wrote doesn't bother to read the data registers.  It end the reading, and loops, waiting for the data ready.

    The PNG images are useful showing me the registers.  I will write a small routine that will dump the whole register list, compare it to those, and let you know what I find.  However, it will likely be a few days before I can do that test.

    I'll get back to you in a few days.  Thanks again.

    -Christopher 'Scott' Weber

  • Nitzan and Matt,

    I think this should be written off as a defective device, and I will try to mount another unit on another breakout board I have.  QFN's aren't a lot of fun, and perhaps I shorted out one of the NC pins and that is causing the problem.

    But here are the results of my tests, if you are interested.  It's a lot of time for a low cost part, but I'm a hobbiest and student so no harm to me.

    First off, this table is a comparison of my registers to the image that Matt sent me for 'Measure Mode'

    The TST is mine, the REF is from Matt:

        BW   P   I   M   IS  FMT

    REG 2c 2d  2e  2f  30  31  3233 3435 3637