已回答假定已回答

ADXL345在正确得到ID后,无法获取XYZ数据

roky82 在 2018-2-23 詢問的問題
最後回覆由孙治国於2018-3-3提供

我芯片用的是realtek公司的蓝牙芯片,内核是ARM Cortex-M0。接线采用的是4线制的spi

我现在能获取到正确的ID值,但是在获取XYZ值时候返回的都是0;初始化程序如下
请教哪里有问题

void ADXL345_write_byte(uint8_t addr,uint8_t data)

{

  uint8_t sendBuf[2];

  sendBuf[0]=addr|0xC0;

  sendBuf[1]=data;

  //DBG_DIRECT("RegAddr=0x%2x",sendBuf[0]);

  SPI_SendBuffer(SPI0, sendBuf, 2);

 

x

 

void ADXL345_Ini(void)

{

  ADXL345_write_byte(0x31,0x2B);

  delayMS(2);

  ADXL345_write_byte(0x1E,0x00);

  delayMS(2);

  ADXL345_write_byte(0x1F,0x00);

  delayMS(2);

  ADXL345_write_byte(0x20,0x00);

  delayMS(2);

  ADXL345_write_byte(0x21,0x00);

  delayMS(2);

  ADXL345_write_byte(0x22,0x00);

  delayMS(2);

  ADXL345_write_byte(0x23,0x00);

  delayMS(2);

  ADXL345_write_byte(0x24,0x01);

  delayMS(2);

  ADXL345_write_byte(0x25,0x01);

  delayMS(2);

  ADXL345_write_byte(0x26,0x2B);

  delayMS(2);

  ADXL345_write_byte(0x27,0x00);

  delayMS(2);

  ADXL345_write_byte(0x28,0x09);

  delayMS(2);

  ADXL345_write_byte(0x29,0xFF);

  delayMS(2);

  ADXL345_write_byte(0x2A,0x80);

  delayMS(2);

  ADXL345_write_byte(0x2C,0x0D);

  delayMS(2);

  ADXL345_write_byte(0x2D,0x08);

  delayMS(2);

  ADXL345_write_byte(0x2E,0x80);

  delayMS(2);

  ADXL345_write_byte(0x2F,0x00);

 

  ADXL345_write_byte(0x38,0x00);

  delayMS(2);

}

結果