AnsweredAssumed Answered

Problem in reading ADXL345

Question asked by ptrpranathi on Dec 27, 2012

Hello All

 

I am using Stm32f2 series to which ADXL 345 is interfaced via SPI.

I am able to transmit the data as well as read the device ID.

But i have problem while reading Axis data (i.e MB) .

I always get Axis data zero even if i tilt my device in any direction.
Below is my code to read multi byte data

Any help in resolving this issue would be appreciated

 

void SPIXLReadSeq(uint8_t Reg,uint8_t Count)
{        
uint8_t  i = 0;
uint16_t RxBuffer;
CSLOW();       
Delay(2); 
/*send register address including Read-Bit and Multible Bytes-Bit */      
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);         
/*Send sequence of data to generate clock*/                         
SPI_I2S_SendData(SPI1, 0xFF);
RxBuffer=SPI_I2S_ReceiveData(SPI1);
SPI_I2S_SendData(SPI1, 0xFF);
RxBuffer=SPI_I2S_ReceiveData(SPI1);
SPI_I2S_SendData(SPI1, 0xFF);
RxBuffer=SPI_I2S_ReceiveData(SPI1);              
// while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);                
for(i=0;i < Count;i++)        
{
 
  SPI_I2S_SendData(SPI1, XL345_R | XL345_MB | ucReg);               
 
[i]= SPI_I2S_ReceiveData(SPI1);      
}       
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == SET);

CSHIGH();

}

 

Thanks

ptr

Outcomes