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