AnsweredAssumed Answered

ADXL362 data always zero!!

Question asked by Awrak on Mar 26, 2015
Latest reply on Apr 3, 2015 by neilzhao

Hi,

I am trying to communicate with ADXL362 via SPI, the controller I'm using is PIC32MX150F128B. I'm trying to get the device ID but I'm getting all zeroes, I've tried reading X, Y & Z values but I'm still unlucky. My SPI loopback is working, so I've not been able to pin point the problem yet. My SPI baud rate is 2MHz, here is ADXL362 read and write code.

 

UINT8 ADXL362_Read(UINT8 reg_add){

    UINT8 u8_spi_read_data;

    UINT dummy;

 

    LATBbits.LATB15 = 0;                                                             // select slave device

    if(!TxBufFullSPI1()){WriteSPI1(SPI_READ_REGISTER_CMD);} // write adxl362 read-command to begin transmission

    while( !SPI1STATbits.SPIRBF);                                               // wait for transfer to complete

    dummy = SPI1BUF;                                                                 // Read the buffer to clear it

 

    if(!TxBufFullSPI1()){WriteSPI1(reg_add);}

    while( !SPI1STATbits.SPIRBF);                                               // wait for transfer to complete

    dummy = SPI1BUF;                                                                // Read the buffer to clear it

 

    if(SPI1STATbits.SPITBE) {SPI1BUF = 0x00;}                           // Transfer some dummy value

    while( !SPI1STATbits.SPIRBF);                                               // wait for transfer to complete

    u8_spi_read_data = SPI1BUF;

    LATBbits.LATB15 = 1;                                                             // release slave device

 

    return u8_spi_read_data;

}

 

 

BOOL ADXL362_Write(UINT8 reg_add,UINT8 reg_value){

    UINT dummy;

 

    LATBbits.LATB15 = 0;                                               // select slave device

    SPI1BUF = SPI_WRITE_REGISTER_CMD;               // write adxl362 write-command to begin transmission

    while( !SPI1STATbits.SPIRBF);                                  // wait for transfer to complete

    dummy = SPI1BUF;                                                    // Read the buffer to clear it

 

    SPI1BUF = reg_add;                                                  // write the 8-bit address

    while( !SPI1STATbits.SPIRBF);                                  // wait for transfer to complete

    dummy = SPI1BUF;                                                    // Read the buffer to clear it

 

    SPI1BUF = reg_value;                                                // write the 8-bit data

    while( !SPI1STATbits.SPIRBF);                                  // wait for transfer to complete

    dummy = SPI1BUF;                                                    // Read the buffer to clear it

    LATBbits.LATB15 = 1;                                                // release slave device

}

 

As per the ADXL362 data sheet I'm writing the Write/Read command first then the register address followed by the data if it is a write or a dummy value if it is a read. I've followed all the instructions as per the PIC and ADXL362 data sheet.

Any help is really appreciated.

 

Thanks!

Outcomes