adxl345 with spi

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 from this posthttp://www.cypress.com/forum/psoc-4-ble/psoc-4-ble-adxl362-problem i am trying to interface adxl345 with  cy8c4247AZI-M485. but i am not getting data . can you help me??

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

Have a look into adxl345's datasheet and adjust your CPHA and CPOL accordingly.

   

I would suggest you to put some more emphasis on a clear and readable structure of your program, no explanations yet, nearly no comments so far and bad indentation. Allocating variables in the middle of a function does not make reading easier... You even do not mention which board the project is made for and that you are accessing an adxl345. In a few months, aftert some other projects done, you will have difficulties to remember all those facts when looking at the sources.

   

 

   

Bob

View solution in original post

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

Two things to mention at first sight:

   

Writing to ss wil fail because it is connected (wired) to your SPI device. Remove the connection and uncheck in pin's configuration "Hardware Connect".

   

 

   

You are writing 2 bytes, but you are retrieving only one byte. Keep in mind that for every byte sent you get one byte back. So your while-loop will certainly end with the first byte in buffer, but without the second.

   

 

   

Bob

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

hey thanks for your reply. i made changes. but still i am getting 0x00. i have uploaded project here

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

Have a look into adxl345's datasheet and adjust your CPHA and CPOL accordingly.

   

I would suggest you to put some more emphasis on a clear and readable structure of your program, no explanations yet, nearly no comments so far and bad indentation. Allocating variables in the middle of a function does not make reading easier... You even do not mention which board the project is made for and that you are accessing an adxl345. In a few months, aftert some other projects done, you will have difficulties to remember all those facts when looking at the sources.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

ok thanks for your support

0 Likes
Anonymous
Not applicable

i set according to datasheet. but i am not getting data. 0x00 is device id register. i should return E5 . but i am getting 0x00

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

...and your latest project state?

   

 

   

Bob

0 Likes
Anonymous
Not applicable

thanks for your support. its working. actually i had made mistake in pin assignment

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

hello there i am getting E5 for device id. but when i am trying to read accelometer x data. i am also getting E5.

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

You do not send dummy bytes to get x values. Aren't the values 16 bit wide? You'll have to combine two bytes to form a 16 byte int.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

yes i need 10 byte. then how many dummy byte should i send??

0 Likes
Anonymous
Not applicable

i have some question. like if i want to on adxl345, i have to write 0x08 in 0x32 . so i write SPIM_WriteTxData two times.then it is necessary to write dummy bytes?

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

In SPI you get back exactly one byte for every byte you send.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

ok then why dummy byte required?? if i send 0x32 then i should get value from 0x32

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

When you send the first bit of your 0x32 the device does not yet know what you intend to do, but with every bit you send, at the very same time a bit is answered. So you get a dummy byte back at first. As a matter of fact you do not really "Read" from an SPI device, all communication happens bi-directionally at the same time. I would suggest you to read SPI datasheet and / or google for it. They can explain better than I can.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

yes i have read datasheet. but i had confusions. in most of datasheet they explain  with shift register

0 Likes
Anonymous
Not applicable

now can you please tell me that when i want to read, should i send dummy byte?? 

0 Likes
Anonymous
Not applicable

in last project, i have commented dummy byte. after uncommenting it, i am getting 0xE5 as x value. i have also used SPIM_ClearRxBuffer(); 

0 Likes
moro_1580446
Level 5
Level 5
100 replies posted 50 replies posted 25 replies posted

hi mr rushin010.could u runing adxl345 with spi or not?because i cant volved this problem!!!

0 Likes
lock attach
Attachments are accessible only for community members.
moro_1580446
Level 5
Level 5
100 replies posted 50 replies posted 25 replies posted

Hi Bob.I want to running ADXL345 with spi to learn complete interfacing g-sensor.but i cant get data from sensor by spi.can yu see my code and tell me where is mistakes?

   

tankyou dear Bob

0 Likes

Hey Moro,

Could you share the working and tested project of ADXL345 with SPI or I2C in Psoc4

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

Your read routine has an error:

   

For every byte the SPI interface gets, one byte is returned immediately. When the very first byte is sent, the interface does not "know" yet what to answer, so a dummy byte is returned which should be skipped. This you do.
SPI has no read command, so you must send dummy bytes to retrieve the information wanted. This you do not!

   

 

   

Bob

0 Likes