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 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; }
/** Power on and prepare for general usage. * This will activate the device and take it out of sleep mode (which must be done * after start-up). This function also sets both the accelerometer and the gyroscope * to their most sensitive settings, namely +/- 2g and +/- 250 degrees/sec, and sets * the clock source to use the X Gyro for reference, which is slightly better than * the default internal clock source. */ PUBLIC void initializeLSM6DS0(bool useAccel, bool useGyro) { xAccelOffset = yAccelOffset = zAccelOffset = 0; xGyroOffset = yGyroOffset = zGyroOffset = 0; gyroEnabled = useGyro; accelEnabled = useAccel; if(gyroEnabled) { gScale = GYRO_FS_245DSP; calcGyroRes(); } if(accelEnabled) { aScale = ACC_FS_2G; calcAccelRes(); } if(testConnection()) { resetLSM6DS0(); if(accelEnabled) { initAccel(); setFullScaleAccelRange(aScale); setAccelODR(ACC_ODR_119Hz); } if(gyroEnabled) { initGyro(); setFullScaleGyroRange(gScale); setGyroODR(GYRO_ODR_119Hz_CO_14Hz); } calibrateLSM6DS0(gbias,abias); } }