SparkFun Forums 

Where electronics enthusiasts find answers.

Discussions on the software and hardware for Atmel's STK standard.
By swemaniac
#174402
Hi guys,

There are a lot of topics like this but I can't understand what's going on here.. I'm a programmer but a noob at electronics.

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:
Code: Select all
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:
Code: Select all
// 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.

Image

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.. :( Thanks.
By jremington
#174414
I think there may be confusion about 7-bit versus 8-bit device addressing. Here is what the data sheet says:
An alternate I2C address of 0x53 (followed by the R/W bit) can be chosen by grounding the ALT ADDRESS pin (Pin 12). This translates to 0xA6 for a write and 0xA7 for a read.
So, try A6.

Also, in the version of Fleury's code that I have, i2c_write() takes a single byte argument. I don't use those routines anymore, and instead use a simpler set of routines that I cobbled together from other sources. They are posted on the Pololu forum (see the last post in the thread) at http://forum.pololu.com/viewtopic.php?f=32&t=8919 They should work, with very minor modifications, on the Baby-O. They include a simple address scanner, which is very convenient to see if all your devices are working.
By swemaniac
#174457
jr - I can't believe it, it seems to be working just with that address modification. I must have missed the part about A6/A7 in the datasheet, and in every example I've seen they're using 0x53. And i2c_start worked with 0x53, but not with another address. Only A6 works for both read and write ops though.

Thank you!