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.
Dependents: particle_filter_test read_sensor_data Bike_Sensor_Fusion Encoder ... more
LSM9DS0.h
00001 //Original author 00002 /****************************************************************************** 00003 SFE_LSM9DS0.h 00004 SFE_LSM9DS0 Library Header File 00005 Jim Lindblom @ SparkFun Electronics 00006 Original Creation Date: February 14, 2014 (Happy Valentines Day!) 00007 https://github.com/sparkfun/LSM9DS0_Breakout 00008 This file prototypes the LSM9DS0 class, implemented in SFE_LSM9DS0.cpp. In 00009 addition, it defines every register in the LSM9DS0 (both the Gyro and Accel/ 00010 Magnetometer registers). 00011 Development environment specifics: 00012 IDE: Arduino 1.0.5 00013 Hardware Platform: Arduino Pro 3.3V/8MHz 00014 LSM9DS0 Breakout Version: 1.0 00015 This code is beerware; if you see me (or any other SparkFun employee) at the 00016 local, and you've found our code helpful, please buy us a round! 00017 Distributed as-is; no warranty is given. 00018 ******************************************************************************/ 00019 #ifndef __SFE_LSM9DS0_H__ 00020 #define __SFE_LSM9DS0_H__ 00021 00022 #include "mbed.h" 00023 00024 00025 #define PI 3.14159f 00026 //////////////////////////// 00027 // LSM9DS0 Gyro Registers // 00028 //////////////////////////// 00029 #define WHO_AM_I_G 0x0F 00030 #define CTRL_REG1_G 0x20 00031 #define CTRL_REG2_G 0x21 00032 #define CTRL_REG3_G 0x22 00033 #define CTRL_REG4_G 0x23 00034 #define CTRL_REG5_G 0x24 00035 #define REFERENCE_G 0x25 00036 #define STATUS_REG_G 0x27 00037 #define OUT_X_L_G 0x28 00038 #define OUT_X_H_G 0x29 00039 #define OUT_Y_L_G 0x2A 00040 #define OUT_Y_H_G 0x2B 00041 #define OUT_Z_L_G 0x2C 00042 #define OUT_Z_H_G 0x2D 00043 #define FIFO_CTRL_REG_G 0x2E 00044 #define FIFO_SRC_REG_G 0x2F 00045 #define INT1_CFG_G 0x30 00046 #define INT1_SRC_G 0x31 00047 #define INT1_THS_XH_G 0x32 00048 #define INT1_THS_XL_G 0x33 00049 #define INT1_THS_YH_G 0x34 00050 #define INT1_THS_YL_G 0x35 00051 #define INT1_THS_ZH_G 0x36 00052 #define INT1_THS_ZL_G 0x37 00053 #define INT1_DURATION_G 0x38 00054 00055 ////////////////////////////////////////// 00056 // LSM9DS0 Accel/Magneto (XM) Registers // 00057 ////////////////////////////////////////// 00058 #define OUT_TEMP_L_XM 0x05 00059 #define OUT_TEMP_H_XM 0x06 00060 #define STATUS_REG_M 0x07 00061 #define OUT_X_L_M 0x08 00062 #define OUT_X_H_M 0x09 00063 #define OUT_Y_L_M 0x0A 00064 #define OUT_Y_H_M 0x0B 00065 #define OUT_Z_L_M 0x0C 00066 #define OUT_Z_H_M 0x0D 00067 #define WHO_AM_I_XM 0x0F 00068 #define INT_CTRL_REG_M 0x12 00069 #define INT_SRC_REG_M 0x13 00070 #define INT_THS_L_M 0x14 00071 #define INT_THS_H_M 0x15 00072 #define OFFSET_X_L_M 0x16 00073 #define OFFSET_X_H_M 0x17 00074 #define OFFSET_Y_L_M 0x18 00075 #define OFFSET_Y_H_M 0x19 00076 #define OFFSET_Z_L_M 0x1A 00077 #define OFFSET_Z_H_M 0x1B 00078 #define REFERENCE_X 0x1C 00079 #define REFERENCE_Y 0x1D 00080 #define REFERENCE_Z 0x1E 00081 #define CTRL_REG0_XM 0x1F 00082 #define CTRL_REG1_XM 0x20 00083 #define CTRL_REG2_XM 0x21 00084 #define CTRL_REG3_XM 0x22 00085 #define CTRL_REG4_XM 0x23 00086 #define CTRL_REG5_XM 0x24 00087 #define CTRL_REG6_XM 0x25 00088 #define CTRL_REG7_XM 0x26 00089 #define STATUS_REG_A 0x27 00090 #define OUT_X_L_A 0x28 00091 #define OUT_X_H_A 0x29 00092 #define OUT_Y_L_A 0x2A 00093 #define OUT_Y_H_A 0x2B 00094 #define OUT_Z_L_A 0x2C 00095 #define OUT_Z_H_A 0x2D 00096 #define FIFO_CTRL_REG 0x2E 00097 #define FIFO_SRC_REG 0x2F 00098 #define INT_GEN_1_REG 0x30 00099 #define INT_GEN_1_SRC 0x31 00100 #define INT_GEN_1_THS 0x32 00101 #define INT_GEN_1_DURATION 0x33 00102 #define INT_GEN_2_REG 0x34 00103 #define INT_GEN_2_SRC 0x35 00104 #define INT_GEN_2_THS 0x36 00105 #define INT_GEN_2_DURATION 0x37 00106 #define CLICK_CFG 0x38 00107 #define CLICK_SRC 0x39 00108 #define CLICK_THS 0x3A 00109 #define TIME_LIMIT 0x3B 00110 #define TIME_LATENCY 0x3C 00111 #define TIME_WINDOW 0x3D 00112 #define ACT_THS 0x3E 00113 #define ACT_DUR 0x3F 00114 00115 // The LSM9DS0 functions over both I2C or SPI. This library supports both. 00116 // But the interface mode used must be sent to the LSM9DS0 constructor. Use 00117 // one of these two as the first parameter of the constructor. 00118 enum interface_mode 00119 { 00120 SPI_MODE = 1, 00121 I2C_MODE = 0, 00122 }; 00123 00124 class LSM9DS0 00125 { 00126 public: 00127 // gyro_scale defines the possible full-scale ranges of the gyroscope: 00128 enum gyro_scale 00129 { 00130 G_SCALE_245DPS = 0x0, // 00: 245 degrees per second 00131 G_SCALE_500DPS = 0x1, // 01: 500 dps 00132 G_SCALE_2000DPS = 0x2, // 10: 2000 dps 00133 }; 00134 // accel_scale defines all possible FSR's of the accelerometer: 00135 enum accel_scale 00136 { 00137 A_SCALE_2G = 0x0, // 000: 2g 00138 A_SCALE_4G = 0x1, // 001: 4g 00139 A_SCALE_6G = 0x2, // 010: 6g 00140 A_SCALE_8G = 0x3, // 011: 8g 00141 A_SCALE_16G = 0x4, // 100: 16g 00142 }; 00143 // mag_scale defines all possible FSR's of the magnetometer: 00144 enum mag_scale 00145 { 00146 M_SCALE_2GS = 0x0, // 00: 2Gs 00147 M_SCALE_4GS = 0x1, // 01: 4Gs 00148 M_SCALE_8GS = 0x2, // 10: 8Gs 00149 M_SCALE_12GS= 0x3, // 11: 12Gs 00150 }; 00151 // gyro_odr defines all possible data rate/bandwidth combos of the gyro: 00152 enum gyro_odr 00153 { // ODR (Hz) --- Cutoff 00154 G_ODR_95_BW_125 = 0x0, // 95 12.5 00155 G_ODR_95_BW_25 = 0x1, // 95 25 00156 // 0x2 and 0x3 define the same data rate and bandwidth 00157 G_ODR_190_BW_125 = 0x4, // 190 12.5 00158 G_ODR_190_BW_25 = 0x5, // 190 25 00159 G_ODR_190_BW_50 = 0x6, // 190 50 00160 G_ODR_190_BW_70 = 0x7, // 190 70 00161 G_ODR_380_BW_20 = 0x8, // 380 20 00162 G_ODR_380_BW_25 = 0x9, // 380 25 00163 G_ODR_380_BW_50 = 0xA, // 380 50 00164 G_ODR_380_BW_100 = 0xB, // 380 100 00165 G_ODR_760_BW_30 = 0xC, // 760 30 00166 G_ODR_760_BW_35 = 0xD, // 760 35 00167 G_ODR_760_BW_50 = 0xE, // 760 50 00168 G_ODR_760_BW_100 = 0xF, // 760 100 00169 }; 00170 // accel_oder defines all possible output data rates of the accelerometer: 00171 enum accel_odr 00172 { 00173 A_POWER_DOWN= 0x00, // Power-down mode (0x0) 00174 A_ODR_3125 = 0x01, // 3.125 Hz (0x1) 00175 A_ODR_625 = 0x02, // 6.25 Hz (0x2) 00176 A_ODR_125 = 0x03, // 12.5 Hz (0x3) 00177 A_ODR_25 = 0x04, // 25 Hz (0x4) 00178 A_ODR_50 = 0x05, // 50 Hz (0x5) 00179 A_ODR_100 = 0x06, // 100 Hz (0x6) 00180 A_ODR_200 = 0x07, // 200 Hz (0x7) 00181 A_ODR_400 = 0x08, // 400 Hz (0x8) 00182 A_ODR_800 = 0x09, // 800 Hz (9) 00183 A_ODR_1600 = 0x0A, // 1600 Hz (0xA) 00184 }; 00185 00186 // accel_abw defines all possible anti-aliasing filter rates of the accelerometer: 00187 enum accel_abw 00188 { 00189 A_ABW_773 = 0x0, // 773 Hz (0x0) 00190 A_ABW_194 = 0x1, // 194 Hz (0x1) 00191 A_ABW_362 = 0x2, // 362 Hz (0x2) 00192 A_ABW_50 = 0x3, // 50 Hz (0x3) 00193 }; 00194 00195 00196 // mag_oder defines all possible output data rates of the magnetometer: 00197 enum mag_odr 00198 { 00199 M_ODR_3125 = 0x00, // 3.125 Hz (0x00) 00200 M_ODR_625 = 0x01, // 6.25 Hz (0x01) 00201 M_ODR_125 = 0x02, // 12.5 Hz (0x02) 00202 M_ODR_25 = 0x03, // 25 Hz (0x03) 00203 M_ODR_50 = 0x04, // 50 (0x04) 00204 M_ODR_100 = 0x05, // 100 Hz (0x05) 00205 }; 00206 00207 // We'll store the gyro, accel, and magnetometer readings in a series of 00208 // public class variables. Each sensor gets three variables -- one for each 00209 // axis. Call readGyro(), readAccel(), and readMag() first, before using 00210 // these variables! 00211 // These values are the RAW signed 16-bit readings from the sensors. 00212 int16_t gx, gy, gz; // x, y, and z axis readings of the gyroscope 00213 int16_t ax, ay, az; // x, y, and z axis readings of the accelerometer 00214 int16_t mx, my, mz; // x, y, and z axis readings of the magnetometer 00215 int16_t temperature; 00216 float abias[3]; 00217 float gbias[3]; 00218 00219 int16_t gyroOffset[3]; 00220 int16_t accelOffset[3]; 00221 int16_t magOffset[3]; 00222 void setGyroOffset(int16_t, int16_t, int16_t); 00223 void setAccelOffset(int16_t, int16_t, int16_t); 00224 void setMagOffset(int16_t, int16_t, int16_t); 00225 00226 // LSM9DS0 -- LSM9DS0 class constructor 00227 // The constructor will set up a handful of private variables, and set the 00228 // communication mode as well. 00229 // Input: 00230 // - interface = Either SPI_MODE or I2C_MODE, whichever you're using 00231 // to talk to the IC. 00232 // - gAddr = If I2C_MODE, this is the I2C address of the gyroscope. 00233 // If SPI_MODE, this is the chip select pin of the gyro (CSG) 00234 // - xmAddr = If I2C_MODE, this is the I2C address of the accel/mag. 00235 // If SPI_MODE, this is the cs pin of the accel/mag (CSXM) 00236 LSM9DS0(interface_mode interface, uint8_t gAddr, uint8_t xmAddr); 00237 00238 // begin() -- Initialize the gyro, accelerometer, and magnetometer. 00239 // This will set up the scale and output rate of each sensor. It'll also 00240 // "turn on" every sensor and every axis of every sensor. 00241 // Input: 00242 // - gScl = The scale of the gyroscope. This should be a gyro_scale value. 00243 // - aScl = The scale of the accelerometer. Should be a accel_scale value. 00244 // - mScl = The scale of the magnetometer. Should be a mag_scale value. 00245 // - gODR = Output data rate of the gyroscope. gyro_odr value. 00246 // - aODR = Output data rate of the accelerometer. accel_odr value. 00247 // - mODR = Output data rate of the magnetometer. mag_odr value. 00248 // Output: The function will return an unsigned 16-bit value. The most-sig 00249 // bytes of the output are the WHO_AM_I reading of the accel. The 00250 // least significant two bytes are the WHO_AM_I reading of the gyro. 00251 // All parameters have a defaulted value, so you can call just "begin()". 00252 // Default values are FSR's of: 2000DPS, 8g, 8Gs; ODRs of 760 Hz for 00253 // gyro, 800 Hz for accelerometer, 100 Hz for magnetometer. 00254 // Use the return value of this function to verify communication. 00255 uint16_t begin(gyro_scale gScl = G_SCALE_2000DPS, 00256 accel_scale aScl = A_SCALE_8G, mag_scale mScl = M_SCALE_8GS, 00257 gyro_odr gODR = G_ODR_760_BW_100, accel_odr aODR = A_ODR_800, 00258 mag_odr mODR = M_ODR_100); 00259 00260 // readGyro() -- Read the gyroscope output registers. 00261 // This function will read all six gyroscope output registers. 00262 // The readings are stored in the class' gx, gy, and gz variables. Read 00263 // those _after_ calling readGyro(). 00264 void readGyro(); 00265 int16_t readRawGyroX( void ); 00266 int16_t readRawGyroY( void ); 00267 int16_t readRawGyroZ( void ); 00268 float readFloatGyroX( void ); 00269 float readFloatGyroY( void ); 00270 float readFloatGyroZ( void ); 00271 00272 // readAccel() -- Read the accelerometer output registers. 00273 // This function will read all six accelerometer output registers. 00274 // The readings are stored in the class' ax, ay, and az variables. Read 00275 // those _after_ calling readAccel(). 00276 void readAccel(); 00277 int16_t readRawAccelX( void ); 00278 int16_t readRawAccelY( void ); 00279 int16_t readRawAccelZ( void ); 00280 float readFloatAccelX( void ); 00281 float readFloatAccelY( void ); 00282 float readFloatAccelZ( void ); 00283 00284 // readMag() -- Read the magnetometer output registers. 00285 // This function will read all six magnetometer output registers. 00286 // The readings are stored in the class' mx, my, and mz variables. Read 00287 // those _after_ calling readMag(). 00288 void readMag(); 00289 int16_t readRawMagX( void ); 00290 int16_t readRawMagY( void ); 00291 int16_t readRawMagZ( void ); 00292 float readFloatMagX( void ); 00293 float readFloatMagY( void ); 00294 float readFloatMagZ( void ); 00295 00296 // readTemp() -- Read the temperature output register. 00297 // This function will read two temperature output registers. 00298 // The combined readings are stored in the class' temperature variables. Read 00299 // those _after_ calling readTemp(). 00300 void readTemp(); 00301 00302 // calcGyro() -- Convert from RAW signed 16-bit value to degrees per second 00303 // This function reads in a signed 16-bit value and returns the scaled 00304 // DPS. This function relies on gScale and gRes being correct. 00305 // Input: 00306 // - gyro = A signed 16-bit raw reading from the gyroscope. 00307 float calcGyro(int16_t gyro); 00308 00309 // calcAccel() -- Convert from RAW signed 16-bit value to gravity (g's). 00310 // This function reads in a signed 16-bit value and returns the scaled 00311 // g's. This function relies on aScale and aRes being correct. 00312 // Input: 00313 // - accel = A signed 16-bit raw reading from the accelerometer. 00314 float calcAccel(int16_t accel); 00315 00316 // calcMag() -- Convert from RAW signed 16-bit value to Gauss (Gs) 00317 // This function reads in a signed 16-bit value and returns the scaled 00318 // Gs. This function relies on mScale and mRes being correct. 00319 // Input: 00320 // - mag = A signed 16-bit raw reading from the magnetometer. 00321 float calcMag(int16_t mag); 00322 00323 // setGyroScale() -- Set the full-scale range of the gyroscope. 00324 // This function can be called to set the scale of the gyroscope to 00325 // 245, 500, or 200 degrees per second. 00326 // Input: 00327 // - gScl = The desired gyroscope scale. Must be one of three possible 00328 // values from the gyro_scale enum. 00329 void setGyroScale(gyro_scale gScl); 00330 00331 // setAccelScale() -- Set the full-scale range of the accelerometer. 00332 // This function can be called to set the scale of the accelerometer to 00333 // 2, 4, 6, 8, or 16 g's. 00334 // Input: 00335 // - aScl = The desired accelerometer scale. Must be one of five possible 00336 // values from the accel_scale enum. 00337 void setAccelScale(accel_scale aScl); 00338 00339 // setMagScale() -- Set the full-scale range of the magnetometer. 00340 // This function can be called to set the scale of the magnetometer to 00341 // 2, 4, 8, or 12 Gs. 00342 // Input: 00343 // - mScl = The desired magnetometer scale. Must be one of four possible 00344 // values from the mag_scale enum. 00345 void setMagScale(mag_scale mScl); 00346 00347 // setGyroODR() -- Set the output data rate and bandwidth of the gyroscope 00348 // Input: 00349 // - gRate = The desired output rate and cutoff frequency of the gyro. 00350 // Must be a value from the gyro_odr enum (check above, there're 14). 00351 void setGyroODR(gyro_odr gRate); 00352 00353 // setAccelODR() -- Set the output data rate of the accelerometer 00354 // Input: 00355 // - aRate = The desired output rate of the accel. 00356 // Must be a value from the accel_odr enum (check above, there're 11). 00357 void setAccelODR(accel_odr aRate); 00358 00359 // setAccelABW() -- Set the anti-aliasing filter rate of the accelerometer 00360 // Input: 00361 // - abwRate = The desired anti-aliasing filter rate of the accel. 00362 // Must be a value from the accel_abw enum (check above, there're 4). 00363 void setAccelABW(accel_abw abwRate); 00364 00365 // setMagODR() -- Set the output data rate of the magnetometer 00366 // Input: 00367 // - mRate = The desired output rate of the mag. 00368 // Must be a value from the mag_odr enum (check above, there're 6). 00369 void setMagODR(mag_odr mRate); 00370 00371 // configGyroInt() -- Configure the gyro interrupt output. 00372 // Triggers can be set to either rising above or falling below a specified 00373 // threshold. This function helps setup the interrupt configuration and 00374 // threshold values for all axes. 00375 // Input: 00376 // - int1Cfg = A 8-bit value that is sent directly to the INT1_CFG_G 00377 // register. This sets AND/OR and high/low interrupt gen for each axis 00378 // - int1ThsX = 16-bit interrupt threshold value for x-axis 00379 // - int1ThsY = 16-bit interrupt threshold value for y-axis 00380 // - int1ThsZ = 16-bit interrupt threshold value for z-axis 00381 // - duration = Duration an interrupt holds after triggered. This value 00382 // is copied directly into the INT1_DURATION_G register. 00383 // Before using this function, read about the INT1_CFG_G register and 00384 // the related INT1* registers in the LMS9DS0 datasheet. 00385 void configGyroInt(uint8_t int1Cfg, uint16_t int1ThsX = 0, 00386 uint16_t int1ThsY = 0, uint16_t int1ThsZ = 0, 00387 uint8_t duration = 0); 00388 00389 00390 void calLSM9DS0(float gbias[3], float abias[3]); 00391 00392 SPI spi_; 00393 I2C i2c_; 00394 DigitalOut csG_; 00395 DigitalOut csXM_; 00396 00397 00398 float pitch, roll; 00399 void complementaryFilter(float data[6], float dt); 00400 00401 float debug; 00402 private: 00403 // xmAddress and gAddress store the I2C address or SPI chip select pin 00404 // for each sensor. 00405 uint8_t xmAddress, gAddress; 00406 // interfaceMode keeps track of whether we're using SPI or I2C to talk 00407 interface_mode interfaceMode; 00408 00409 // gScale, aScale, and mScale store the current scale range for each 00410 // sensor. Should be updated whenever that value changes. 00411 gyro_scale gScale; 00412 accel_scale aScale; 00413 mag_scale mScale; 00414 00415 // gRes, aRes, and mRes store the current resolution for each sensor. 00416 // Units of these values would be DPS (or g's or Gs's) per ADC tick. 00417 // This value is calculated as (sensor scale) / (2^15). 00418 float gRes, aRes, mRes; 00419 00420 // initGyro() -- Sets up the gyroscope to begin reading. 00421 // This function steps through all five gyroscope control registers. 00422 // Upon exit, the following parameters will be set: 00423 // - CTRL_REG1_G = 0x0F: Normal operation mode, all axes enabled. 00424 // 95 Hz ODR, 12.5 Hz cutoff frequency. 00425 // - CTRL_REG2_G = 0x00: HPF set to normal mode, cutoff frequency 00426 // set to 7.2 Hz (depends on ODR). 00427 // - CTRL_REG3_G = 0x88: Interrupt enabled on INT_G (set to push-pull and 00428 // active high). Data-ready output enabled on DRDY_G. 00429 // - CTRL_REG4_G = 0x00: Continuous update mode. Data LSB stored in lower 00430 // address. Scale set to 245 DPS. SPI mode set to 4-wire. 00431 // - CTRL_REG5_G = 0x00: FIFO disabled. HPF disabled. 00432 void initGyro(); 00433 00434 // initAccel() -- Sets up the accelerometer to begin reading. 00435 // This function steps through all accelerometer related control registers. 00436 // Upon exit these registers will be set as: 00437 // - CTRL_REG0_XM = 0x00: FIFO disabled. HPF bypassed. Normal mode. 00438 // - CTRL_REG1_XM = 0x57: 100 Hz data rate. Continuous update. 00439 // all axes enabled. 00440 // - CTRL_REG2_XM = 0x00: 2g scale. 773 Hz anti-alias filter BW. 00441 // - CTRL_REG3_XM = 0x04: Accel data ready signal on INT1_XM pin. 00442 void initAccel(); 00443 00444 // initMag() -- Sets up the magnetometer to begin reading. 00445 // This function steps through all magnetometer-related control registers. 00446 // Upon exit these registers will be set as: 00447 // - CTRL_REG4_XM = 0x04: Mag data ready signal on INT2_XM pin. 00448 // - CTRL_REG5_XM = 0x14: 100 Hz update rate. Low resolution. Interrupt 00449 // requests don't latch. Temperature sensor disabled. 00450 // - CTRL_REG6_XM = 0x00: 2 Gs scale. 00451 // - CTRL_REG7_XM = 0x00: Continuous conversion mode. Normal HPF mode. 00452 // - INT_CTRL_REG_M = 0x09: Interrupt active-high. Enable interrupts. 00453 void initMag(); 00454 00455 // gReadByte() -- Reads a byte from a specified gyroscope register. 00456 // Input: 00457 // - subAddress = Register to be read from. 00458 // Output: 00459 // - An 8-bit value read from the requested address. 00460 uint8_t gReadByte(uint8_t subAddress); 00461 00462 // gReadBytes() -- Reads a number of bytes -- beginning at an address 00463 // and incrementing from there -- from the gyroscope. 00464 // Input: 00465 // - subAddress = Register to be read from. 00466 // - * dest = A pointer to an array of uint8_t's. Values read will be 00467 // stored in here on return. 00468 // - count = The number of bytes to be read. 00469 // Output: No value is returned, but the `dest` array will store 00470 // the data read upon exit. 00471 void gReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count); 00472 00473 // gWriteByte() -- Write a byte to a register in the gyroscope. 00474 // Input: 00475 // - subAddress = Register to be written to. 00476 // - data = data to be written to the register. 00477 void gWriteByte(uint8_t subAddress, uint8_t data); 00478 00479 // xmReadByte() -- Read a byte from a register in the accel/mag sensor 00480 // Input: 00481 // - subAddress = Register to be read from. 00482 // Output: 00483 // - An 8-bit value read from the requested register. 00484 uint8_t xmReadByte(uint8_t subAddress); 00485 00486 // xmReadBytes() -- Reads a number of bytes -- beginning at an address 00487 // and incrementing from there -- from the accelerometer/magnetometer. 00488 // Input: 00489 // - subAddress = Register to be read from. 00490 // - * dest = A pointer to an array of uint8_t's. Values read will be 00491 // stored in here on return. 00492 // - count = The number of bytes to be read. 00493 // Output: No value is returned, but the `dest` array will store 00494 // the data read upon exit. 00495 void xmReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count); 00496 00497 // xmWriteByte() -- Write a byte to a register in the accel/mag sensor. 00498 // Input: 00499 // - subAddress = Register to be written to. 00500 // - data = data to be written to the register. 00501 void xmWriteByte(uint8_t subAddress, uint8_t data); 00502 00503 // calcgRes() -- Calculate the resolution of the gyroscope. 00504 // This function will set the value of the gRes variable. gScale must 00505 // be set prior to calling this function. 00506 void calcgRes(); 00507 00508 // calcmRes() -- Calculate the resolution of the magnetometer. 00509 // This function will set the value of the mRes variable. mScale must 00510 // be set prior to calling this function. 00511 void calcmRes(); 00512 00513 // calcaRes() -- Calculate the resolution of the accelerometer. 00514 // This function will set the value of the aRes variable. aScale must 00515 // be set prior to calling this function. 00516 void calcaRes(); 00517 00518 /////////////////// 00519 // SPI Functions // 00520 /////////////////// 00521 // initSPI() -- Initialize the SPI hardware. 00522 // This function will setup all SPI pins and related hardware. 00523 void initSPI(); 00524 00525 // SPIwriteByte() -- Write a byte out of SPI to a register in the device 00526 // Input: 00527 // - csPin = The chip select pin of the slave device. 00528 // - subAddress = The register to be written to. 00529 // - data = Byte to be written to the register. 00530 void SPIwriteByte(uint8_t csPin, uint8_t subAddress, uint8_t data); 00531 00532 // SPIreadByte() -- Read a single byte from a register over SPI. 00533 // Input: 00534 // - csPin = The chip select pin of the slave device. 00535 // - subAddress = The register to be read from. 00536 // Output: 00537 // - The byte read from the requested address. 00538 uint8_t SPIreadByte(uint8_t csPin, uint8_t subAddress); 00539 00540 // SPIreadBytes() -- Read a series of bytes, starting at a register via SPI 00541 // Input: 00542 // - csPin = The chip select pin of a slave device. 00543 // - subAddress = The register to begin reading. 00544 // - * dest = Pointer to an array where we'll store the readings. 00545 // - count = Number of registers to be read. 00546 // Output: No value is returned by the function, but the registers read are 00547 // all stored in the *dest array given. 00548 void SPIreadBytes(uint8_t csPin, uint8_t subAddress, 00549 uint8_t * dest, uint8_t count); 00550 00551 /////////////////// 00552 // I2C Functions // 00553 /////////////////// 00554 // initI2C() -- Initialize the I2C hardware. 00555 // This function will setup all I2C pins and related hardware. 00556 void initI2C(); 00557 00558 // I2CwriteByte() -- Write a byte out of I2C to a register in the device 00559 // Input: 00560 // - address = The 7-bit I2C address of the slave device. 00561 // - subAddress = The register to be written to. 00562 // - data = Byte to be written to the register. 00563 void I2CwriteByte(uint8_t address, uint8_t subAddress, uint8_t data); 00564 00565 // I2CreadByte() -- Read a single byte from a register over I2C. 00566 // Input: 00567 // - address = The 7-bit I2C address of the slave device. 00568 // - subAddress = The register to be read from. 00569 // Output: 00570 // - The byte read from the requested address. 00571 uint8_t I2CreadByte(uint8_t address, uint8_t subAddress); 00572 00573 // I2CreadBytes() -- Read a series of bytes, starting at a register via SPI 00574 // Input: 00575 // - address = The 7-bit I2C address of the slave device. 00576 // - subAddress = The register to begin reading. 00577 // - * dest = Pointer to an array where we'll store the readings. 00578 // - count = Number of registers to be read. 00579 // Output: No value is returned by the function, but the registers read are 00580 // all stored in the *dest array given. 00581 void I2CreadBytes(uint8_t address, uint8_t subAddress, uint8_t * dest, uint8_t count); 00582 00583 00584 }; 00585 00586 #endif // SFE_LSM9DS0_H //
Generated on Thu Jul 14 2022 20:25:30 by
