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 void configMagInt(uint8_t generator, h_lactive activeLow, bool latch = true); 00317 00318 /** configMagThs() -- Configure the threshold of a gyroscope axis 00319 * Input: 00320 * - threshold = Interrupt threshold. Possible values: 0-0x7FF. 00321 * Value is equivalent to raw magnetometer value. 00322 */ 00323 void configMagThs(uint16_t threshold); 00324 00325 //! getGyroIntSrc() -- Get contents of Gyroscope interrupt source register 00326 uint8_t getGyroIntSrc(); 00327 00328 //! getGyroIntSrc() -- Get contents of accelerometer interrupt source register 00329 uint8_t getAccelIntSrc(); 00330 00331 //! getGyroIntSrc() -- Get contents of magnetometer interrupt source register 00332 uint8_t getMagIntSrc(); 00333 00334 //! getGyroIntSrc() -- Get status of inactivity interrupt 00335 uint8_t getInactivity(); 00336 00337 /** sleepGyro() -- Sleep or wake the gyroscope 00338 * Input: 00339 * - enable: True = sleep gyro. False = wake gyro. 00340 */ 00341 void sleepGyro(bool enable = true); 00342 00343 /** enableFIFO() - Enable or disable the FIFO 00344 * Input: 00345 * - enable: true = enable, false = disable. 00346 */ 00347 void enableFIFO(bool enable = true); 00348 00349 /** setFIFO() - Configure FIFO mode and Threshold 00350 * Input: 00351 * - fifoMode: Set FIFO mode to off, FIFO (stop when full), continuous, bypass 00352 * Possible inputs: FIFO_OFF, FIFO_THS, FIFO_CONT_TRIGGER, FIFO_OFF_TRIGGER, FIFO_CONT 00353 * - fifoThs: FIFO threshold level setting 00354 * Any value from 0-0x1F is acceptable. 00355 */ 00356 void setFIFO(fifoMode_type fifoMode, uint8_t fifoThs); 00357 00358 //! getFIFOSamples() - Get number of FIFO samples 00359 uint8_t getFIFOSamples(); 00360 00361 00362 protected: 00363 // x_mAddress and gAddress store the I2C address or SPI chip select pin 00364 // for each sensor. 00365 uint8_t _mAddress, _xgAddress; 00366 00367 // gRes, aRes, and mRes store the current resolution for each sensor. 00368 // Units of these values would be DPS (or g's or Gs's) per ADC tick. 00369 // This value is calculated as (sensor scale) / (2^15). 00370 float gRes, aRes, mRes; 00371 00372 // _autoCalc keeps track of whether we're automatically subtracting off 00373 // accelerometer and gyroscope bias calculated in calibrate(). 00374 bool _autoCalc; 00375 00376 // init() -- Sets up gyro, accel, and mag settings to default. 00377 // - interface - Sets the interface mode (IMU_MODE_I2C or IMU_MODE_SPI) 00378 // - xgAddr - Sets either the I2C address of the accel/gyro or SPI chip 00379 // select pin connected to the CS_XG pin. 00380 // - mAddr - Sets either the I2C address of the magnetometer or SPI chip 00381 // select pin connected to the CS_M pin. 00382 void init(interface_mode interface, uint8_t xgAddr, uint8_t mAddr); 00383 00384 // initGyro() -- Sets up the gyroscope to begin reading. 00385 // This function steps through all five gyroscope control registers. 00386 // Upon exit, the following parameters will be set: 00387 // - CTRL_REG1_G = 0x0F: Normal operation mode, all axes enabled. 00388 // 95 Hz ODR, 12.5 Hz cutoff frequency. 00389 // - CTRL_REG2_G = 0x00: HPF set to normal mode, cutoff frequency 00390 // set to 7.2 Hz (depends on ODR). 00391 // - CTRL_REG3_G = 0x88: Interrupt enabled on INT_G (set to push-pull and 00392 // active high). Data-ready output enabled on DRDY_G. 00393 // - CTRL_REG4_G = 0x00: Continuous update mode. Data LSB stored in lower 00394 // address. Scale set to 245 DPS. SPI mode set to 4-wire. 00395 // - CTRL_REG5_G = 0x00: FIFO disabled. HPF disabled. 00396 void initGyro(); 00397 00398 // initAccel() -- Sets up the accelerometer to begin reading. 00399 // This function steps through all accelerometer related control registers. 00400 // Upon exit these registers will be set as: 00401 // - CTRL_REG0_XM = 0x00: FIFO disabled. HPF bypassed. Normal mode. 00402 // - CTRL_REG1_XM = 0x57: 100 Hz data rate. Continuous update. 00403 // all axes enabled. 00404 // - CTRL_REG2_XM = 0x00: 2g scale. 773 Hz anti-alias filter BW. 00405 // - CTRL_REG3_XM = 0x04: Accel data ready signal on INT1_XM pin. 00406 void initAccel(); 00407 00408 // initMag() -- Sets up the magnetometer to begin reading. 00409 // This function steps through all magnetometer-related control registers. 00410 // Upon exit these registers will be set as: 00411 // - CTRL_REG4_XM = 0x04: Mag data ready signal on INT2_XM pin. 00412 // - CTRL_REG5_XM = 0x14: 100 Hz update rate. Low resolution. Interrupt 00413 // requests don't latch. Temperature sensor disabled. 00414 // - CTRL_REG6_XM = 0x00: 2 Gs scale. 00415 // - CTRL_REG7_XM = 0x00: Continuous conversion mode. Normal HPF mode. 00416 // - INT_CTRL_REG_M = 0x09: Interrupt active-high. Enable interrupts. 00417 void initMag(); 00418 00419 // gReadByte() -- Reads a byte from a specified gyroscope register. 00420 // Input: 00421 // - subAddress = Register to be read from. 00422 // Output: 00423 // - An 8-bit value read from the requested address. 00424 uint8_t mReadByte(uint8_t subAddress); 00425 00426 // gReadBytes() -- Reads a number of bytes -- beginning at an address 00427 // and incrementing from there -- from the gyroscope. 00428 // Input: 00429 // - subAddress = Register to be read from. 00430 // - * dest = A pointer to an array of uint8_t's. Values read will be 00431 // stored in here on return. 00432 // - count = The number of bytes to be read. 00433 // Output: No value is returned, but the `dest` array will store 00434 // the data read upon exit. 00435 void mReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count); 00436 00437 // gWriteByte() -- Write a byte to a register in the gyroscope. 00438 // Input: 00439 // - subAddress = Register to be written to. 00440 // - data = data to be written to the register. 00441 void mWriteByte(uint8_t subAddress, uint8_t data); 00442 00443 // xmReadByte() -- Read a byte from a register in the accel/mag sensor 00444 // Input: 00445 // - subAddress = Register to be read from. 00446 // Output: 00447 // - An 8-bit value read from the requested register. 00448 uint8_t xgReadByte(uint8_t subAddress); 00449 00450 // xmReadBytes() -- Reads a number of bytes -- beginning at an address 00451 // and incrementing from there -- from the accelerometer/magnetometer. 00452 // Input: 00453 // - subAddress = Register to be read from. 00454 // - * dest = A pointer to an array of uint8_t's. Values read will be 00455 // stored in here on return. 00456 // - count = The number of bytes to be read. 00457 // Output: No value is returned, but the `dest` array will store 00458 // the data read upon exit. 00459 void xgReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count); 00460 00461 // xmWriteByte() -- Write a byte to a register in the accel/mag sensor. 00462 // Input: 00463 // - subAddress = Register to be written to. 00464 // - data = data to be written to the register. 00465 void xgWriteByte(uint8_t subAddress, uint8_t data); 00466 00467 // calcgRes() -- Calculate the resolution of the gyroscope. 00468 // This function will set the value of the gRes variable. gScale must 00469 // be set prior to calling this function. 00470 void calcgRes(); 00471 00472 // calcmRes() -- Calculate the resolution of the magnetometer. 00473 // This function will set the value of the mRes variable. mScale must 00474 // be set prior to calling this function. 00475 void calcmRes(); 00476 00477 // calcaRes() -- Calculate the resolution of the accelerometer. 00478 // This function will set the value of the aRes variable. aScale must 00479 // be set prior to calling this function. 00480 void calcaRes(); 00481 00482 ////////////////////// 00483 // Helper Functions // 00484 ////////////////////// 00485 void constrainScales(); 00486 00487 /////////////////// 00488 // SPI Functions // 00489 /////////////////// 00490 // initSPI() -- Initialize the SPI hardware. 00491 // This function will setup all SPI pins and related hardware. 00492 void initSPI(); 00493 00494 // SPIwriteByte() -- Write a byte out of SPI to a register in the device 00495 // Input: 00496 // - csPin = The chip select pin of the slave device. 00497 // - subAddress = The register to be written to. 00498 // - data = Byte to be written to the register. 00499 void SPIwriteByte(uint8_t csPin, uint8_t subAddress, uint8_t data); 00500 00501 // SPIreadByte() -- Read a single byte from a register over SPI. 00502 // Input: 00503 // - csPin = The chip select pin of the slave device. 00504 // - subAddress = The register to be read from. 00505 // Output: 00506 // - The byte read from the requested address. 00507 uint8_t SPIreadByte(uint8_t csPin, uint8_t subAddress); 00508 00509 // SPIreadBytes() -- Read a series of bytes, starting at a register via SPI 00510 // Input: 00511 // - csPin = The chip select pin of a slave device. 00512 // - subAddress = The register to begin reading. 00513 // - * dest = Pointer to an array where we'll store the readings. 00514 // - count = Number of registers to be read. 00515 // Output: No value is returned by the function, but the registers read are 00516 // all stored in the *dest array given. 00517 void SPIreadBytes(uint8_t csPin, uint8_t subAddress, 00518 uint8_t * dest, uint8_t count); 00519 00520 /////////////////// 00521 // I2C Functions // 00522 /////////////////// 00523 // initI2C() -- Initialize the I2C hardware. 00524 // This function will setup all I2C pins and related hardware. 00525 void initI2C(); 00526 00527 // I2CwriteByte() -- Write a byte out of I2C to a register in the device 00528 // Input: 00529 // - address = The 7-bit I2C address of the slave device. 00530 // - subAddress = The register to be written to. 00531 // - data = Byte to be written to the register. 00532 void I2CwriteByte(uint8_t address, uint8_t subAddress, uint8_t data); 00533 00534 // I2CreadByte() -- Read a single byte from a register over I2C. 00535 // Input: 00536 // - address = The 7-bit I2C address of the slave device. 00537 // - subAddress = The register to be read from. 00538 // Output: 00539 // - The byte read from the requested address. 00540 uint8_t I2CreadByte(uint8_t address, uint8_t subAddress); 00541 00542 // I2CreadBytes() -- Read a series of bytes, starting at a register via SPI 00543 // Input: 00544 // - address = The 7-bit I2C address of the slave device. 00545 // - subAddress = The register to begin reading. 00546 // - * dest = Pointer to an array where we'll store the readings. 00547 // - count = Number of registers to be read. 00548 // Output: No value is returned by the function, but the registers read are 00549 // all stored in the *dest array given. 00550 uint8_t I2CreadBytes(uint8_t address, uint8_t subAddress, uint8_t * dest, uint8_t count); 00551 00552 private: 00553 I2C i2c; 00554 }; 00555 00556 #endif // SFE_LSM9DS1_H //
Generated on Wed Jul 13 2022 03:20:53 by
1.7.2