AnsweredAssumed Answered

ADXL345 Configuration

Question asked by Cjp3323 on Nov 19, 2013

Hi,

 

     I'm using the ADXL345 for a project and am having trouble writing to the registers. I attempt to write to the the Data format reg followed by a write to the power ctl register. I then read back the values of these registers and display them to my terminal in which case a '0' appears meaning they are still at there reset values and not the ones I wrote. I have confirmed that I can in fact read a register appropriately as I have done it successfully with the device ID register. My function for writing to a register is:

 

#define ACCEL_W 0xA6

#define ACCEL_R 0xA7

 

void writeAccelReg(char reg, char byte)

{

    StartI2C3();

    IdleI2C3();

    MasterWriteI2C3(ACCEL_W);

    IdleI2C3();

    MasterWriteI2C3(reg);

    IdleI2C3();

    MasterWriteI2C3(byte);  //byte is the data to be stored in the reg

    IdleI2C3();

    StopI2C3();

}

 

and for reading a reg is:


char readAccelReg(char reg)

{

    char byte;

 

    StartI2C3();

    IdleI2C3();

    MasterWriteI2C3(ACCEL_W);

    IdleI2C3();

    MasterWriteI2C3(reg);

    IdleI2C3();

    RestartI2C3();

    IdleI2C3();

    MasterWriteI2C3(ACCEL_R);

    IdleI2C3();

    byte = MasterReadI2C3();

    NotAckI2C3();

    IdleI2C3();

    StopI2C3();

 

    return byte;

}

 

     I'm using a PIC24 and the schematic setup is attached. It's a breakout board from sparkfun used by many so the hardware should be configured correctly. The I2C lines also seem to be set up correctly since I can do successful read operations. I have also confirmed that no I2C errors occur during transmissions. I understand this is a very simple procedure which is why it's so bothersome in the first place. Ultimately, I would like confirmation that the software "should" in fact work so that I can focus on seeing if there's something wrong with the board and if I need to order another one. Let me know if you need any other relevant information.

 

Thanks,

Caleb


Attachments

Outcomes