Exemplo n.º 1
0
void f3d_gyro_init(void) {
  uint8_t ctrl1 = 0x00; 
  uint8_t ctrl4 = 0x00;

  f3d_gyro_interface_init();

  // CTRL1 Register
  // Bit 7:6 Data Rate: Datarate 0
  // Bit 5:4 Bandwidth: Bandwidth 3
  // Bit 3: Power Mode: Active
  // Bit 2:0 Axes Enable: X,Y,Z enabled
  ctrl1 |= (uint8_t) (((uint8_t)0x00) |\
		      ((uint8_t)0x30) |\
		      ((uint8_t)0x08) |\
		      ((uint8_t)0x07));    
  
  // CTRL4 Register 
  // Bit 7 Block Update: Continuous */
  // Bit 6 Endianess: LSB first  */
  // Bit 5:4 Full Scale: 500 dps */
  ctrl4 |= (uint8_t) (((uint8_t)0x00) |\
  		      ((uint8_t)0x00) |\
		      ((uint8_t)0x10));      


  f3d_gyro_write(&ctrl1, 0x20, 1);
  f3d_gyro_write(&ctrl4, 0x23, 1);
}
Exemplo n.º 2
0
//the init function to be called in your main.c
void f3d_gyro_init(void) {
  //
  //SETTING THE CONTROL REGISTERS 
  f3d_gyro_interface_init();
  // CTRL1 Register 
  // Bit 7:6 Data Rate: Datarate 0
  // Bit 5:4 Bandwidth: Bandwidth 3
  // Bit 3: Power Mode: Active
  // Bit 2:0 Axes Enable: X,Y,Z enabled
  uint8_t ctrl1;
  uint8_t ctrl4;
	
  ctrl1 |= (uint8_t) (((uint8_t)0x00)|		
		      ((uint8_t)0x30)|		
		      ((uint8_t)0x08)|		
		      ((uint8_t)0x07));
  // CTRL4 Register 
  // Bit 7 Block Update: Continuous */
  // Bit 6 Endianess: LSB first  */
  // Bit 5:4 Full Scale: 500 dps */
  ctrl4 |= (uint8_t) (((uint8_t)0x00)|			
		      ((uint8_t)0x00)|				     
		      ((uint8_t)0x10));

  f3d_gyro_write(&ctrl1, 0x20, 1);
  f3d_gyro_write(&ctrl4, 0x23, 1);


  GPIO_SetBits(GPIOE, GPIO_Pin_3);
}
/*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;
	}
}