i2c code working on 14m2 but not 20x2

Hi, I have an adxl345 accelerometer breakout board from sparkfun.
I have it working with my 14m2 chip.

Here is my code:

Code:
setfreq m32

HI2CSETUP I2CMASTER, 0xA6, i2cfast_32, i2cbyte

HI2COUT 0x31,(0x01) 'Put the ADXL345 into +/- 4G range
HI2COUT 0x2D,(0x08) 'Put the ADXL345 into Measurement Mode 

main:

HI2CIN 0x32,(b1,b2,b3,b4,b5,b6) 'read x1,x2,y1,y2,z1,z2 values
low b.5
debug
goto main
however now i need to get it working with a 20x2 chip.
I am using the exact same code, and I get 255 for all the values (b2-b6) except b1 is always 167.

The SDO pin is connected to ground, CS pin is connected to VCC

SCL is connected to b.7, SDA is connected to b.5 both are pulled high by 10k resistors


I can post pictures of the circuit if i need to but I think the problem is most likely in the code.
 

marks

Senior Member
Hi plasmaninjaa ,
try a pause after set frequency
Code:
setfreq m32
pause 200
HI2CSETUP I2CMASTER, 0xA6, i2cfast_32, i2cbyte

HI2COUT 0x31,(0x01) 'Put the ADXL345 into +/- 4G range
HI2COUT 0x2D,(0x08) 'Put the ADXL345 into Measurement Mode 

main:

HI2CIN 0x32,(b1,b2,b3,b4,b5,b6) 'read x1,x2,y1,y2,z1,z2 values
low b.5
debug
goto main
 
It didnt work :(

I just disconnected the sda and scl pins completely from the picaxe and i get the same values (b1 = 167, b2-b6 = 255) so the picaxe isnt getting any information from the adxl345.

I've gone back and forth like 3 times. It works perfectly every time on the 14m2.
 

Rick100

Senior Member
The pullups for the scl and sda lines are supposed to be 4.7K . You might try using i2cslow in case it's a speed problem.
 
I tried i2cslow, i2cslow_64 (and every other speed matching it to the "setfreq") and none of those worked.
I also put in some 4.7k resistors instead. Still nothing.
 

Goeytex

Senior Member
It may be debug causing some trouble.

Try changing Main to:

Code:
main:

    HI2CIN 0x32,(b1,b2,b3,b4,b5,b6) 'read x1,x2,y1,y2,z1,z2 values
    low b.5
    sertxd (#b1," ",#b2," ",#b3," ",#b4," ",#b5," ",#b6,cr,lf)  [COLOR="#008000"] '//Get rid of debug and use sertxd[/COLOR]
    pause 1000   'Slow it down for testing

goto main
Decrease the pause 1000 to read faster.
 
Was it the low b.5 which is the sda line?
yep. I had that because I had written this code a long time ago and was pwming an led based on the tilt using a 14m2 chip.
I removed all the pwm parts of the code, but for some reason thought low b.5 was part of the I2C code and not my pwming of the led.

2 hours down the drain... atleast it works now :)
 

Goeytex

Senior Member
2 hours is better than 2 days.

Ive been working on a problem for about 2 days now. Not Picaxe related but code / hardware related. Maybe I'll get it tomorrow.
 
wow 2 days is alot! After hours of trying to figure a problem late at night, usually after a nights sleep i'll figure out what I was doing wrong within minutes the next day.
good luck!
 
Top