ADXL345

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

cross mob
moro_1580446
Level 5
Level 5
100 replies posted 50 replies posted 25 replies posted

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

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

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

View solution in original post

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

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...

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

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

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

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

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

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

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

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...

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

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

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

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...

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

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

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 friends.i want to ask question.please help me and show guidline to me that solve problem please...

   

I am running adxl345 on i2c and its worked very well.project file is attached here,but i am using fixed function.when i changed i2c component from fixed function to UDB it is not working.why it is happening?how can i solved problem?

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

Got a virus alert when I copied your project. Please check on your side...

   

 

   

Bob

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

    Accel_Xout_Val =((read_i2c(ADXL345_Addr,RA_DATAX1)<<8) | read_i2c(ADXL345_Addr,RA_DATAX0))+Cal_Xout_Val;

   


This will not work: read_i2c() returns a char which always will deliver 0x00 when shifted left by 8.

   

Another issue might be

   

    Data=I2C_MasterReadByte(I2C_ACK_DATA);            // Read from register
    //I2C_MasterReadByte(I2C_NAK_DATA);            // Read from register, last byte is NAKed

   


You just read one byte, but that should be NAKed, so

   

    Data=I2C_MasterReadByte(I2C_NAK_DATA);            // Read from register

   

would be correct.

   

 

   

Bob

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

Oh i dont know why it has virus but now i clear with kaspersky.please check my file.

   

tanks alot...

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

No virus warning in your code now. Some html files had been corrupted.

   

 

   

Bob

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

 I changed and do any thing in program but it is not work.dear Bob my program is working well when i select I2C component as fixed function and not working when i select UDB.i dont know why it is happening?

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

The reset signal is pulled high (1). So the UDB I2C will not run.

   

 

   

Bob

0 Likes