A library to interface with the LSM9DS1 IMU using SPI
LSM9DS1_SPI.h@0:dc98084cf6be, 2017-10-18 (annotated)
- Committer:
- Anaesthetix
- Date:
- Wed Oct 18 09:22:00 2017 +0000
- Revision:
- 0:dc98084cf6be
LSM9DS1 spi library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Anaesthetix | 0:dc98084cf6be | 1 | // Written by: Erik van de Coevering |
Anaesthetix | 0:dc98084cf6be | 2 | |
Anaesthetix | 0:dc98084cf6be | 3 | #ifndef __LSM9DS1_SPI_H__ |
Anaesthetix | 0:dc98084cf6be | 4 | #define __LSM9DS1_SPI_H__ |
Anaesthetix | 0:dc98084cf6be | 5 | |
Anaesthetix | 0:dc98084cf6be | 6 | #include "mbed.h" |
Anaesthetix | 0:dc98084cf6be | 7 | |
Anaesthetix | 0:dc98084cf6be | 8 | class lsm9ds1_spi |
Anaesthetix | 0:dc98084cf6be | 9 | { |
Anaesthetix | 0:dc98084cf6be | 10 | SPI& spi; |
Anaesthetix | 0:dc98084cf6be | 11 | DigitalOut csAG; |
Anaesthetix | 0:dc98084cf6be | 12 | DigitalOut csM; |
Anaesthetix | 0:dc98084cf6be | 13 | |
Anaesthetix | 0:dc98084cf6be | 14 | public: |
Anaesthetix | 0:dc98084cf6be | 15 | lsm9ds1_spi(SPI& _spi, PinName _csAG, PinName _csM); |
Anaesthetix | 0:dc98084cf6be | 16 | unsigned int WriteRegAG(uint8_t WriteAddr, uint8_t WriteData); |
Anaesthetix | 0:dc98084cf6be | 17 | unsigned int WriteRegM(uint8_t WriteAddr, uint8_t WriteData); |
Anaesthetix | 0:dc98084cf6be | 18 | unsigned int ReadRegAG(uint8_t WriteAddr, uint8_t WriteData); |
Anaesthetix | 0:dc98084cf6be | 19 | unsigned int ReadRegM(uint8_t WriteAddr, uint8_t WriteData); |
Anaesthetix | 0:dc98084cf6be | 20 | void ReadRegsAG(uint8_t ReadAddr, uint8_t *ReadBuf, unsigned int Bytes ); |
Anaesthetix | 0:dc98084cf6be | 21 | void ReadRegsM(uint8_t ReadAddr, uint8_t *ReadBuf, unsigned int Bytes ); |
Anaesthetix | 0:dc98084cf6be | 22 | |
Anaesthetix | 0:dc98084cf6be | 23 | void selectAG(); |
Anaesthetix | 0:dc98084cf6be | 24 | void selectM(); |
Anaesthetix | 0:dc98084cf6be | 25 | void deselectAG(); |
Anaesthetix | 0:dc98084cf6be | 26 | void deselectM(); |
Anaesthetix | 0:dc98084cf6be | 27 | |
Anaesthetix | 0:dc98084cf6be | 28 | void init(); |
Anaesthetix | 0:dc98084cf6be | 29 | unsigned int whoami(); |
Anaesthetix | 0:dc98084cf6be | 30 | unsigned int whoamiM(); |
Anaesthetix | 0:dc98084cf6be | 31 | float read_temp(); // reads temperature in degrees C |
Anaesthetix | 0:dc98084cf6be | 32 | void read_acc(); // reads accelerometer in G |
Anaesthetix | 0:dc98084cf6be | 33 | void read_gyr(); // reads gyroscope in DPS |
Anaesthetix | 0:dc98084cf6be | 34 | void read_mag(); // reads magnetometer in gauss |
Anaesthetix | 0:dc98084cf6be | 35 | void read_all(); // reads acc / gyro / magneto |
Anaesthetix | 0:dc98084cf6be | 36 | |
Anaesthetix | 0:dc98084cf6be | 37 | float acc_multiplier; |
Anaesthetix | 0:dc98084cf6be | 38 | float gyro_multiplier; |
Anaesthetix | 0:dc98084cf6be | 39 | float mag_multiplier; |
Anaesthetix | 0:dc98084cf6be | 40 | float accelerometer_data[3]; |
Anaesthetix | 0:dc98084cf6be | 41 | float gyroscope_data[3]; |
Anaesthetix | 0:dc98084cf6be | 42 | float magnetometer_data[3]; |
Anaesthetix | 0:dc98084cf6be | 43 | |
Anaesthetix | 0:dc98084cf6be | 44 | }; |
Anaesthetix | 0:dc98084cf6be | 45 | |
Anaesthetix | 0:dc98084cf6be | 46 | #define FS_G_245DPS 0x00 |
Anaesthetix | 0:dc98084cf6be | 47 | #define FS_G_500DPS 0x08 |
Anaesthetix | 0:dc98084cf6be | 48 | #define FS_G_2000DPS 0x18 |
Anaesthetix | 0:dc98084cf6be | 49 | #define ODR_G_15HZ 0x20 |
Anaesthetix | 0:dc98084cf6be | 50 | #define ODR_G_60HZ 0x40 |
Anaesthetix | 0:dc98084cf6be | 51 | #define ODR_G_119HZ 0x60 |
Anaesthetix | 0:dc98084cf6be | 52 | #define ODR_G_238HZ 0x80 |
Anaesthetix | 0:dc98084cf6be | 53 | #define ODR_G_476HZ 0xA0 |
Anaesthetix | 0:dc98084cf6be | 54 | #define ODR_G_952HZ 0xC0 |
Anaesthetix | 0:dc98084cf6be | 55 | #define BW_G_33HZ 0x00 // Bandwidth dependant on ODR, these freq's are correct for ODR=476Hz or 952Hz. Check datasheet for other ODR's |
Anaesthetix | 0:dc98084cf6be | 56 | #define BW_G_40HZ 0x01 |
Anaesthetix | 0:dc98084cf6be | 57 | #define BW_G_58HZ 0x02 |
Anaesthetix | 0:dc98084cf6be | 58 | #define BW_G_100HZ 0x03 |
Anaesthetix | 0:dc98084cf6be | 59 | #define FS_A_2G 0x00 |
Anaesthetix | 0:dc98084cf6be | 60 | #define FS_A_4G 0x10 |
Anaesthetix | 0:dc98084cf6be | 61 | #define FS_A_8G 0x18 |
Anaesthetix | 0:dc98084cf6be | 62 | #define FS_A_16G 0x08 |
Anaesthetix | 0:dc98084cf6be | 63 | #define FS_M_4GAUSS 0x00 |
Anaesthetix | 0:dc98084cf6be | 64 | #define FS_M_8GAUSS 0x20 |
Anaesthetix | 0:dc98084cf6be | 65 | #define FS_M_12GAUSS 0x40 |
Anaesthetix | 0:dc98084cf6be | 66 | #define FS_M_16GAUSS 0x60 |
Anaesthetix | 0:dc98084cf6be | 67 | |
Anaesthetix | 0:dc98084cf6be | 68 | #define ACC_SENS_2G 0.000061f |
Anaesthetix | 0:dc98084cf6be | 69 | #define ACC_SENS_4G 0.000122f |
Anaesthetix | 0:dc98084cf6be | 70 | #define ACC_SENS_8G 0.000244f |
Anaesthetix | 0:dc98084cf6be | 71 | #define ACC_SENS_16G 0.000732f |
Anaesthetix | 0:dc98084cf6be | 72 | #define GYR_SENS_245DPS 0.00875f |
Anaesthetix | 0:dc98084cf6be | 73 | #define GYR_SENS_500DPS 0.0175f |
Anaesthetix | 0:dc98084cf6be | 74 | #define GYR_SENS_2000DPS 0.07f |
Anaesthetix | 0:dc98084cf6be | 75 | #define MAG_SENS_4GAUSS 0.00014f |
Anaesthetix | 0:dc98084cf6be | 76 | #define MAG_SENS_8GAUSS 0.00029f |
Anaesthetix | 0:dc98084cf6be | 77 | #define MAG_SENS_12GAUSS 0.00043f |
Anaesthetix | 0:dc98084cf6be | 78 | #define MAG_SENS_16GAUSS 0.000732f |
Anaesthetix | 0:dc98084cf6be | 79 | |
Anaesthetix | 0:dc98084cf6be | 80 | #define READ_FLAG 0x80 |
Anaesthetix | 0:dc98084cf6be | 81 | |
Anaesthetix | 0:dc98084cf6be | 82 | #endif |
Anaesthetix | 0:dc98084cf6be | 83 | |
Anaesthetix | 0:dc98084cf6be | 84 |