AnsweredAssumed Answered

Some problems with the initialization of ADXL372

Question asked by edc on May 20, 2018
Latest reply on May 21, 2018 by jwang

I used the ADXL372 vibration sensor, MPU is stm32L452RE, and I used the No-Os driver of ADXL372 provided by analog(ADXL372 - No-OS Driver [Analog Devices Wiki] ). I have some problems.

1: initialization needs to be written 5 times, otherwise it will not be able to read normally.

2: If it is powered on again, it will enter a hardware interrupt and will not work.
3: Can I use adxl372_get_accel_data () in FULL_BW_MEASUREMENT model and set FIFO in FIFO BYPASSED mode?

 

//=========================== include =========================================

#include "board.h"

#include "timers.h"

#include "scheduler.h"

#include "applications.h"

#include "vibration.h"

//=========================== main ============================================

int main(void)

{

   /* Initialize. */

   board_init();

   timers_init();

   scheduler_init();

 

   adxl372_dev *dev;

   adxl372_init_param param;

 

   param.spi_init = hspi2.Init;

   param.bw                        = ADXL372_BW_1600HZ;

   param.odr                       = ADXL372_ODR_3200HZ;

   param.op_mode                   = ADXL372_FULL_BW_MEASUREMENT;

   param.fifo_config.fifo_mode     = ADXL372_FIFO_BYPASSED;

   param.fifo_config.fifo_samples  = 0 ;

   adxl372_xyz_accel_data temp[1]={0};

 

   dev->spi_desc = &hspi2;

   adxl372_init(&dev, param);

   adxl372_init(&dev, param);

   adxl372_init(&dev, param);

   adxl372_init(&dev, param);

   adxl372_init(&dev, param);

 

   while(1){

   for(int i=0;i<6400;i++){

   adxl372_get_accel_data(dev, temp);

   }

   led_toggle();

   HAL_Delay(1000);

   }

   return 0;

}

 

 

int32_t adxl372_get_accel_data(adxl372_dev *dev,

       adxl372_xyz_accel_data *accel_data)

{

uint8_t buf[6];

uint8_t status1, status2;

uint16_t fifo_entries;

int32_t ret=0;

 

do {

adxl372_get_status(dev, &status1, &status2, &fifo_entries);

} while(!(ADXL372_STATUS_1_DATA_RDY(status1)));

 

 

ret = adxl372_spi_reg_read_multiple(dev,

    ADXL372_X_DATA_H,

    buf, 6);

 

if (ret)

return -1;

 

accel_data->x = (buf[0] << 4) | (buf[1] >> 4);

accel_data->y = (buf[2] << 4) | (buf[3] >> 4);

accel_data->z = (buf[4] << 4) | (buf[5] >> 4);

 

return ret;

}

Outcomes