Пример #1
0
uint16_t LSM9DS0_begin( LSM9DS0_t* lsm_t, LMS9DS0_Init_t* init_t )
{
	#if (DEBUG0==1)
		uint8_t test[8];
	#endif
		uint8_t gTest, xmTest;
	if(init_t==NULL)
		init_t = &LMS_Device_Defaults;

	// Store the given scales in class variables. These scale variables
	// are used throughout to calculate the actual g's, DPS,and Gs's.
	lsm_t->gScale = init_t->gScl;
	lsm_t->aScale = init_t->aScl;
	lsm_t->mScale = init_t->mScl;

	// Once we have the scale values, we can calculate the resolution
	// of each sensor. That's what these functions are for. One for each sensor
	calcgRes(lsm_t); // Calculate DPS / ADC tick, stored in gRes variable
	calcmRes(lsm_t); // Calculate Gs / ADC tick, stored in mRes variable
	calcaRes(lsm_t); // Calculate g / ADC tick, stored in aRes variable

	// Now, initialize our hardware interface.
	#if(LSM_I2C_SUPPORT==1)
	if (lsm_t->interfaceMode == MODE_I2C)	// If we're using I2C
		LSM_initI2C();					// Initialize I2C
	else if (lsm_t->interfaceMode == MODE_SPI) 	// else, if we're using SPI
	#endif
		//LSM_initSPI();							// Initialize SPI

	// To verify communication, we can read from the WHO_AM_I register of
	// each device. Store those in a variable so we can return them.
	gTest  = gReadByte(lsm_t,WHO_AM_I_G);		// Read the gyro WHO_AM_I
	xmTest = xmReadByte(lsm_t,WHO_AM_I_XM);	// Read the accel/mag WHO_AM_I

	// Gyro initialization stuff:
	initGyro(lsm_t);		// This will "turn on" the gyro. Setting up interrupts, etc.
	setGyroODR(lsm_t,init_t->gODR); 		// Set the gyro output data rate and bandwidth.
	setGyroScale(lsm_t,lsm_t->gScale); 	// Set the gyro range

	// Accelerometer initialization stuff:
	initAccel(lsm_t); // "Turn on" all axes of the accel. Set up interrupts, etc.
	setAccelODR(lsm_t,init_t->aODR); // Set the accel data rate.
	setAccelScale(lsm_t,lsm_t->aScale); // Set the accel range.

	// Magnetometer initialization stuff:
	initMag(lsm_t); // "Turn on" all axes of the mag. Set up interrupts, etc.
	setMagODR(lsm_t,init_t->mODR); // Set the magnetometer output data rate.
	setMagScale(lsm_t,lsm_t->mScale); // Set the magnetometer's range.
	LSM9DS0_Update_Ctrl(lsm_t);
	lsm_t->update=UPDATE_ON_SET;

	#if (DEBUG0==1)
		I2CreadBytes(lsm_t->gAddress,CTRL_REG1_G,test,5);
		I2CreadBytes(lsm_t->xmAddress,CTRL_REG0_XM,test,7);
	#endif


	// Once everything is initialized, return the WHO_AM_I registers we read:
	return (xmTest << 8) | gTest;
}
uint16_t begin(LSM9DS0_t* imu, gyro_scale gScl, accel_scale aScl,
		mag_scale mScl, gyro_odr gODR, accel_odr aODR, mag_odr mODR)
{
	// Store the given scales in imu struct. These scale variables
	// are used throughout to calculate the actual g's, DPS,and Gs's.
	imu->gScale = gScl;
	imu->aScale = aScl;
	imu->mScale = mScl;

	// Once we have the scale values, we can calculate the resolution
	// of each sensor. That's what these functions are for. One for each sensor
	calcgRes(imu); // Calculate DPS / ADC tick, stored in gRes variable
	calcaRes(imu); // Calculate g / ADC tick, stored in aRes variable
	calcmRes(imu); // Calculate Gs / ADC tick, stored in mRes variable

	// To verify communication, we can read from the WHO_AM_I register of
	// each device. Store those in a variable so we can return them.
	uint8_t gTest = gReadByte(imu->gyro, WHO_AM_I_G);		// Read the gyro WHO_AM_I
	uint8_t xmTest = xmReadByte(imu->xm, WHO_AM_I_XM);	// Read the accel/mag WHO_AM_I
	
	// Gyro initialization stuff:
	initGyro(imu->gyro);	// This will "turn on" the gyro. Setting up interrupts, etc.
	setGyroODR(imu->gyro, gODR); // Set the gyro output data rate and bandwidth.
	setGyroScale(imu, imu->gScale); // Set the gyro range
}
Пример #3
0
/* ************************************************************************** */
uint16_t LSM9DS0_begin_adv( stLSM9DS0_t * stThis,
                            gyro_scale gScl,
                            accel_scale aScl,
                            mag_scale mScl,
                            gyro_odr gODR,
                            accel_odr aODR,
                            mag_odr mODR )
{
    // Default to 0xFF to indicate status is not OK
    uint8_t gTest = 0xFF;
    uint8_t xmTest = 0xFF;
    byte byDatas;

    byte byAddress = 0x1D;
    byte bySubAddress = 0x0F;

    // Wiat for a few millis at the beginning for the chip to boot
    WAIT1_Waitms( 200 );

    // Store the given scales in class variables. These scale variables
    // are used throughout to calculate the actual g's, DPS,and Gs's.
    stThis->gScale = gScl;
    stThis->aScale = aScl;
    stThis->mScale = mScl;

    // Once we have the scale values, we can calculate the resolution
    // of each sensor. That's what these functions are for. One for each sensor
    calcgRes(stThis); // Calculate DPS / ADC tick, stored in gRes variable
    calcmRes(stThis); // Calculate Gs / ADC tick, stored in mRes variable
    calcaRes(stThis); // Calculate g / ADC tick, stored in aRes variable

    // Now, initialize our hardware interface.
    if (stThis->interfaceMode == MODE_I2C)			// If we're using I2C
        initI2C(stThis);							// Initialize I2C
    else if (stThis->interfaceMode == MODE_SPI)		// else, if we're using SPI
        initSPI(stThis);							// Initialize SPI

    // To verify communication, we can read from the WHO_AM_I register of
    // each device. Store those in a variable so we can return them.
    gTest = gReadByte( stThis, WHO_AM_I_G );		// Read the gyro WHO_AM_I
    xmTest = xmReadByte( stThis, WHO_AM_I_XM );	// Read the accel/mag WHO_AM_I

    // Gyro initialization stuff:
    initGyro(stThis);	// This will "turn on" the gyro. Setting up interrupts, etc.
    LSM9DS0_setGyroODR(stThis, gODR); // Set the gyro output data rate and bandwidth.
    LSM9DS0_setGyroScale(stThis, stThis->gScale); // Set the gyro range

    // Accelerometer initialization stuff:
    initAccel(stThis); // "Turn on" all axes of the accel. Set up interrupts, etc.
    LSM9DS0_setAccelODR(stThis, aODR); // Set the accel data rate.
    LSM9DS0_setAccelScale(stThis, stThis->aScale); // Set the accel range.

    // Magnetometer initialization stuff:
    initMag(stThis); // "Turn on" all axes of the mag. Set up interrupts, etc.
    LSM9DS0_setMagODR(stThis, mODR); // Set the magnetometer output data rate.
    LSM9DS0_setMagScale(stThis, stThis->mScale); // Set the magnetometer's range.

    // Once everything is initialized, return the WHO_AM_I registers we read:
    return (xmTest << 8) | gTest;
}
Пример #4
0
bool LSM9DS0::newGData()
{
  const uint8_t dReadyMask = 0b00001000;
  uint8_t statusRegVal = gReadByte(STATUS_REG_G);
  if ((dReadyMask & statusRegVal) != 0)
  {
    return true;
  }
  return false;
}
Пример #5
0
void LSM330D::setGyroODR(gyro_odr gRate)
{
	// We need to preserve the other bytes in CTRL_REG1_G. So, first read it:
	uint8_t temp = gReadByte(CTRL_REG1_G);
	// Then mask out the gyro ODR bits:
	temp &= 0x0F;
	// Then shift in our new ODR bits:
	temp |= (gRate << 4);
	// And write the new register value back into CTRL_REG1_G:
	gWriteByte(CTRL_REG1_G, temp);
}
void setGyroODR(mraa_i2c_context gyro, gyro_odr gRate)
{
	// We need to preserve the other bytes in CTRL_REG1_G. So, first read it:
	uint8_t temp = gReadByte(gyro, CTRL_REG1_G);
	// Then mask out the gyro ODR bits:
	temp &= 0xFF^(0xF << 4);
	// Then shift in our new ODR bits:
	temp |= (gRate << 4);
	// And write the new register value back into CTRL_REG1_G:
	gWriteByte(gyro, CTRL_REG1_G, temp);
}
Пример #7
0
/**
	@brief	Read gyro.
			The return values are in dps units multiplied by factor of 100.
*/
void readGyro(int32_t* gx, int32_t* gy, int32_t* gz)
{
	uint8_t temp[6]; // We'll read six bytes from the gyro into temp
	float gScale = 245.0 / 32768.0; // 245dps/ADC ticks based on 2bit value
	int16_t x, y, z;
	float fx, fy, fz;
	const float factor = 100.0;

	temp[0] = gReadByte(OUT_X_L_G);
	temp[1] = gReadByte(OUT_X_H_G);
	temp[2] = gReadByte(OUT_Y_L_G);
	temp[3] = gReadByte(OUT_Y_H_G);
	temp[4] = gReadByte(OUT_Z_L_G);
	temp[5] = gReadByte(OUT_Z_H_G);

	x = (temp[1] << 8) | temp[0];
	y = (temp[3] << 8) | temp[2];
	z = (temp[5] << 8) | temp[4];

	// Convert the values
	fx = x * gScale * factor;
	fy = y * gScale * factor;
	fz = z * gScale * factor;

	*gx = (int)fx;
	*gy = (int)fy;
	*gz = (int)fz;
}
Пример #8
0
void LSM330D::setGyroScale(gyro_scale gScl)
{
	// We need to preserve the other bytes in CTRL_REG4_G. So, first read it:
	uint8_t temp = gReadByte(CTRL_REG4_G);
	// Then mask out the gyro scale bits:
	temp &= 0xCF;
	// Then shift in our new scale bits:
	temp |= gScl << 4;
	// And write the new register value back into CTRL_REG4_G:
	gWriteByte(CTRL_REG4_G, temp);
	
	// We've updated the sensor, but we also need to update our class variables
	// First update gScale:
	gScale = gScl;
	// Then calculate a new gRes, which relies on gScale being set correctly:
	calcgRes();
}
Пример #9
0
uint16_t LSM9DS0::begin(gyro_scale gScl, accel_scale aScl, mag_scale mScl, 
						gyro_odr gODR, accel_odr aODR, mag_odr mODR)
{
	// Store the given scales in class variables. These scale variables
	// are used throughout to calculate the actual g's, DPS,and Gs's.
	gScale = gScl;
	aScale = aScl;
	mScale = mScl;
	
	// Once we have the scale values, we can calculate the resolution
	// of each sensor. That's what these functions are for. One for each sensor
	calcgRes(); // Calculate DPS / ADC tick, stored in gRes variable
	calcmRes(); // Calculate Gs / ADC tick, stored in mRes variable
	calcaRes(); // Calculate g / ADC tick, stored in aRes variable
	
	// Now, initialize our hardware interface.
	if (interfaceMode == MODE_I2C)	// If we're using I2C
	{} //initI2C();					// Initialize I2C
	else if (interfaceMode == MODE_SPI) 	// else, if we're using SPI
		initSPI();							// Initialize SPI
	
	// To verify communication, we can read from the WHO_AM_I register of
	// each device. Store those in a variable so we can return them.
	uint8_t gTest = gReadByte(WHO_AM_I_G);		// Read the gyro WHO_AM_I
	uint8_t xmTest = xmReadByte(WHO_AM_I_XM);	// Read the accel/mag WHO_AM_I
	
	// Gyro initialization stuff:
	initGyro();	// This will "turn on" the gyro. Setting up interrupts, etc.
	setGyroODR(gODR); // Set the gyro output data rate and bandwidth.
	setGyroScale(gScale); // Set the gyro range
	
	// Accelerometer initialization stuff:
	initAccel(); // "Turn on" all axes of the accel. Set up interrupts, etc.
	setAccelODR(aODR); // Set the accel data rate.
	setAccelScale(aScale); // Set the accel range.
	
	// Magnetometer initialization stuff:
	initMag(); // "Turn on" all axes of the mag. Set up interrupts, etc.
	setMagODR(mODR); // Set the magnetometer output data rate.
	setMagScale(mScale); // Set the magnetometer's range.
	
	// Once everything is initialized, return the WHO_AM_I registers we read:
	return (xmTest << 8) | gTest;
}
Пример #10
0
void LSM9DS0_readGyro(LSM9DS0_t* lsm_t)
{
	uint8_t temp[6];
#if(DEBUG_R_G==1)
	temp[0]=gReadByte(lsm_t,OUT_X_L_G);
	temp[1]=gReadByte(lsm_t,OUT_X_H_G);
	temp[2]=gReadByte(lsm_t,OUT_Y_L_G);
	temp[3]=gReadByte(lsm_t,OUT_Y_H_G);
	temp[4]=gReadByte(lsm_t,OUT_Z_L_G);
	temp[5]=gReadByte(lsm_t,OUT_Z_H_G);
#else
	//uint8_t temp[6]; // We'll read six bytes from the gyro into temp
	gReadBytes(lsm_t,OUT_X_L_G, temp, 6); // Read 6 bytes, beginning at OUT_X_L_G
#endif
	lsm_t->gx = (temp[1] << 8) | temp[0]; // Store x-axis values into gx
	lsm_t->gy = (temp[3] << 8) | temp[2]; // Store y-axis values into gy
	lsm_t->gz = (temp[5] << 8) | temp[4]; // Store z-axis values into gz
}
Пример #11
0
void LSM330D::calLSM330D(float * gbias, float * abias)
{  
  uint8_t data[6] = {0, 0, 0, 0, 0, 0};
  int32_t gyro_bias[3] = {0, 0, 0}, accel_bias[3] = {0, 0, 0};
  uint16_t samples, ii;
  
  // First get gyro bias
  byte c = gReadByte(CTRL_REG5_G);
  gWriteByte(CTRL_REG5_G, c | 0x40);         // Enable gyro FIFO  
  delay(20);                                 // Wait for change to take effect
  gWriteByte(FIFO_CTRL_REG_G, 0x20 | 0x1F);  // Enable gyro FIFO stream mode and set watermark at 32 samples
  delay(1000);  // delay 1000 milliseconds to collect FIFO samples
  
  samples = (gReadByte(FIFO_SRC_REG_G) & 0x1F); // Read number of stored samples

  for(ii = 0; ii < samples ; ii++) {            // Read the gyro data stored in the FIFO
    int16_t gyro_temp[3] = {0, 0, 0};
    gReadBytes(OUT_X_L_G,  &data[0], 6);
    gyro_temp[0] = (int16_t) (((int16_t)data[1] << 8) | data[0]); // Form signed 16-bit integer for each sample in FIFO
    gyro_temp[1] = (int16_t) (((int16_t)data[3] << 8) | data[2]);
    gyro_temp[2] = (int16_t) (((int16_t)data[5] << 8) | data[4]);

    gyro_bias[0] += (int32_t) gyro_temp[0]; // Sum individual signed 16-bit biases to get accumulated signed 32-bit biases
    gyro_bias[1] += (int32_t) gyro_temp[1]; 
    gyro_bias[2] += (int32_t) gyro_temp[2]; 
  }  

  gyro_bias[0] /= samples; // average the data
  gyro_bias[1] /= samples; 
  gyro_bias[2] /= samples; 
  
  gbias[0] = (float)gyro_bias[0]*gRes;  // Properly scale the data to get deg/s
  gbias[1] = (float)gyro_bias[1]*gRes;
  gbias[2] = (float)gyro_bias[2]*gRes;
  
  c = gReadByte(CTRL_REG5_G);
  gWriteByte(CTRL_REG5_G, c & ~0x40);  // Disable gyro FIFO  
  delay(20);
  gWriteByte(FIFO_CTRL_REG_G, 0x00);   // Enable gyro bypass mode
  

  //  Now get the accelerometer biases
  c = xmReadByte(CTRL_REG5_A);
  xmWriteByte(CTRL_REG5_A, c | 0x40);      // Enable accelerometer FIFO  
  delay(20);                                // Wait for change to take effect
  xmWriteByte(FIFO_CTRL_REG, 0x40 | 0x1F);  // Enable accelerometer FIFO stream mode and set watermark at 32 samples
  delay(1000);  // delay 1000 milliseconds to collect FIFO samples

  samples = (xmReadByte(FIFO_SRC_REG) & 0x1F); // Read number of stored accelerometer samples

   for(ii = 0; ii < samples ; ii++) {          // Read the accelerometer data stored in the FIFO
    int16_t accel_temp[3] = {0, 0, 0};
    xmReadBytes(OUT_X_L_A, &data[0], 6);
    accel_temp[0] = (int16_t) (((int16_t)data[1] << 8) | data[0]);// Form signed 16-bit integer for each sample in FIFO
    accel_temp[1] = (int16_t) (((int16_t)data[3] << 8) | data[2]);
    accel_temp[2] = (int16_t) (((int16_t)data[5] << 8) | data[4]);  

    accel_bias[0] += (int32_t) accel_temp[0]; // Sum individual signed 16-bit biases to get accumulated signed 32-bit biases
    accel_bias[1] += (int32_t) accel_temp[1]; 
    accel_bias[2] += (int32_t) accel_temp[2]; 
  }  

  accel_bias[0] /= samples; // average the data
  accel_bias[1] /= samples; 
  accel_bias[2] /= samples; 

  if(accel_bias[2] > 0L) {accel_bias[2] -= (int32_t) (1.0/aRes);}  // Remove gravity from the z-axis accelerometer bias calculation
  else {accel_bias[2] += (int32_t) (1.0/aRes);}
 
  
  abias[0] = (float)accel_bias[0]*aRes; // Properly scale data to get gs
  abias[1] = (float)accel_bias[1]*aRes;
  abias[2] = (float)accel_bias[2]*aRes;

  c = xmReadByte(CTRL_REG5_A);
  xmWriteByte(CTRL_REG5_A, c & ~0x40);    // Disable accelerometer FIFO  
  delay(20);
  xmWriteByte(FIFO_CTRL_REG, 0x00);       // Enable accelerometer bypass mode
}
Пример #12
0
// This is a function that uses the FIFO to accumulate sample of accelerometer and gyro data, average
// them, scales them to  gs and deg/s, respectively, and then passes the biases to the main sketch
// for subtraction from all subsequent data. There are no gyro and accelerometer bias registers to store
// the data as there are in the ADXL345, a precursor to the LSM9DS0, or the MPU-9150, so we have to
// subtract the biases ourselves. This results in a more accurate measurement in general and can
// remove errors due to imprecise or varying initial placement. Calibration of sensor data in this manner
// is good practice.
void calLSM9DS0(LSM9DS0_t* lsm_t, float * gbias, float * abias)
{
  uint8_t data[6] 	= {0, 0, 0, 0, 0, 0};
  int16_t
  	gyro_bias[3] 	= {0, 0, 0},
  	accel_bias[3] 	= {0, 0, 0};
  int samples, ii;

  // First get gyro bias
  uint8_t c = gReadByte(lsm_t,CTRL_REG5_G);		//read modify write 
  gWriteByte(lsm_t, CTRL_REG5_G, c | 0x40);         	// Enable gyro FIFO
  delay(20);                                 	// Wait for change to take effect
  gWriteByte(lsm_t, FIFO_CTRL_REG_G, 0x20 | 0x1F);  	// Enable gyro FIFO stream mode and set watermark at 32 samples
  delay(1000);  								// delay 1000 milliseconds to collect FIFO samples

  samples = (gReadByte(lsm_t,FIFO_SRC_REG_G) & 0x1F); // Read number of stored samples

  for(ii = 0; ii < samples ; ii++) {            // Read the gyro data stored in the FIFO
    gReadBytes(lsm_t,OUT_X_L_G,  &data[0], 6);
    gyro_bias[0] += (((int16_t)data[1] << 8) | data[0]);
    gyro_bias[1] += (((int16_t)data[3] << 8) | data[2]);
    gyro_bias[2] += (((int16_t)data[5] << 8) | data[4]);
  }

  gyro_bias[0] /= samples; 						// average the data
  gyro_bias[1] /= samples;
  gyro_bias[2] /= samples;

  gbias[0] = (float)gyro_bias[0]*lsm_t->gRes; 			 // Properly scale the data to get deg/s
  gbias[1] = (float)gyro_bias[1]*lsm_t->gRes;
  gbias[2] = (float)gyro_bias[2]*lsm_t->gRes;

  c = gReadByte(lsm_t,CTRL_REG5_G);
  gWriteByte(lsm_t, CTRL_REG5_G, c & ~0x40);  			// Disable gyro FIFO
  delay(20);
  gWriteByte(lsm_t, FIFO_CTRL_REG_G, 0x00);   			// Enable gyro bypass mode


  //  Now get the accelerometer biases
  c = xmReadByte(lsm_t,CTRL_REG0_XM);
  xmWriteByte(lsm_t,CTRL_REG0_XM, c | 0x40);      	// Enable accelerometer FIFO
  delay(20);                                	// Wait for change to take effect
  xmWriteByte(lsm_t,FIFO_CTRL_REG, 0x20 | 0x1F);  	// Enable accelerometer FIFO stream mode and set watermark at 32 samples
  delay(1000); 	 								// delay 1000 milliseconds to collect FIFO samples

  samples = (xmReadByte(lsm_t,FIFO_SRC_REG) & 0x1F); 	// Read number of stored accelerometer samples

   for(ii = 0; ii < samples ; ii++) {          	// Read the accelerometer data stored in the FIFO
    xmReadBytes(lsm_t,OUT_X_L_A, &data[0], 6);
    accel_bias[0] += (((int16_t)data[1] << 8) | data[0]);
    accel_bias[1] += (((int16_t)data[3] << 8) | data[2]);
    accel_bias[2] += (((int16_t)data[5] << 8) | data[4]) - (int16_t)(1.0f/lsm_t->aRes); // Assumes sensor facing up!
  }

  accel_bias[0] /= samples; // average the data
  accel_bias[1] /= samples;
  accel_bias[2] /= samples;

  abias[0] = (float)accel_bias[0]*lsm_t->aRes; // Properly scale data to get gs
  abias[1] = (float)accel_bias[1]*lsm_t->aRes;
  abias[2] = (float)accel_bias[2]*lsm_t->aRes;

  c = xmReadByte(lsm_t,CTRL_REG0_XM);
  xmWriteByte(lsm_t,CTRL_REG0_XM, c & ~0x40);    // Disable accelerometer FIFO
  delay(20);
  xmWriteByte(lsm_t,FIFO_CTRL_REG, 0x00);       // Enable accelerometer bypass mode
}
Пример #13
0
void initGyro( LSM9DS0_t* lsm_t )
{
#if (DEBUG0==1)
		uint8_t test[5],test1[5],i;
#endif
	/* CTRL_REG1_G sets output data rate, bandwidth, power-down and enables
	Bits[7:0]: DR1 DR0 BW1 BW0 PD Zen Xen Yen
	DR[1:0] - Output data rate selection
		00=95Hz, 01=190Hz, 10=380Hz, 11=760Hz
	BW[1:0] - Bandwidth selection (sets cutoff frequency)
		 Value depends on ODR. See datasheet table 21.
	PD - Power down enable (0=power down mode, 1=normal or sleep mode)
	Zen, Xen, Yen - Axis enable (o=disabled, 1=enabled)	*/
	//gWriteByte(lsm_t, CTRL_REG1_G, 0x0F); // Normal mode, enable all axes
	lsm_t->gCtrl[0]=0b01111111;
#if (DEBUG0==1)
		gWriteByte(lsm_t, CTRL_REG1_G, lsm_t->gCtrl[0]);
		test[0] = gReadByte(lsm_t,CTRL_REG1_G);
		assert(test[0]==lsm_t->gCtrl[0]);
#endif
	/* CTRL_REG2_G sets up the HPF
	Bits[7:0]: 0 0 HPM1 HPM0 HPCF3 HPCF2 HPCF1 HPCF0
	HPM[1:0] - High pass filter mode selection
		00=normal (reset reading HP_RESET_FILTER, 01=ref signal for filtering,
		10=normal, 11=autoreset on interrupt
	HPCF[3:0] - High pass filter cutoff frequency
		Value depends on data rate. See datasheet table 26.
	*/
	//gWriteByte(lsm_t, CTRL_REG2_G, 0x25); // Normal mode, high cutoff frequency //0x00
	lsm_t->gCtrl[1]=0b00100101;
#if (DEBUG0==1)
		gWriteByte(lsm_t, CTRL_REG2_G, lsm_t->gCtrl[1]);
		test[1] = gReadByte(lsm_t,CTRL_REG2_G);
		assert(test[1]==lsm_t->gCtrl[1]);
#endif
	/* CTRL_REG3_G sets up interrupt and DRDY_G pins
	Bits[7:0]: I1_IINT1 I1_BOOT H_LACTIVE PP_OD I2_DRDY I2_WTM I2_ORUN I2_EMPTY
	I1_INT1 - Interrupt enable on INT_G pin (0=disable, 1=enable)
	I1_BOOT - Boot status available on INT_G (0=disable, 1=enable)
	H_LACTIVE - Interrupt active configuration on INT_G (0:high, 1:low)
	PP_OD - Push-pull/open-drain (0=push-pull, 1=open-drain)
	I2_DRDY - Data ready on DRDY_G (0=disable, 1=enable)
	I2_WTM - FIFO watermark interrupt on DRDY_G (0=disable 1=enable)
	I2_ORUN - FIFO overrun interrupt on DRDY_G (0=disable 1=enable)
	I2_EMPTY - FIFO empty interrupt on DRDY_G (0=disable 1=enable) */
	// Int1 enabled (pp, active low), data read on DRDY_G:
	//gWriteByte(lsm_t, CTRL_REG3_G, 0x00); //88
	lsm_t->gCtrl[2]=0b00000000;
#if (DEBUG0==1)
		gWriteByte(lsm_t, CTRL_REG3_G, lsm_t->gCtrl[2]);
		test[2] = gReadByte(lsm_t,CTRL_REG3_G);
		assert(test[2]==lsm_t->gCtrl[2]);
#endif
	/* CTRL_REG4_G sets the scale, update mode
	Bits[7:0] - BDU BLE FS1 FS0 - ST1 ST0 SIM
	BDU - Block data update (0=continuous, 1=output not updated until read
	BLE - Big/little endian (0=data LSB @ lower address, 1=LSB @ higher add)
	FS[1:0] - Full-scale selection
		00=245dps, 01=500dps, 10=2000dps, 11=2000dps
	ST[1:0] - Self-test enable
		00=disabled, 01=st 0 (x+, y-, z-), 10=undefined, 11=st 1 (x-, y+, z+)
	SIM - SPI serial interface mode select
		0=4 wire, 1=3 wire */
	//gWriteByte(lsm_t, CTRL_REG4_G, 0x90); // Set scale to 245 dps//00
	lsm_t->gCtrl[3]=0b10010000;
#if (DEBUG0==1)
		gWriteByte(lsm_t, CTRL_REG4_G, lsm_t->gCtrl[3]);
		test[3] = gReadByte(lsm_t,CTRL_REG4_G);
		assert(test[3]==lsm_t->gCtrl[3]);
#endif
	/* CTRL_REG5_G sets up the FIFO, HPF, and INT1
	Bits[7:0] - BOOT FIFO_EN - HPen INT1_Sel1 INT1_Sel0 Out_Sel1 Out_Sel0
	BOOT - Reboot memory content (0=normal, 1=reboot)
	FIFO_EN - FIFO enable (0=disable, 1=enable)
	HPen - HPF enable (0=disable, 1=enable)
	INT1_Sel[1:0] - Int 1 selection configuration
	Out_Sel[1:0] - Out selection configuration */

	//gWriteByte(lsm_t, CTRL_REG5_G, 0x00);
	lsm_t->gCtrl[4]=0b00000000;
#if (DEBUG0==1)
		gWriteByte(lsm_t, CTRL_REG5_G, lsm_t->gCtrl[4]);
		test[4] = gReadByte(lsm_t,CTRL_REG5_G);
		assert(test[4]==lsm_t->gCtrl[4]);
#endif
	if (lsm_t->update==UPDATE_ON_CALL)
	{
		gWriteBytes(lsm_t,CTRL_REG1_G, lsm_t->gCtrl,5);
	}

#if (DEBUG0==1)
	gReadBytes(lsm_t, CTRL_REG1_G,test1,5);
	for (i=0;i<5;i++)
	{
		assert(test[i]==test1[i]);
	}
#endif

}