reading adxl345 data on i2c

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

hello there,i am interfacing adxl345 with  CY8CKIT-042-BLE kit. i have uploaded my main.c and main.h file here. can you tell me where i am doing mistake??

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Usinf I2C master component, addressing the adxl345 as slave with address 0xd1.

   

sendstart()

   

writebyte() write register address 0x32

   

sendRestart()

   

readByte() 5 times with ACK, last time with NAK

   

sendstop()

   

 

   

Bob

View solution in original post

0 Likes
15 Replies
Anonymous
Not applicable

i have also question if i want to read 6 bytes from 0x32 location. how to read it??

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Usinf I2C master component, addressing the adxl345 as slave with address 0xd1.

   

sendstart()

   

writebyte() write register address 0x32

   

sendRestart()

   

readByte() 5 times with ACK, last time with NAK

   

sendstop()

   

 

   

Bob

0 Likes
Anonymous
Not applicable

ok my adxl345 address is 0x53/ i have done in my code. but i am not getting data

0 Likes
Anonymous
Not applicable

this code is not working. can you tell me why??

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I do not believe that the I2C address is 0x53. The datasheet tells 0x32. Post a link to datasheet with a different address, please.

   

Can you please post your complete project, so that we all can have a look at all of your settings? To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

hello i have uploaded project here

0 Likes
Anonymous
Not applicable

https://www.sparkfun.com/datasheets/Sensors/Accelerometer/ADXL345.pdf in this data sheet , page 10 says that slave address is 0x53. i have also used adxl345 with another microcontroller with 0x53 address.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

So you are using the alternate I2C address, how should one know... But better check that!

   

Some general hints: a .h file usually contains declarations only, no definitions at al. Thus, a .h file does not allocate or use any memory, neither flash nor ram. So your main.h contains programs, which you should avoid. Have a look at the Cypress generated .h and .c files and how they communicate. look at the #if !defined or #ifndef conditional compilation at the beginning of the .h. This allows to #include them into several different files within a project.

   

You are using

   

        uint8 buffer_i2cy[1] ={0x33} ;
    I2C_I2CMasterSendStart(ADXL375_ADDR , I2C_I2C_WRITE_XFER_MODE);
    I2C_I2CMasterWriteByte(buffer_i2cy[0]);

   

Better will be

   

Status =    I2C_I2CMasterSendStart(ADXL375_ADDR , I2C_I2C_WRITE_XFER_MODE);
Status |=    I2C_I2CMasterWriteByte(0x32);

   

Status |=    I2C_I2CMasterSendRestart(ADXL375_ADDR, I2C_I2C_READ_XFER_MODE);
    x  =  I2C_I2CMasterReadByte( I2C_I2C_ACK_ADDR  );
    x1 =  I2C_I2CMasterReadByte( I2C_I2C_NAK_ADDR  );
Status |=    I2C_I2CMasterSendStop();

   

and check the status variable in debugger for != 0 which indicates an error.

   

 

   

Bob

Anonymous
Not applicable

hello there i followed your guidelines.but it didn't work for me. now

   

(1)i am working with  CY8C4247LQI-BL483 kit. i am trying to interface sparkfun adxl345. it is not working for me

   

(2)i tried to interface  sparkfun bmp180  with CY8C4247LQI-BL483. it works fine

   

(3) i interfaced sparkfun adxl345 with CYBLE-022001-EVAL. it works fine

   

 

   

now problem is between CY8C4247LQI-BL483 and sparkfun adxl345. 

   

 

   

can anyone tell me?? what is solution of this??

0 Likes

You said in the post above that you had it working with the CYBLE-022001-EVAL.  So take that project, and use the Device Selector from the Project Menu and change the device to CY8C4247LQI-BL483.  Change the Pin assignments for I2C if needed, then build and program and it should work fine.

   

I do this all the time without issues.

   

 

   

/edit: spelling fixes

0 Likes
DaBr_1233126
Level 4
Level 4
10 likes given 5 likes given First like received

If you had it working with the CYBLE-022001-EVAL, all you should have had to do was use the device selector and change devices to the CY8C4247LQI-BL483 and you would be done.  Well, I would check that the pins are still assigned how you wanted them, but otherwise code would have been the same.

   

I have used both PSoC and PRoC to interface to an MMA8451Q and this is all I have had to do to change between boards.  (I have several homemade boards with different devices I use for testing code and design changes, so I am doing this all the time...)

0 Likes
Anonymous
Not applicable

i have already selected device CY8C4247LQI-BL483. otherwise code can't fuse in devices. iam facing this problem in adxl345. i have also used mma8451Q. its working fine for me

0 Likes
DaBr_1233126
Level 4
Level 4
10 likes given 5 likes given First like received

Have you gotten this to work yet?  If not, post your project and I will test on my hardware.  I have the sparkfun module you are using.

0 Likes
lock attach
Attachments are accessible only for community members.
andreacassigoli
Level 1
Level 1
Welcome! First question asked First reply posted

Hi all,

I retrieved the project "adxl345.zip" and improved to work on my CY8CKIT-042-BLE kit.

I implemented single and multiple read.

Thank you all.

I hope evryone will appreciate if I attach my working project.

0 Likes
lock attach
Attachments are accessible only for community members.

Hi @andreacassigoli @Bob_Marlowe @DaBr_1233126 

I retrieved the above project and executed it, where my x,y, and z values do not change when I move the adxl345 sensor.

Could you Check my code? and tell me where I made a mistake because the x,y, and z values are not changing when I read from registers, Where I change the position of my sensor. once Check the flow where I made a mistake in I2C, 

PFA of the project.

0 Likes