Baby O and ADXL345 via I2C hangs

Hi guys,

I’ve been battling this for a few days now, I’m a programmer but kind of a noob at electronics so I’m kinda hoping it’s my wiring. I know there are a lot of threads around on this subject but I’ve been through all of them.

Basically I have a Baby Orangutan B-328 hooked up to a SparkFun ADXL345 via I2C using Peter Fleury’s i2cmaster lib. But it hangs at i2c_start, i.e. at this line:

// twimaster.c (i2c_start)

// send START condition
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);

// wait until transmission completed (HANGS)
while(!(TWCR & (1<<TWINT)));

The simplest code I have that hangs is:

i2c_init();
i2c_start(0x53 + I2C_WRITE);
i2c_stop();
while (1) {}

The ADXL345 wants <=3.6v so I’ve used a voltage divider (5v > 1000/2200 = 3.4v) and measured 3.4v at the pins.
The SDA and SCL pins are connected to SDA and SCL respectively, and I have pull-up resistors at 4.7k and I’ve measured 3.4v on all the pins.
The SDO pin is pulled low for the 0x53 address.
The CS pin is pulled high to Vcc for I2C mode.

Here’s an image of my setup: ('scuse the messy pull-ups and SDA/SCL wires, I had proper jumpers and stuff but I was testing things)

The ADXL chip works - I’ve got it hooked up to my Raspberry Pi and I’m getting readings from it with that.
The address 0x53 is correct - it works on the Pi (but the code never gets to the address bit anyway).
I’ve also tried both the TWI and the software (assembler) version of the i2cmaster lib with the same results.
I’ve set the clock frequency to 20mhz for the TWI version, and the pins to 4 and 5 on the C port for the software version.

I also have a BlueMate Bluetooth chip on the serial port just to be able to communicate some debugging (which works fine).

I’ve given up on trying to solve this myself… Anyone with some helpful advice? Thanks.

Hi guys,

I thought I posted a topic before about this but it never appeared…

I’m having problems communicating with a SparkFun ADXL345 accelerator chip from a Baby Orangutan B-328 via I2C and Peter Fleury’s i2cmaster lib. I can init and start I2C with the correct address (0x53) but when I’m writing to it the code for waiting for ack just hangs. The chip works, I’m able to hook it up to my Raspberry Pi and read values from it no problem.

My code:

i2c_init();
i2c_start_wait(0x53 + I2C_WRITE);
i2c_write(0x2D, 0); // for example, anything fails
i2c_stop();
while (1) {}

The part of the i2cmaster i2c_write code that freezes:

// wait until transmission completed
while(!(TWCR & (1<<TWINT)));

I’m using a voltage divider to go from 5v to ~3.4v since the ADXL345 wants <3.6v.
I’m also using pull-up resistors of 4.7k for the SDA and SCL pins, which I’ve confirmed are pulling the pins to 3.4v.
The CS pin is pulled high to enable I2C.
The SDO pin is pulled low to enable the 0x53 address.

What’s happening is, the i2c_write is pulling the pins low but then the SCL pin is never pulled high again… I guess that’s why it never leaves the loop? The SDA pin is being pulled high however (at a lower voltage though… like 2.9v). I’ve tried with different pull-up resistor values to no avail. As I said previously, the pull-ups does work when the i2c is not used (SDA and SCL are pulled high).

Anyone with some helpful advice? I’ve been battling this for several days now… :frowning: Thanks.

See response at forum.sparkfun.com/viewtopic.php?f=7&t=39126