I'm working with a FXLS8471 sensor with SPI.
My problem is that the reading of the 32 measurements of the FIFO does not coincide with the reading of the acceleration in the three axes. The sensor interrupted by filling the FIFO but when I try to read the 192 bytes in burst mode, the answer is incomprehensible.
Thank you
Carlos Canal
Hello Carlos,
Can you share your FXLS8471 configuration?
I also would like to take a look at your drain function which empty the FIFO.
Here my configuration if you want to compare:
// CONFIG
#define FXLS8471Q_CTRL_REG1 0x2A
#define FXLS8471Q_CTRL_REG2 0x2B
#define FXLS8471Q_CTRL_REG3 0x2C
#define FXLS8471Q_CTRL_REG4 0x2D
#define FXLS8471Q_CTRL_REG5 0x2E
#define FXLS8471Q_XYZ_DATA_CFG 0x0E
// ID
#define FXLS8471Q_WHO_AM_I 0x0D
#define FXLS8471Q_WHO_AM_I_VAL 0x6A
// FIFO
#define FXLS8471Q_F_SETUP 0x09
#define FXLS8471Q_F_STATUS 0x00
bool FXLS8471Q::vInit()
{
bool __b_result=false;
uint8_t __u8_temp=0xFF;
/* Check presence of the sensor to prevent SPI issues*/
if(bRead(FXLS8471Q_WHO_AM_I,&__u8_temp,1))
if(__u8_temp == FXLS8471Q_WHO_AM_I_VAL) //Check Sensor ID answer
/* Confugre the sensor */
if(bWrite(FXLS8471Q_CTRL_REG1 ,0x0)) //Standby mode
if(bWrite(FXLS8471Q_XYZ_DATA_CFG,0x2)) //0.976mg/LSB
/* Configure the FIFO */
if(bWrite(FXLS8471Q_F_SETUP ,0x80)) // FIFO mode2 : stops accepting new samples when overflowed
/* Configure the FIFO interrupt */
if(bWrite(FXLS8471Q_CTRL_REG3 ,0x82)) // FIFO, interrupt active high (rising event)
if(bWrite(FXLS8471Q_CTRL_REG4 ,0x40)) // FIFO interrupt enabled
if(bWrite(FXLS8471Q_CTRL_REG5 ,0x40)) // FIFO interrupt pin routed to INT1
if(bWrite(FXLS8471Q_CTRL_REG1 ,0x11)) //Set ODR to 400Hz & active mode
{
__b_result= true;
}
return __b_result;
}
#define FXLS8471Q_OUT_X_MSB 0x01
bool FXLS8471Q::bGetFIFOAccelData(int16_t __aai16_AccelData[32][3])
{
uint8_t __au8_Buffer[192];
int16_t __i16_SingleData;
uint8_t __u8_i,__u8_j;
bool __b_result;
if(__b_result = bRead(FXLS8471Q_OUT_X_MSB,(uint8_t*)__au8_Buffer,192))
{
for(__u8_i=0;__u8_i<32;__u8_i++)
{
for(__u8_j=0;__u8_j<3;__u8_j++)
{
__i16_SingleData = (int16_t)( (__au8_Buffer[__u8_j*2+__u8_i*6]<<8) + __au8_Buffer[__u8_j*2+__u8_i*6+1]);
__aai16_AccelData[__u8_i][__u8_j] = (int16_t)( ((float)__i16_SingleData)/4.0);
}
}
}
return __b_result;
}
Give me more information about your issues.
Thanks,
Anthony
Hello Anthony:
Thank you very much for your cooperation.
This weekend I report my code and put it on this page.
I have the following question: Can use a 800 Hz ODR to work with FIFO?
Thank you very much and best regards
Carlos Canal
Hello Anthony:
I do not get properly read accelerations 32 records stored in the FIFO.
For example, a reading of the acceleration of the three axes is: FF E0 FD 70 40 E8
Where axis X reading is = FF E0 (AX=0.0024g), axis Y=FD 70 (Ay=-0.0518g) and axis Z= 40 E8 (Az=0.9995g)
The following data correspond to a reading of the FIFO
For example, axis X =7E D8 , axis Y =20 60 and axis Z =00 40
7E D8 20 60 00 40 7E B8 20 38 00 34 7E D8 20 B8 00 30 7E D8 20 4C 00 18 7E E8 20 90 00 34 7E F8 20 64 00 18
7E F4 20 40 00 3C 7E F4 20 30 00 10 7E D8 20 78 00 3C 7E C0 20 50 7F F8 7E D0 20 40 00 44 7E B0 20 6C 00 44
7E E0 20 50 00 38 7E F0 20 7C 00 08 7E E0 20 38 00 00 7E D8 20 50 00 18 7E C0 20 5C 00 10 7E E0 20 74 00 18
7E E0 20 7C 00 10 7E D8 20 90 00 10 7E F0 20 30 00 30 7E E0 20 30 00 38 7E E8 20 60 00 44 7E E8 20 58 00 2C
7E E0 20 54 00 3C 7E F4 20 88 00 58 7E D8 20 60 00 2C 7E B8 20 6C 00 38 7E A8 20 64 00 20 7E A8 20 64 00 44
7E D0 20 60 00 04 7E E0 20 58 00 7C
La function para leer los 192 bytes es la siguiente:
void IMUREAD2(char reg1, int count, unsigned char array[]){
unsigned int i;
unsigned char value;
unsigned char dire, dire1;
dire =reg1 &0x7F;
dire1= reg1 &0x80;
CS_FX=0;
WByteSPI1(dire);
WByteSPI1(dire1);
for(i = 0; i < count; i++){
array[i]=RByteSPI1();//
}
Nop();
CS_FX=1;
return;
}
Thank you very much and best regards
Carlos Canal
Hello Carlos,
Here some suggestions & feedbacks:
"Where axis X reading is = FF E0 (AX=0.0024g), axis Y=FD 70 (Ay=-0.0518g) and axis Z= 40 E8 (Az=0.9995g)"
Regarding your conversion, AX should be negative FFE0 (hex) = -32 signed 16 bits) = -32/2² = -4 (signed 14bits) = -4*sensitivity (g or mg).
About your reading function, it seems good, I've got:
bool FXLS8471Q::bRead(uint8_t __u8_register, uint8_t* __au8_OutValue,uint8_t __u8_length)
{
bool __b_result = false;
uint8_t __u8_i;
_t_cs = 0;
_t_spi.write( (__u8_register&0x7F) | (0x0<<7) ) ;
_t_spi.write(__u8_register&0x80);
for(__u8_i=0;__u8_i<__u8_length;__u8_i++)
{
__au8_OutValue[__u8_i] = _t_spi.write(0x00) ;
}
_t_cs = 1;
__b_result = true;
return __b_result;
}
but again, check your conversion...
Are you sure the FIFO is enabled? How did you configure the sensor?
Thanks,
Anthony