void f3d_gyro_getdata(float *pfData) {
  
  uint8_t tmpbuffer[6] ={0};
  int16_t RawData[3] = {0};
  uint8_t tmpreg = 0;
  float sensitivity = 0;
  int i =0;
  
  f3d_gyro_read(&tmpreg,0x23,1);      // Read the control register (CRTL4) 
  f3d_gyro_read(tmpbuffer,0x28,6);    // Read the data for all 4 axis
  
  /*  for (i=0;i<6;i++) { */
  /*   printf("%x ",tmpbuffer[i]); */
  /* } */
  /* printf("\n"); */

  /* check in the control register 4 the data alignment (Big Endian or Little Endian)*/
  if(!(tmpreg & 0x40)) {
    /* printf("a\n"); */
    for(i=0; i<3; i++) {
      RawData[i]=(int16_t)(((uint16_t)tmpbuffer[2*i+1] << 8) + tmpbuffer[2*i]);
    }
  }
  else {
    /* printf("b\n"); */
    for(i=0; i<3; i++) {
      RawData[i]=(int16_t)(((uint16_t)tmpbuffer[2*i] << 8) + tmpbuffer[2*i+1]);
    }
  }
   
  /* Switch the sensitivity value set in the CRTL4 */
  switch(tmpreg & 0x30) {
  case 0x00:
    sensitivity=L3G_Sensitivity_250dps;
    break;
    
  case 0x10:
    sensitivity=L3G_Sensitivity_500dps;
    break;
    
  case 0x20:
    sensitivity=L3G_Sensitivity_2000dps;
    break;
  }
  /* divide by sensitivity */
  for(i=0; i<3; i++) {
    pfData[i]=(float)RawData[i]/sensitivity;
  }
}
/*gets the data*/
void f3d_gyro_getdata(float *pfData) {
	//
	//
	int16_t RawData[3];
	uint8_t tmpbuffer[6];
	int i;
	//We are going to write some data to the gyro
	f3d_gyro_write(tmpbuffer,0x28,6);
	//Then we are going to read it
	f3d_gyro_read(tmpbuffer,0x28,6);
	//casting the data retreiving from tmpbuffer to raw data
	for(i=0; i<3; i++) {
		RawData[i]=(int16_t)(((uint16_t)tmpbuffer[2*i+1] << 8) + tmpbuffer[2*i]);
	}
	//adjusting the data with the sensitivity
	for(i=0; i<3; i++) {
		pfData[i]=(float)RawData[i]/L3G_Sensitivity_500dps;
	}
}
示例#3
0
void f3d_gyro_getdata(float *pfData) {
  
  uint8_t tmpbuffer[6];
  int i;
  int16_t RawData[3];

  f3d_gyro_read(tmpbuffer,0x28,6); 

  for(i=0; i<3; i++) 
  {
    RawData[i]=(int16_t)(((uint16_t)tmpbuffer[2*i+1] << 8) + tmpbuffer[2*i]);
  }

  #define GYRO_Sensitivity_500dps (float) 57.1429f

  for(i=0; i<3; i++) {
    pfData[i]=(float)RawData[i]/GYRO_Sensitivity_500dps;
    //printf("in gyro %d\n", RawData[i]/GYRO_Sensitivity_500dps);
  }

}