6

I am trying to connect an ADXL355 digital sensor to an Arduino. The wiring and the code I think are OK because the system returns the correct values sometimes and partly correct answers mostly. The code checks the device register, and the correct data is printed to serial most of the time. The code also checks for temperature but only returns the correct value occasionally. The values are polled every few seconds. The values are correct all of the time if they are correct the first time after restart but never if they are incorrect on restart. I thought it might help to unplug the sensor when uploading the program or powering up the Arduino through USB to the computer but there is no clear pattern.

It is not a defective sensor because I have 2 that behave the same way. What could be the problem? Is this a problem with the Arduino?

enter image description here

I only wire VDD, VDDIO, ground,chip select, sclk, MOSI and MISO.

code:

#include <SPI.h>

    const int ID = 0x00;
    const int FIFO = 0x11;
    const int TEMP = 0x06;
    const int TEMP1 = 0x07;
    const byte FIFO_WATERMARK = 0x29;
    const int chipSelectPin = 7;


    void setup() {
        Serial.begin(9600);

        SPI.begin();

        pinMode(dataReadyPin, INPUT);
        pinMode(chipSelectPin, OUTPUT);

        // writing 0 to to enable sensor
        writeRegister(0x2D, 0x00);

        delay(100);

        Serial.println(readRegister(ID));
        Serial.println(readRegister(FIFO_WATERMARK));
    }

    void loop() {
        int temp = (readRegister(TEMP)); // << 8) | (readRegister(TEMP1))) ;
        temp = (temp<<8)|(readRegister(TEMP1));
        Serial.println(((1852 - temp)/9.05) + 19.21);
        Serial.println(readRegister(ID));

        delay(1000);
    }

    byte readRegister (byte thisRegister){
        byte inByte = 0 ;
        SPI.beginTransaction(SPISettings(500000, MSBFIRST, SPI_MODE0)); // 500khz clock
        digitalWrite(chipSelectPin, LOW);
        SPI.transfer((thisRegister << 1) | 1);
        inByte = SPI.transfer(0x00);
        digitalWrite(chipSelectPin, HIGH);
        return inByte;
    }
    void writeRegister (byte thisRegister, byte value){
        SPI.beginTransaction(SPISettings(500000, MSBFIRST, SPI_MODE0)); // 500khz clock
        digitalWrite(chipSelectPin, LOW);
        SPI.transfer(thisRegister << 1);
        SPI.transfer(value);
        digitalWrite(chipSelectPin, HIGH);
    }

Some one suggested it might be signal bounce on the SPI and the clock rate was set to 500kHz but it didn't work.

Update:
Not long ago, the correct device ID would be read consistently (173 for 0xAD); now that returns 0. The temperature would either return 0 from the register or changing values between -1 and -5 that may have been wrongly calibrated temperature. But sometimes the correct temperature would return. Now it also only returns 0 from the registers.

4
  • Could you show some of the output you get?
    – Gerben
    Mar 12, 2017 at 19:09
  • @Gerben I updated the post with the outputs.
    – rur2641
    Mar 12, 2017 at 19:28
  • Try adding a bit of delay after setting the ChipSelect pin low.
    – Gerben
    Mar 12, 2017 at 19:31
  • @Gerben It didn't work, outputs are 0.
    – rur2641
    Mar 12, 2017 at 19:51

2 Answers 2

2

This is a poor product, look at this: that describes exactly the problems you (and me) are experiencing. Correct me if you've found any solutions so far.

edit

Try looking at description of regster 0x2f in datasheet and to this question.
I think that the first problem you describe can be solved this way, the second behaviour sounds like you fried the device.

1
  • While that link may provide an answer to the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. Nov 13, 2020 at 13:55
1

Per your post looks like you have not wired any grounds. Consider wiring Analog and Digital grounds.

ADXL355 Grounds

Here are excerpts from the datasheet

ADXL355 Ground Pins

5
  • Thank you. I forgot to mention that I wired the ground. But I did not the VSSIO. Someone also suggested it was because the sensor runs on 3.3 V and the Arduino on 5.
    – rur2641
    Mar 13, 2017 at 3:43
  • Regardless of 3.3V or 5V GND is 0V. DGND and AGND are internally isolated. So erratic behavior can be explained due to poor grounding. Good luck. BTW don't cross post questions. Mar 13, 2017 at 8:51
  • 1
    It could also be caused by insufficient or unregulated power supply.
    – SDsolar
    Mar 13, 2017 at 9:17
  • @Mahendra Gunawardena 6 The VSSIO is tied to the VSS through the P1 6 pin header
    – rur2641
    Mar 13, 2017 at 15:18
  • Attaching a small ceramic or electrolytic capacitor to the power rail /might/ help to reduce the issue.
    – Avamander
    Mar 14, 2017 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.