ADXL345 | Cypress Semiconductor

ADXL345

Summary: 8 Replies, Latest post by Bob Marlowe on 18 Oct 2016 02:50 AM PDT
Verified Answers: 2
Last post
Log in to post new comments.
m.roshandelpoor_1580446's picture
User
29 posts

Hi freinds;

I want to running adxl345 by psoc5 but i cant runing in i2c or spi peripheral.older topic is not useful for me.

Anyone have any example code for interfacing a 5LP to use correct programing  for relationship between master and slave in i2c or spi , or tested psoc creator file for adxl345?

Roshandel

m.roshandelpoor_1580446's picture
User
29 posts

My psoc is CY5888LTI-LP097 please help me for solve problem?

little example for psoc is one of most problem with them.tanks for attention...

user_1377889's picture
User
9590 posts

Welcome in the forum Roshandel.

I would suggest you to use I2C interface. Wire your ADXL345 as shown in the datasheet.

Are you using a Cypress development/prototyping Kit? Which one??

Place an I2C Master component onto your topdesign. Do not forget the required pullup resistors. ADXL's I2C address will be 0x1D or 0x52 depending on the level of the AltAddress pin.

Byte I2C interface is quite simple: After setting up the component and starting it you use

    I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE);    // Initialize a transaction for writing
    I2C_MasterWriteByte(Register);                // Indicate which register you want to write to
    I2C_MasterWriteByte(Value);                // Write to register
    I2C_MasterSendStop();                    // End of transaction

When you want to read from a device you use (example for reading two bytes

    I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE);    // Initialize a transaction for writing
    I2C_MasterWrite(Register);                // Indicate which register you want to write to
    I2C_MasterSendRestart(DeviceAddress,I2C_READ_XFER_MODE);
    I2C_MasterReadByte(I2C_ACK_DATA);            // Read from register
    I2C_MasterReadByte(I2C_NAK_DATA);            // Read from register, last byte is NAKed
    I2C_MasterSendStop();                    // End of transaction

Not too difficult. Keep in mind that most of the APIs (except those for reading a byte) return a status byte which, when non-zero indicate an error condition.

The high-level APIs must be used in this way:

Writing to slave Count bytes
I2C_MasterWriteBuf(SlaveAddress,DataPtr,Count,I2C_MODE_COMPLETE_XFER);

Reading from Slave sending register byte first:
I2C_MasterWriteBuf(SlaveAddress,&RegAddress,1,I2C_MODE_NO_STOP);
I2C_MasterReadBuf(SlaveAddress,DataPtr,Count,I2C_MODE_REPEAT_START);

Bob

 

 

m.roshandelpoor_1580446's picture
User
29 posts

Tanks for your description MR Marlowe,but i want examples or psoc creator project that i can see and running.but my problem is i2c peripheral,i think because it is not sync with sensor.i dont now why.can you give me a sample?

my psoc is cy8ckit-059 prototyping kit.

tanks

user_1377889's picture
User
9590 posts

I2C "is not sync with sensor" What do you mean with that (language barrier, please explain)

"why.can you give me a sample?" Because I would have to write it.

Start Creator. At Start page scroll to "Find Code Example"

or

Right click on the I2C Master component and select "Find Code Example"

 

Bob

m.roshandelpoor_1580446's picture
User
29 posts

Excuse me Bob Marlowe for language barrier.I test adxl345 with avr and work verygood.now i want to use header of avr from codevision in psoc creator.I did it and change format of header on psoc creator,but it is not work.can you see my code?and tell me where is mistake.it is  important for me to run with psoc.tanks alot...

Attachments: 
user_1377889's picture
User
9590 posts

The project compiles fine exept the warnings concerning the #pragma which is installation/compiler dependent code, you may delete them.

What is really strange is the fact that in your .h file are the definitions (code) for many variables and functions. Normally a .h file only contains declarations (also known as function prototypes or forward declarations) and declarations of external variables. So a k. file never allocates code or ram space and can be #included several times in a project without conflicts.

All those definitions go into a corresponding (usually same name) .c file which #includes the .h file.

 

The I2C address of your ADCL is wrong. Creator expects a 7 bit address as listed in the ADXL manual, so not 0xa6 but 0x53.

 

Bob

m.roshandelpoor_1580446's picture
User
29 posts

This .h code worked very well in avr and calculate x , y , z and calibration to calculate exact.I deleted #pragma but it is not working right now.Then i changed I2C address of 0xa6 to 0x53 and 0x1d but not working again.

Even when i test i2c or spi from psoc creator on my  cypress,not sending and recieving.I want to test your code sample for adxl and check with my code to find mistake?

this picture of adxl345 running by avr...

Attachments: 
user_1377889's picture
User
9590 posts

You do not start the I2C interface. Put a I2C_1_Start() before accessing the ADXL.

As you prove with your picture: Even badly written software can run correctly. The problems tend to start when platform changes are needed.

 

Bob

Log in to post new comments.