2014-11-20 12:22 PM
Hi guys,
I am working on the L3GD20 embeeded in the stm32f3 discovery board. I came with this code which gives me 0 on the 3 axes even when i move the board. any suggestions please?#include ''stm32f3_discovery_l3gdh''
void
init_Gyro()
{L3GD20_InitTypeDef Gyro_init;
L3GD20_FilterConfigTypeDef Gyro_filter;
Gyro_filter.HighPassFilter_Mode_Selection=L3GD20_HPM_NORMAL_MODE ;
Gyro_filter.HighPassFilter_CutOff_Frequency=L3GD20_HPFCF_2;
//3.5 hz
Gyro_init.Power_Mode=L3GD20_MODE_ACTIVE;
Gyro_init.Output_DataRate=L3GD20_OUTPUT_DATARATE_2;
//190 hz
Gyro_init.Axes_Enable=L3GD20_AXES_ENABLE ;
Gyro_init.Band_Width=L3GD20_BANDWIDTH_4;
//25 hz
Gyro_init.BlockData_Update=1;
//no update until data read
Gyro_init.Endianness=0;
Gyro_init.Full_Scale=L3GD20_FULLSCALE_500;
L3GD20_Init(&Gyro_init);
L3GD20_FilterConfig(&Gyro_filter);
L3GD20_FilterCmd(L3GD20_HIGHPASSFILTER_ENABLE);
}
void
GyroRead(uint8_t *GyropBuffer)
{
L3GD20_Read(GyropBuffer,L3GD20_OUT_X_L_ADDR, 6);
}
int
main(
void
)
{
uint8_t GyroBuffer[6]={0,0,0,0,0,0};
init_Gyro();
while
(1)
{GyroRead(GyroBuffer);
}
return
(1);
}
2014-11-21 12:33 AM
Actually i figured it out by looking at the demo example.
2014-11-21 12:14 PM
Actually after reading the demo example and the l3gd20 datasheet, i came with code.
The gyro gives one time and never do it again .Which is weird. Does somebody have any suggestions?#include ''stm32f3_discovery_l3gdh''
int sensitivity=500;
void init_Gyro()
{L3GD20_InitTypeDef Gyro_init;
L3GD20_FilterConfigTypeDef Gyro_filter;
Gyro_init.Power_Mode=L3GD20_MODE_ACTIVE;
Gyro_init.Output_DataRate=L3GD20_OUTPUT_DATARATE_1; //190 hz
Gyro_init.Axes_Enable=L3GD20_AXES_ENABLE ;
Gyro_init.Band_Width=L3GD20_BANDWIDTH_4; //25 hz
Gyro_init.BlockData_Update=L3GD20_BlockDataUpdate_Single;
Gyro_init.Endianness=L3GD20_BLE_LSB;
Gyro_init.Full_Scale=L3GD20_FULLSCALE_500;
L3GD20_Init(&Gyro_init);
Gyro_filter.HighPassFilter_Mode_Selection=L3GD20_HPM_NORMAL_MODE ;
Gyro_filter.HighPassFilter_CutOff_Frequency=L3GD20_HPFCF_2;
L3GD20_FilterConfig(&Gyro_filter);
L3GD20_FilterCmd(L3GD20_HIGHPASSFILTER_ENABLE);
}
void GyroRead(float *Gyrodata)
{uint8_t Gyrobuffer[6] ={0};
L3GD20_Read(Gyrobuffer,L3GD20_OUT_X_L_ADDR, 6);
int16_t RawData[3] = {0,0,0};
uint8_t tmpreg = 0;
int i =0;
L3GD20_Read(&tmpreg,L3GD20_CTRL_REG4_ADDR,1);
if(!(tmpreg & 0x40))
{
for(i=0; i<3; i++)
{
RawData[i]=(int16_t)(((uint16_t)Gyrobuffer[2*i+1] << 8) + Gyrobuffer[2*i]);
}
}
else
{
for(i=0; i<3; i++)
{
RawData[i]=(int16_t)(((uint16_t)Gyrobuffer[2*i] << 8) + Gyrobuffer[2*i+1]);
}
}
/* divide by sensitivity */
for(i=0; i<3; i++)
{
Gyrodata[i]=(float)RawData[i]/sensitivity;
}
}
int main(void)
{
float Gyrodata[3]={23,23,23};
float x,y,z=25;
init_Gyro();
while(1){
GyroRead(Gyrodata);
x=Gyrodata[1];
y=Gyrodata[2];
z=Gyrodata[3];
}
}