0

ADXL345 hangs at Wire.endtransmission()
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ADXL345 hangs at Wire.endtransmission()

by TBlay on Thu May 18, 2017 5:41 pm

Hello,

I've been using the Arduino UNO and the Adafruit ADXL345 starter code and setup guide, this one:

https://learn.adafruit.com/adxl345-digi ... and-wiring
and sensortest from the ADXL345 library

Unfortunately, I've been having issues getting the code to progress past the "if(!accel.begin())" line in setup, as the code hangs. But I nailed the issue down to the Wire.endTransmission() function in the Adafruit_ADXL345_Unified::writeRegister and readRegister functions through serial prints. Oddly, to fix this I've tried to delay right before the endTransmission(), and while this fixed the issue once, on a second function call, the function rehangs. SImilarly, if I remove the the SDA and SCL wires during the hang the code runs through but with adxl values of -.4 for everything

I don't think its related to how I've wired anything. Vin->5v , GND->Gnd, SCL->SCL, SDA->SDA All right next to their respective pin on the breadboard

If anyone has any ideas about this, I'd love to hear them.

Code: Select all | TOGGLE FULL SIZE
void Adafruit_ADXL345_Unified::writeRegister(uint8_t reg, uint8_t value) {
  if (_i2c) {
    Wire.beginTransmission(ADXL345_ADDRESS);
   Serial.println("Write Register: begin transmission");
    i2cwrite((uint8_t)reg);
    i2cwrite((uint8_t)(value));
   Serial.println("Write Register: wrote to i2c");
   delay(500);
   Serial.println("Write Register: end of delay");
    Wire.endTransmission();
   Serial.println("Write Register: no issue with wire");
  } else {
    digitalWrite(_cs, LOW);
    spixfer(_clk, _di, _do, reg);
    spixfer(_clk, _di, _do, value);
    digitalWrite(_cs, HIGH);
  }
}

Code: Select all | TOGGLE FULL SIZE
uint8_t Adafruit_ADXL345_Unified::readRegister(uint8_t reg) {
   Serial.println("get data rate");
  if (_i2c) {
     Serial.println("i2c");
    Wire.beginTransmission(ADXL345_ADDRESS);
   Serial.println("got adress");
    i2cwrite(reg);
   Serial.println("wrote");
   delay(1000);
    Wire.endTransmission();
   Serial.println("end transmission");
    Wire.requestFrom(ADXL345_ADDRESS, 1);
   Serial.println("no Wire issue");
    return (i2cread());
  } else {
    reg |= 0x80; // read byte
    digitalWrite(_cs, LOW);
    spixfer(_clk, _di, _do, reg);
    uint8_t reply = spixfer(_clk, _di, _do, 0xFF);
    digitalWrite(_cs, HIGH);
    return reply;
  } 
}

TBlay
 
Posts: 3
Joined: Thu May 18, 2017 5:07 pm

Re: ADXL345 hangs at Wire.endtransmission()

by adafruit_support_bill on Thu May 18, 2017 6:24 pm

i2c communication hangs are most often due to marginal connections. Please post some photos showing your soldering and connections.

adafruit_support_bill
 
Posts: 60264
Joined: Sat Feb 07, 2009 10:11 am

Re: ADXL345 hangs at Wire.endtransmission()

by TBlay on Fri May 19, 2017 6:07 pm

Sorry for taking a day to reply. I had medical business come up.

But here are my soldering pictures via Flickr:

Wiring to Adafruit Uno:Image

Side-view soldering pins: Image

Front view of adxl345 Image

Top-Down view of solder Image

Honestly, I hope its just a lack of proper soldering, it would be reassuring

TBlay
 
Posts: 3
Joined: Thu May 18, 2017 5:07 pm

Re: ADXL345 hangs at Wire.endtransmission()

by adafruit_support_bill on Fri May 19, 2017 8:10 pm

The quality of the soldering looks OK. But the header is installed from the wrong side of the board, so the pins are not long enough to make reliable contact. The short end of the pins should be inserted from the underside of the board as shown in the guide:
https://learn.adafruit.com/adxl345-digi ... g#assembly

adafruit_support_bill
 
Posts: 60264
Joined: Sat Feb 07, 2009 10:11 am

Re: ADXL345 hangs at Wire.endtransmission()

by TBlay on Mon May 22, 2017 10:26 pm

Posting a success update:

Its been two days since it started working consistently, so I feel confident enough to say the issue was resolved.

To fix this, I followed your advice, and pushed the pins down into the board using my soldering iron. Once they were properly long enough, I resoldered the pins to get better connections.

Thank you for the help!

TBlay
 
Posts: 3
Joined: Thu May 18, 2017 5:07 pm

Re: ADXL345 hangs at Wire.endtransmission()

by adafruit_support_bill on Tue May 23, 2017 5:50 am

Good to hear. Thanks for the follow-up.

adafruit_support_bill
 
Posts: 60264
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.