12 #define ga (LSM9DS0_G)
13 #define xma (LSM9DS0_XM)
16 #define g_rb(x) (imu_rb(ga,x))
17 #define g_rbs(x,y,z) (imu_rbs(ga,x,y,z))
18 #define g_wb(x,y) (imu_wb(ga,x,y))
19 #define xm_rb(x) (imu_rb(xma,x))
20 #define xm_rbs(x,y,z) (imu_rbs(xma,x,y,z))
21 #define xm_wb(x,y) (imu_wb(xma,x,y))
22 #define multiple(x) (x | 0x80)
28 return (((int16_t) temp[1] << 12) | temp[0] << 4 ) >> 4;
51 if (gTest != 0xD4 || xmTest != 0x49)
205 void readAccel(int16_t * ax, int16_t * ay, int16_t * az)
209 *ax = (temp[1] << 8) | temp[0];
210 *ay = (temp[3] << 8) | temp[2];
211 *az = (temp[5] << 8) | temp[4];
214 void readMag(int16_t * mx, int16_t * my, int16_t * mz)
218 *mx = (temp[1] << 8) | temp[0];
219 *my = (temp[3] << 8) | temp[2];
220 *mz = (temp[5] << 8) | temp[4];
223 void readGyro(int16_t * gx, int16_t * gy, int16_t * gz)
227 *gx = (temp[1] << 8) | temp[0];
228 *gy = (temp[3] << 8) | temp[2];
229 *gz = (temp[5] << 8) | temp[4];
282 temp &= 0xFF^(0x3 << 4);
301 temp &= 0xFF^(0x3 << 3);
319 temp &= 0xFF^(0x3 << 5);
337 temp &= 0xFF^(0xF << 4);
339 temp |= (gRate << 4);
348 temp &= 0xFF^(0xF << 4);
350 temp |= (aRate << 4);
359 temp &= 0xFF^(0x3 << 7);
361 temp |= (abwRate << 7);
371 temp &= 0xFF^(0x7 << 2);
373 temp |= (mRate << 2);
386 gRes = 245.0 / 32768.0;
389 gRes = 500.0 / 32768.0;
392 gRes = 2000.0 / 32768.0;
403 (((float)
aScale + 1.0) * 2.0) / 32768.0;
412 (float) (
mScale << 2) / 32768.0;
416 void imu_wb(uint8_t address, uint8_t subAddress, uint8_t data)
418 if (address == (0x1D<<1)) {
426 uint8_t
imu_rb(uint8_t address, uint8_t subAddress)
437 void imu_rbs(uint8_t address, uint8_t subAddress, uint8_t * dest, uint8_t count)
440 if (address == (0x1D<<1)&& subAddress ==
OUT_X_L_A) {
449 for (i = 0; i < count; i++) {
unsigned char i2c_rep_start(unsigned char addr)
Issues a repeated start condition and sends address and transfer direction.
void setGyroODR(enum gyro_odr gRate)
set the data capture rate of the gyroscope see the enum gyro_odr to see what values this can take...
float calcAccel(int16_t accel)
void i2c_stop(void)
Terminates the data transfer and releases the I2C bus.
unsigned char i2c_readNak(void)
read one byte from the I2C device, read is followed by a stop condition
void readAccel(int16_t *ax, int16_t *ay, int16_t *az)
void readGyro(int16_t *gx, int16_t *gy, int16_t *gz)
void setMagScale(enum mag_scale mScl)
see the setGyroScale function
void setMagODR(enum mag_odr mRate)
see the setGyroODR function
unsigned char i2c_start(unsigned char addr)
Issues a start condition and sends address and transfer direction.
void readMag(int16_t *mx, int16_t *my, int16_t *mz)
void setGyroScale(enum gyro_scale gScl)
set the scale of the gyroscope see enum gyro_Scale to see what values this can take.
float calcGyro(int16_t gyro)
takes a raw gyro reading and returns the actual value
void i2c_init(void)
initialize the I2C master interace. Need to be called only once
void imu_wb(uint8_t address, uint8_t subAddress, uint8_t data)
Writes a byte to the register at the address specified by subAddress.
int16_t readTemp()
Returns the temperature in Celcius. Will be 25 degrees, which is the optimal temparture for the gyros...
void initAccel()
initilize the accelometer, this must be called before using any accelometer fucntions ...
void setAccelODR(enum accel_odr aRate)
see setGyroODR function
void setAccelScale(enum accel_scale aScl)
see the setGyroScle function
uint8_t imu_rb(uint8_t address, uint8_t subAddress)
Read one byte from the device.
void calcmRes()
sets the mRes variable to the correct resolution of the magenmeter readings
unsigned char i2c_write(unsigned char data)
Send one byte to I2C device.
unsigned char i2c_readAck(void)
read one byte from the I2C device, request more data from device
void read_mag(float *x, float *y, float *z)
Reads the magnemeter and calculates the real value from the raw reading.
void calcaRes()
sets the aRes variable to the correct resolution of the accelometer readings
void initGyro()
initialize the gyroscope, must be done before reading from the gyroscope
void calcgRes()
sets the gRes variable to the correct resolution of the gyroscope readings
uint16_t init_imu(enum gyro_scale gScl, enum accel_scale aScl, enum mag_scale mScl, enum gyro_odr gODR, enum accel_odr aODR, enum mag_odr mODR)
Initilizes the IMU and enables all 9 axes and set the respective scales and data rates.
void read_gyro(float *x, float *y, float *z)
Reads the gyroscope and calculates the real value from the raw reading.
float calcMag(int16_t mag)
void setAccelABW(enum accel_abw abwRate)
void imu_rbs(uint8_t address, uint8_t subAddress, uint8_t *dest, uint8_t count)
read multiple bytes from the imu
void read_accel(float *x, float *y, float *z)
Reads the accelometer and calculates the real value from the raw reading.