AnsweredAssumed Answered

Can't Seem to Accurately Read ANY ADXL362 Register

Question asked by tomjoy94 on Feb 25, 2015
Latest reply on Mar 11, 2015 by neilzhao

Hi,

 

I'm using a PIC18f46k20 to work with m ADXL362 Accelerometer, and regardless of what register  attempt to read i always receive the same result. I can see I'm sending the correct data to my ADXL as I'm using an oscilloscope and can see the read command(0x0B) followed by the Address(0x02 for example) and then the 0x00 to get the value back, however I never actually get a correct value. I just get the same value over and over again...

 

So my questions are, to read a register do I need to do the soft reset first? or should I be able to read register straight away?

Is there anyway to test the accelerometer is actually working? other than reading a known register? As I'm near certain my SPI interfacing code is correct as the output from the PIC is seen on the oscilloscope...

 

For those interested, SPI interface code =

 

    TRISCbits.TRISC5 = 0;       // Serial data out SDO //RC5

    TRISCbits.TRISC4 = 1;       // SDI   //RC4

    TRISCbits.TRISC3 = 0;       // SCK   //RC3

    TRISAbits.TRISA5 =0;       // SS pin select //17.3.3

   

    // Initialise SPI1

    SSPCON1bits.SSPEN = 0;     // Disables and resets pins as I/O

    SSPCON1bits.SSPM3 = 0;

    SSPCON1bits.SSPM2 = 0;

    SSPCON1bits.SSPM1 = 0;   //Synchronous Serial Port Mode Select Bits //SPI Master Mode Clock = Fosc/4

    SSPCON1bits.SSPM0 = 0;

 

     SSPCON1bits.CKP = 0;       // Idle state for clock is a low level

     SSPSTATbits.CKE = 1;        // Output changes on clock transition from idle to active - NEEDS TO BE OPPOSITE OF CPHA = 0

     SSPSTATbits.SMP = 1; // Input data sampled at end of data output time

     SSPCON1bits.SSPEN = 1;      // Enables serial port, SCK, SDO, SDI and SS pins are set as serial port pins

   

And Example of read command sent to ADXL362 =


     ss = 0;

     WriteSPI(0x0B);

     while (SSPSTATbits.BF = 0);

     ReadSPI();

 

     WriteSPI(0x02);

     while (SSPSTATbits.BF = 0);

     ReadSPI();

 

     WriteSPI(0x00);

     while (SSPSTATbits.BF = 0);

     ReadSPI();

     ss= 1;

 

Thanks for any hep you can give!

 

Tom

Outcomes