Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
LSM9DS1.h
00001 /****************************************************************************** 00002 SFE_LSM9DS1.h 00003 SFE_LSM9DS1 Library Header File 00004 Jim Lindblom @ SparkFun Electronics 00005 Original Creation Date: February 27, 2015 00006 https://github.com/sparkfun/LSM9DS1_Breakout 00007 00008 This file prototypes the LSM9DS1 class, implemented in SFE_LSM9DS1.cpp. In 00009 addition, it defines every register in the LSM9DS1 (both the Gyro and Accel/ 00010 Magnetometer registers). 00011 00012 Development environment specifics: 00013 IDE: Arduino 1.6.0 00014 Hardware Platform: Arduino Uno 00015 LSM9DS1 Breakout Version: 1.0 00016 00017 This code is beerware; if you see me (or any other SparkFun employee) at the 00018 local, and you've found our code helpful, please buy us a round! 00019 00020 Distributed as-is; no warranty is given. 00021 ******************************************************************************/ 00022 #ifndef __SparkFunLSM9DS1_H__ 00023 #define __SparkFunLSM9DS1_H__ 00024 00025 //#if defined(ARDUINO) && ARDUINO >= 100 00026 // #include "Arduino.h" 00027 //#else 00028 // #include "WProgram.h" 00029 // #include "pins_arduino.h" 00030 //#endif 00031 00032 #include "mbed.h" 00033 #include <stdint.h> 00034 #include "LSM9DS1_Registers.h" 00035 #include "LSM9DS1_Types.h" 00036 00037 #define LSM9DS1_AG_ADDR(sa0) ((sa0) == 0 ? 0x6A : 0x6B) 00038 #define LSM9DS1_M_ADDR(sa1) ((sa1) == 0 ? 0x1C : 0x1E) 00039 00040 enum lsm9ds1_axis { 00041 X_AXIS, 00042 Y_AXIS, 00043 Z_AXIS, 00044 ALL_AXIS 00045 }; 00046 00047 class LSM9DS1 00048 { 00049 public: 00050 IMUSettings settings; 00051 00052 // We'll store the gyro, accel, and magnetometer readings in a series of 00053 // public class variables. Each sensor gets three variables -- one for each 00054 // axis. Call readGyro(), readAccel(), and readMag() first, before using 00055 // these variables! 00056 // These values are the RAW signed 16-bit readings from the sensors. 00057 int16_t gx, gy, gz; // x, y, and z axis readings of the gyroscope 00058 int16_t ax, ay, az; // x, y, and z axis readings of the accelerometer 00059 int16_t mx, my, mz; // x, y, and z axis readings of the magnetometer 00060 int16_t temperature; // Chip temperature 00061 float gBias[3], aBias[3], mBias[3]; 00062 int16_t gBiasRaw[3], aBiasRaw[3], mBiasRaw[3]; 00063 00064 // LSM9DS1 -- LSM9DS1 class constructor 00065 // The constructor will set up a handful of private variables, and set the 00066 // communication mode as well. 00067 /**Input: 00068 * - interface = Either IMU_MODE_SPI or IMU_MODE_I2C, whichever you're using 00069 * to talk to the IC. 00070 * - xgAddr = If IMU_MODE_I2C, this is the I2C address of the accel/gyroscope. 00071 * If IMU_MODE_SPI, this is the chip select pin of the gyro (CS_AG) 00072 * - mAddr = If IMU_MODE_I2C, this is the I2C address of the magnetometer. 00073 * If IMU_MODE_SPI, this is the cs pin of the magnetometer (CS_M) 00074 00075 */ 00076 LSM9DS1(PinName sda, PinName scl, uint8_t xgAddr, uint8_t mAddr); 00077 //LSM9DS1(interface_mode interface, uint8_t xgAddr, uint8_t mAddr); 00078 //LSM9DS1(); 00079 00080 00081 /** begin() -- Initialize the gyro, accelerometer, and magnetometer. 00082 *This will set up the scale and output rate of each sensor. The values set 00083 * in the IMUSettings struct will take effect after calling this function. 00084 */ 00085 uint16_t begin(); 00086 00087 void calibrate(bool autoCalc = true); 00088 void calibrateMag(bool loadIn = true); 00089 void magOffset(uint8_t axis, int16_t offset); 00090 00091 /** accelAvailable() -- Polls the accelerometer status register to check 00092 * if new data is available. 00093 * Output: 1 - New data available 00094 * 0 - No new data available 00095 */ 00096 uint8_t accelAvailable(); 00097 00098 /** gyroAvailable() -- Polls the gyroscope status register to check 00099 * if new data is available. 00100 * Output: 1 - New data available 00101 * 0 - No new data available 00102 */ 00103 uint8_t gyroAvailable(); 00104 00105 /** gyroAvailable() -- Polls the temperature status register to check 00106 * if new data is available. 00107 * Output: 1 - New data available 00108 * 0 - No new data available 00109 */ 00110 uint8_t tempAvailable(); 00111 00112 /** magAvailable() -- Polls the accelerometer status register to check 00113 * if new data is available. 00114 * Input: 00115 * - axis can be either X_AXIS, Y_AXIS, Z_AXIS, to check for new data 00116 * on one specific axis. Or ALL_AXIS (default) to check for new data 00117 * on all axes. 00118 * Output: 1 - New data available 00119 * 0 - No new data available 00120 */ 00121 uint8_t magAvailable(lsm9ds1_axis axis = ALL_AXIS); 00122 00123 /** readGyro() -- Read the gyroscope output registers. 00124 * This function will read all six gyroscope output registers. 00125 * The readings are stored in the class' gx, gy, and gz variables. Read 00126 * those _after_ calling readGyro(). 00127 */ 00128 void readGyro(); 00129 00130 /** int16_t readGyro(axis) -- Read a specific axis of the gyroscope. 00131 * [axis] can be any of X_AXIS, Y_AXIS, or Z_AXIS. 00132 * Input: 00133 * - axis: can be either X_AXIS, Y_AXIS, or Z_AXIS. 00134 * Output: 00135 * A 16-bit signed integer with sensor data on requested axis. 00136 */ 00137 int16_t readGyro(lsm9ds1_axis axis); 00138 00139 /** readAccel() -- Read the accelerometer output registers. 00140 * This function will read all six accelerometer output registers. 00141 * The readings are stored in the class' ax, ay, and az variables. Read 00142 * those _after_ calling readAccel(). 00143 */ 00144 void readAccel(); 00145 00146 /** int16_t readAccel(axis) -- Read a specific axis of the accelerometer. 00147 * [axis] can be any of X_AXIS, Y_AXIS, or Z_AXIS. 00148 * Input: 00149 * - axis: can be either X_AXIS, Y_AXIS, or Z_AXIS. 00150 * Output: 00151 * A 16-bit signed integer with sensor data on requested axis. 00152 */ 00153 int16_t readAccel(lsm9ds1_axis axis); 00154 00155 /** readMag() -- Read the magnetometer output registers. 00156 * This function will read all six magnetometer output registers. 00157 * The readings are stored in the class' mx, my, and mz variables. Read 00158 * those _after_ calling readMag(). 00159 */ 00160 void readMag(); 00161 00162 /** int16_t readMag(axis) -- Read a specific axis of the magnetometer. 00163 * [axis] can be any of X_AXIS, Y_AXIS, or Z_AXIS. 00164 * Input: 00165 * - axis: can be either X_AXIS, Y_AXIS, or Z_AXIS. 00166 * Output: 00167 * A 16-bit signed integer with sensor data on requested axis. 00168 */ 00169 int16_t readMag(lsm9ds1_axis axis); 00170 00171 /** readTemp() -- Read the temperature output register. 00172 * This function will read two temperature output registers. 00173 * The combined readings are stored in the class' temperature variables. Read 00174 * those _after_ calling readTemp(). 00175 */ 00176 void readTemp(); 00177 00178 /** calcGyro() -- Convert from RAW signed 16-bit value to degrees per second 00179 * This function reads in a signed 16-bit value and returns the scaled 00180 * DPS. This function relies on gScale and gRes being correct. 00181 * Input: 00182 * - gyro = A signed 16-bit raw reading from the gyroscope. 00183 */ 00184 float calcGyro(int16_t gyro); 00185 00186 /** calcAccel() -- Convert from RAW signed 16-bit value to gravity (g's). 00187 * This function reads in a signed 16-bit value and returns the scaled 00188 * g's. This function relies on aScale and aRes being correct. 00189 * Input: 00190 * - accel = A signed 16-bit raw reading from the accelerometer. 00191 */ 00192 float calcAccel(int16_t accel); 00193 00194 /** calcMag() -- Convert from RAW signed 16-bit value to Gauss (Gs) 00195 * This function reads in a signed 16-bit value and returns the scaled 00196 * Gs. This function relies on mScale and mRes being correct. 00197 * Input: 00198 * - mag = A signed 16-bit raw reading from the magnetometer. 00199 */ 00200 float calcMag(int16_t mag); 00201 00202 /** setGyroScale() -- Set the full-scale range of the gyroscope. 00203 * This function can be called to set the scale of the gyroscope to 00204 * 245, 500, or 200 degrees per second. 00205 * Input: 00206 * - gScl = The desired gyroscope scale. Must be one of three possible 00207 * values from the gyro_scale. 00208 */ 00209 void setGyroScale(uint16_t gScl); 00210 00211 /** setAccelScale() -- Set the full-scale range of the accelerometer. 00212 * This function can be called to set the scale of the accelerometer to 00213 * 2, 4, 6, 8, or 16 g's. 00214 * Input: 00215 * - aScl = The desired accelerometer scale. Must be one of five possible 00216 * values from the accel_scale. 00217 */ 00218 void setAccelScale(uint8_t aScl); 00219 00220 /** setMagScale() -- Set the full-scale range of the magnetometer. 00221 * This function can be called to set the scale of the magnetometer to 00222 * 2, 4, 8, or 12 Gs. 00223 * Input: 00224 * - mScl = The desired magnetometer scale. Must be one of four possible 00225 * values from the mag_scale. 00226 */ 00227 void setMagScale(uint8_t mScl); 00228 00229 /** setGyroODR() -- Set the output data rate and bandwidth of the gyroscope 00230 * Input: 00231 * - gRate = The desired output rate and cutoff frequency of the gyro. 00232 */ 00233 void setGyroODR(uint8_t gRate); 00234 00235 // setAccelODR() -- Set the output data rate of the accelerometer 00236 // Input: 00237 // - aRate = The desired output rate of the accel. 00238 void setAccelODR(uint8_t aRate); 00239 00240 // setMagODR() -- Set the output data rate of the magnetometer 00241 // Input: 00242 // - mRate = The desired output rate of the mag. 00243 void setMagODR(uint8_t mRate); 00244 00245 // configInactivity() -- Configure inactivity interrupt parameters 00246 // Input: 00247 // - duration = Inactivity duration - actual value depends on gyro ODR 00248 // - threshold = Activity Threshold 00249 // - sleepOn = Gyroscope operating mode during inactivity. 00250 // true: gyroscope in sleep mode 00251 // false: gyroscope in power-down 00252 void configInactivity(uint8_t duration, uint8_t threshold, bool sleepOn); 00253 00254 // configAccelInt() -- Configure Accelerometer Interrupt Generator 00255 // Input: 00256 // - generator = Interrupt axis/high-low events 00257 // Any OR'd combination of ZHIE_XL, ZLIE_XL, YHIE_XL, YLIE_XL, XHIE_XL, XLIE_XL 00258 // - andInterrupts = AND/OR combination of interrupt events 00259 // true: AND combination 00260 // false: OR combination 00261 void configAccelInt(uint8_t generator, bool andInterrupts = false); 00262 00263 // configAccelThs() -- Configure the threshold of an accelereomter axis 00264 // Input: 00265 // - threshold = Interrupt threshold. Possible values: 0-255. 00266 // Multiply by 128 to get the actual raw accel value. 00267 // - axis = Axis to be configured. Either X_AXIS, Y_AXIS, or Z_AXIS 00268 // - duration = Duration value must be above or below threshold to trigger interrupt 00269 // - wait = Wait function on duration counter 00270 // true: Wait for duration samples before exiting interrupt 00271 // false: Wait function off 00272 void configAccelThs(uint8_t threshold, lsm9ds1_axis axis, uint8_t duration = 0, bool wait = 0); 00273 00274 // configGyroInt() -- Configure Gyroscope Interrupt Generator 00275 // Input: 00276 // - generator = Interrupt axis/high-low events 00277 // Any OR'd combination of ZHIE_G, ZLIE_G, YHIE_G, YLIE_G, XHIE_G, XLIE_G 00278 // - aoi = AND/OR combination of interrupt events 00279 // true: AND combination 00280 // false: OR combination 00281 // - latch: latch gyroscope interrupt request. 00282 void configGyroInt(uint8_t generator, bool aoi, bool latch); 00283 00284 // configGyroThs() -- Configure the threshold of a gyroscope axis 00285 // Input: 00286 // - threshold = Interrupt threshold. Possible values: 0-0x7FF. 00287 // Value is equivalent to raw gyroscope value. 00288 // - axis = Axis to be configured. Either X_AXIS, Y_AXIS, or Z_AXIS 00289 // - duration = Duration value must be above or below threshold to trigger interrupt 00290 // - wait = Wait function on duration counter 00291 // true: Wait for duration samples before exiting interrupt 00292 // false: Wait function off 00293 void configGyroThs(int16_t threshold, lsm9ds1_axis axis, uint8_t duration, bool wait); 00294 00295 // configInt() -- Configure INT1 or INT2 (Gyro and Accel Interrupts only) 00296 // Input: 00297 // - interrupt = Select INT1 or INT2 00298 // Possible values: XG_INT1 or XG_INT2 00299 // - generator = Or'd combination of interrupt generators. 00300 // Possible values: INT_DRDY_XL, INT_DRDY_G, INT1_BOOT (INT1 only), INT2_DRDY_TEMP (INT2 only) 00301 // INT_FTH, INT_OVR, INT_FSS5, INT_IG_XL (INT1 only), INT1_IG_G (INT1 only), INT2_INACT (INT2 only) 00302 // - activeLow = Interrupt active configuration 00303 // Can be either INT_ACTIVE_HIGH or INT_ACTIVE_LOW 00304 // - pushPull = Push-pull or open drain interrupt configuration 00305 // Can be either INT_PUSH_PULL or INT_OPEN_DRAIN 00306 void configInt(interrupt_select interupt, uint8_t generator, 00307 h_lactive activeLow = INT_ACTIVE_LOW, pp_od pushPull = INT_PUSH_PULL); 00308 00309 /** configMagInt() -- Configure Magnetometer Interrupt Generator 00310 * Input: 00311 * - generator = Interrupt axis/high-low events 00312 * Any OR'd combination of ZIEN, YIEN, XIEN 00313 * - activeLow = Interrupt active configuration 00314 * Can be either INT_ACTIVE_HIGH or INT_ACTIVE_LOW 00315 * - latch: latch gyroscope interrupt request. 00316 */ 00317 void configMagInt(uint8_t generator, h_lactive activeLow, bool latch = true); 00318 00319 /** configMagThs() -- Configure the threshold of a gyroscope axis 00320 * Input: 00321 * - threshold = Interrupt threshold. Possible values: 0-0x7FF. 00322 * Value is equivalent to raw magnetometer value. 00323 */ 00324 void configMagThs(uint16_t threshold); 00325 00326 //! getGyroIntSrc() -- Get contents of Gyroscope interrupt source register 00327 uint8_t getGyroIntSrc(); 00328 00329 //! getGyroIntSrc() -- Get contents of accelerometer interrupt source register 00330 uint8_t getAccelIntSrc(); 00331 00332 //! getGyroIntSrc() -- Get contents of magnetometer interrupt source register 00333 uint8_t getMagIntSrc(); 00334 00335 //! getGyroIntSrc() -- Get status of inactivity interrupt 00336 uint8_t getInactivity(); 00337 00338 /** sleepGyro() -- Sleep or wake the gyroscope 00339 * Input: 00340 * - enable: True = sleep gyro. False = wake gyro. 00341 */ 00342 void sleepGyro(bool enable = true); 00343 00344 /** enableFIFO() - Enable or disable the FIFO 00345 * Input: 00346 * - enable: true = enable, false = disable. 00347 */ 00348 void enableFIFO(bool enable = true); 00349 00350 /** setFIFO() - Configure FIFO mode and Threshold 00351 * Input: 00352 * - fifoMode: Set FIFO mode to off, FIFO (stop when full), continuous, bypass 00353 * Possible inputs: FIFO_OFF, FIFO_THS, FIFO_CONT_TRIGGER, FIFO_OFF_TRIGGER, FIFO_CONT 00354 * - fifoThs: FIFO threshold level setting 00355 * Any value from 0-0x1F is acceptable. 00356 */ 00357 void setFIFO(fifoMode_type fifoMode, uint8_t fifoThs); 00358 00359 //! getFIFOSamples() - Get number of FIFO samples 00360 uint8_t getFIFOSamples(); 00361 00362 00363 protected: 00364 // x_mAddress and gAddress store the I2C address or SPI chip select pin 00365 // for each sensor. 00366 uint8_t _mAddress, _xgAddress; 00367 00368 // gRes, aRes, and mRes store the current resolution for each sensor. 00369 // Units of these values would be DPS (or g's or Gs's) per ADC tick. 00370 // This value is calculated as (sensor scale) / (2^15). 00371 float gRes, aRes, mRes; 00372 00373 // _autoCalc keeps track of whether we're automatically subtracting off 00374 // accelerometer and gyroscope bias calculated in calibrate(). 00375 bool _autoCalc; 00376 00377 // init() -- Sets up gyro, accel, and mag settings to default. 00378 // - interface - Sets the interface mode (IMU_MODE_I2C or IMU_MODE_SPI) 00379 // - xgAddr - Sets either the I2C address of the accel/gyro or SPI chip 00380 // select pin connected to the CS_XG pin. 00381 // - mAddr - Sets either the I2C address of the magnetometer or SPI chip 00382 // select pin connected to the CS_M pin. 00383 void init(interface_mode interface, uint8_t xgAddr, uint8_t mAddr); 00384 00385 // initGyro() -- Sets up the gyroscope to begin reading. 00386 // This function steps through all five gyroscope control registers. 00387 // Upon exit, the following parameters will be set: 00388 // - CTRL_REG1_G = 0x0F: Normal operation mode, all axes enabled. 00389 // 95 Hz ODR, 12.5 Hz cutoff frequency. 00390 // - CTRL_REG2_G = 0x00: HPF set to normal mode, cutoff frequency 00391 // set to 7.2 Hz (depends on ODR). 00392 // - CTRL_REG3_G = 0x88: Interrupt enabled on INT_G (set to push-pull and 00393 // active high). Data-ready output enabled on DRDY_G. 00394 // - CTRL_REG4_G = 0x00: Continuous update mode. Data LSB stored in lower 00395 // address. Scale set to 245 DPS. SPI mode set to 4-wire. 00396 // - CTRL_REG5_G = 0x00: FIFO disabled. HPF disabled. 00397 void initGyro(); 00398 00399 // initAccel() -- Sets up the accelerometer to begin reading. 00400 // This function steps through all accelerometer related control registers. 00401 // Upon exit these registers will be set as: 00402 // - CTRL_REG0_XM = 0x00: FIFO disabled. HPF bypassed. Normal mode. 00403 // - CTRL_REG1_XM = 0x57: 100 Hz data rate. Continuous update. 00404 // all axes enabled. 00405 // - CTRL_REG2_XM = 0x00: 2g scale. 773 Hz anti-alias filter BW. 00406 // - CTRL_REG3_XM = 0x04: Accel data ready signal on INT1_XM pin. 00407 void initAccel(); 00408 00409 // initMag() -- Sets up the magnetometer to begin reading. 00410 // This function steps through all magnetometer-related control registers. 00411 // Upon exit these registers will be set as: 00412 // - CTRL_REG4_XM = 0x04: Mag data ready signal on INT2_XM pin. 00413 // - CTRL_REG5_XM = 0x14: 100 Hz update rate. Low resolution. Interrupt 00414 // requests don't latch. Temperature sensor disabled. 00415 // - CTRL_REG6_XM = 0x00: 2 Gs scale. 00416 // - CTRL_REG7_XM = 0x00: Continuous conversion mode. Normal HPF mode. 00417 // - INT_CTRL_REG_M = 0x09: Interrupt active-high. Enable interrupts. 00418 void initMag(); 00419 00420 // gReadByte() -- Reads a byte from a specified gyroscope register. 00421 // Input: 00422 // - subAddress = Register to be read from. 00423 // Output: 00424 // - An 8-bit value read from the requested address. 00425 uint8_t mReadByte(uint8_t subAddress); 00426 00427 // gReadBytes() -- Reads a number of bytes -- beginning at an address 00428 // and incrementing from there -- from the gyroscope. 00429 // Input: 00430 // - subAddress = Register to be read from. 00431 // - * dest = A pointer to an array of uint8_t's. Values read will be 00432 // stored in here on return. 00433 // - count = The number of bytes to be read. 00434 // Output: No value is returned, but the `dest` array will store 00435 // the data read upon exit. 00436 void mReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count); 00437 00438 // gWriteByte() -- Write a byte to a register in the gyroscope. 00439 // Input: 00440 // - subAddress = Register to be written to. 00441 // - data = data to be written to the register. 00442 void mWriteByte(uint8_t subAddress, uint8_t data); 00443 00444 // xmReadByte() -- Read a byte from a register in the accel/mag sensor 00445 // Input: 00446 // - subAddress = Register to be read from. 00447 // Output: 00448 // - An 8-bit value read from the requested register. 00449 uint8_t xgReadByte(uint8_t subAddress); 00450 00451 // xmReadBytes() -- Reads a number of bytes -- beginning at an address 00452 // and incrementing from there -- from the accelerometer/magnetometer. 00453 // Input: 00454 // - subAddress = Register to be read from. 00455 // - * dest = A pointer to an array of uint8_t's. Values read will be 00456 // stored in here on return. 00457 // - count = The number of bytes to be read. 00458 // Output: No value is returned, but the `dest` array will store 00459 // the data read upon exit. 00460 void xgReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count); 00461 00462 // xmWriteByte() -- Write a byte to a register in the accel/mag sensor. 00463 // Input: 00464 // - subAddress = Register to be written to. 00465 // - data = data to be written to the register. 00466 void xgWriteByte(uint8_t subAddress, uint8_t data); 00467 00468 // calcgRes() -- Calculate the resolution of the gyroscope. 00469 // This function will set the value of the gRes variable. gScale must 00470 // be set prior to calling this function. 00471 void calcgRes(); 00472 00473 // calcmRes() -- Calculate the resolution of the magnetometer. 00474 // This function will set the value of the mRes variable. mScale must 00475 // be set prior to calling this function. 00476 void calcmRes(); 00477 00478 // calcaRes() -- Calculate the resolution of the accelerometer. 00479 // This function will set the value of the aRes variable. aScale must 00480 // be set prior to calling this function. 00481 void calcaRes(); 00482 00483 ////////////////////// 00484 // Helper Functions // 00485 ////////////////////// 00486 void constrainScales(); 00487 00488 /////////////////// 00489 // SPI Functions // 00490 /////////////////// 00491 // initSPI() -- Initialize the SPI hardware. 00492 // This function will setup all SPI pins and related hardware. 00493 void initSPI(); 00494 00495 // SPIwriteByte() -- Write a byte out of SPI to a register in the device 00496 // Input: 00497 // - csPin = The chip select pin of the slave device. 00498 // - subAddress = The register to be written to. 00499 // - data = Byte to be written to the register. 00500 void SPIwriteByte(uint8_t csPin, uint8_t subAddress, uint8_t data); 00501 00502 // SPIreadByte() -- Read a single byte from a register over SPI. 00503 // Input: 00504 // - csPin = The chip select pin of the slave device. 00505 // - subAddress = The register to be read from. 00506 // Output: 00507 // - The byte read from the requested address. 00508 uint8_t SPIreadByte(uint8_t csPin, uint8_t subAddress); 00509 00510 // SPIreadBytes() -- Read a series of bytes, starting at a register via SPI 00511 // Input: 00512 // - csPin = The chip select pin of a slave device. 00513 // - subAddress = The register to begin reading. 00514 // - * dest = Pointer to an array where we'll store the readings. 00515 // - count = Number of registers to be read. 00516 // Output: No value is returned by the function, but the registers read are 00517 // all stored in the *dest array given. 00518 void SPIreadBytes(uint8_t csPin, uint8_t subAddress, 00519 uint8_t * dest, uint8_t count); 00520 00521 /////////////////// 00522 // I2C Functions // 00523 /////////////////// 00524 // initI2C() -- Initialize the I2C hardware. 00525 // This function will setup all I2C pins and related hardware. 00526 void initI2C(); 00527 00528 // I2CwriteByte() -- Write a byte out of I2C to a register in the device 00529 // Input: 00530 // - address = The 7-bit I2C address of the slave device. 00531 // - subAddress = The register to be written to. 00532 // - data = Byte to be written to the register. 00533 void I2CwriteByte(uint8_t address, uint8_t subAddress, uint8_t data); 00534 00535 // I2CreadByte() -- Read a single byte from a register over I2C. 00536 // Input: 00537 // - address = The 7-bit I2C address of the slave device. 00538 // - subAddress = The register to be read from. 00539 // Output: 00540 // - The byte read from the requested address. 00541 uint8_t I2CreadByte(uint8_t address, uint8_t subAddress); 00542 00543 // I2CreadBytes() -- Read a series of bytes, starting at a register via SPI 00544 // Input: 00545 // - address = The 7-bit I2C address of the slave device. 00546 // - subAddress = The register to begin reading. 00547 // - * dest = Pointer to an array where we'll store the readings. 00548 // - count = Number of registers to be read. 00549 // Output: No value is returned by the function, but the registers read are 00550 // all stored in the *dest array given. 00551 uint8_t I2CreadBytes(uint8_t address, uint8_t subAddress, uint8_t * dest, uint8_t count); 00552 00553 private: 00554 I2C i2c; 00555 }; 00556 00557 #endif // SFE_LSM9DS1_H //
Generated on Thu Jul 21 2022 07:46:41 by
