Added mag calibration and interrupt-based data ready
Dependencies: BLE_API mbed-src nRF51822
EM7180.h@4:8d11bfc7cac0, 2016-09-22 (annotated)
- Committer:
- onehorse
- Date:
- Thu Sep 22 01:21:24 2016 +0000
- Revision:
- 4:8d11bfc7cac0
Added mag calibration and interrupt-based data ready
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
onehorse | 4:8d11bfc7cac0 | 1 | #ifndef EM7180_H |
onehorse | 4:8d11bfc7cac0 | 2 | #define EM7180_H |
onehorse | 4:8d11bfc7cac0 | 3 | |
onehorse | 4:8d11bfc7cac0 | 4 | //#include "mbed.h" |
onehorse | 4:8d11bfc7cac0 | 5 | |
onehorse | 4:8d11bfc7cac0 | 6 | // EM7180 SENtral register map |
onehorse | 4:8d11bfc7cac0 | 7 | // see http://www.emdeveloper.com/downloads/7180/EMSentral_EM7180_Register_Map_v1_3.pdf |
onehorse | 4:8d11bfc7cac0 | 8 | // |
onehorse | 4:8d11bfc7cac0 | 9 | #define EM7180_QX 0x00 // this is a 32-bit normalized floating point number read from registers 0x00-03 |
onehorse | 4:8d11bfc7cac0 | 10 | #define EM7180_QY 0x04 // this is a 32-bit normalized floating point number read from registers 0x04-07 |
onehorse | 4:8d11bfc7cac0 | 11 | #define EM7180_QZ 0x08 // this is a 32-bit normalized floating point number read from registers 0x08-0B |
onehorse | 4:8d11bfc7cac0 | 12 | #define EM7180_QW 0x0C // this is a 32-bit normalized floating point number read from registers 0x0C-0F |
onehorse | 4:8d11bfc7cac0 | 13 | #define EM7180_QTIME 0x10 // this is a 16-bit unsigned integer read from registers 0x10-11 |
onehorse | 4:8d11bfc7cac0 | 14 | #define EM7180_MX 0x12 // int16_t from registers 0x12-13 |
onehorse | 4:8d11bfc7cac0 | 15 | #define EM7180_MY 0x14 // int16_t from registers 0x14-15 |
onehorse | 4:8d11bfc7cac0 | 16 | #define EM7180_MZ 0x16 // int16_t from registers 0x16-17 |
onehorse | 4:8d11bfc7cac0 | 17 | #define EM7180_MTIME 0x18 // uint16_t from registers 0x18-19 |
onehorse | 4:8d11bfc7cac0 | 18 | #define EM7180_AX 0x1A // int16_t from registers 0x1A-1B |
onehorse | 4:8d11bfc7cac0 | 19 | #define EM7180_AY 0x1C // int16_t from registers 0x1C-1D |
onehorse | 4:8d11bfc7cac0 | 20 | #define EM7180_AZ 0x1E // int16_t from registers 0x1E-1F |
onehorse | 4:8d11bfc7cac0 | 21 | #define EM7180_ATIME 0x20 // uint16_t from registers 0x20-21 |
onehorse | 4:8d11bfc7cac0 | 22 | #define EM7180_GX 0x22 // int16_t from registers 0x22-23 |
onehorse | 4:8d11bfc7cac0 | 23 | #define EM7180_GY 0x24 // int16_t from registers 0x24-25 |
onehorse | 4:8d11bfc7cac0 | 24 | #define EM7180_GZ 0x26 // int16_t from registers 0x26-27 |
onehorse | 4:8d11bfc7cac0 | 25 | #define EM7180_GTIME 0x28 // uint16_t from registers 0x28-29 |
onehorse | 4:8d11bfc7cac0 | 26 | #define EM7180_Baro 0x2A // start of two-byte MS5637 pressure data, 16-bit signed interger |
onehorse | 4:8d11bfc7cac0 | 27 | #define EM7180_BaroTIME 0x2C // start of two-byte MS5637 pressure timestamp, 16-bit unsigned |
onehorse | 4:8d11bfc7cac0 | 28 | #define EM7180_Temp 0x2E // start of two-byte MS5637 temperature data, 16-bit signed interger |
onehorse | 4:8d11bfc7cac0 | 29 | #define EM7180_TempTIME 0x30 // start of two-byte MS5637 temperature timestamp, 16-bit unsigned |
onehorse | 4:8d11bfc7cac0 | 30 | #define EM7180_QRateDivisor 0x32 // uint8_t |
onehorse | 4:8d11bfc7cac0 | 31 | #define EM7180_EnableEvents 0x33 |
onehorse | 4:8d11bfc7cac0 | 32 | #define EM7180_HostControl 0x34 |
onehorse | 4:8d11bfc7cac0 | 33 | #define EM7180_EventStatus 0x35 |
onehorse | 4:8d11bfc7cac0 | 34 | #define EM7180_SensorStatus 0x36 |
onehorse | 4:8d11bfc7cac0 | 35 | #define EM7180_SentralStatus 0x37 |
onehorse | 4:8d11bfc7cac0 | 36 | #define EM7180_AlgorithmStatus 0x38 |
onehorse | 4:8d11bfc7cac0 | 37 | #define EM7180_FeatureFlags 0x39 |
onehorse | 4:8d11bfc7cac0 | 38 | #define EM7180_ParamAcknowledge 0x3A |
onehorse | 4:8d11bfc7cac0 | 39 | #define EM7180_SavedParamByte0 0x3B |
onehorse | 4:8d11bfc7cac0 | 40 | #define EM7180_SavedParamByte1 0x3C |
onehorse | 4:8d11bfc7cac0 | 41 | #define EM7180_SavedParamByte2 0x3D |
onehorse | 4:8d11bfc7cac0 | 42 | #define EM7180_SavedParamByte3 0x3E |
onehorse | 4:8d11bfc7cac0 | 43 | #define EM7180_ActualMagRate 0x45 |
onehorse | 4:8d11bfc7cac0 | 44 | #define EM7180_ActualAccelRate 0x46 |
onehorse | 4:8d11bfc7cac0 | 45 | #define EM7180_ActualGyroRate 0x47 |
onehorse | 4:8d11bfc7cac0 | 46 | #define EM7180_ActualBaroRate 0x48 |
onehorse | 4:8d11bfc7cac0 | 47 | #define EM7180_ActualTempRate 0x49 |
onehorse | 4:8d11bfc7cac0 | 48 | #define EM7180_ErrorRegister 0x50 |
onehorse | 4:8d11bfc7cac0 | 49 | #define EM7180_AlgorithmControl 0x54 |
onehorse | 4:8d11bfc7cac0 | 50 | #define EM7180_MagRate 0x55 |
onehorse | 4:8d11bfc7cac0 | 51 | #define EM7180_AccelRate 0x56 |
onehorse | 4:8d11bfc7cac0 | 52 | #define EM7180_GyroRate 0x57 |
onehorse | 4:8d11bfc7cac0 | 53 | #define EM7180_BaroRate 0x58 |
onehorse | 4:8d11bfc7cac0 | 54 | #define EM7180_TempRate 0x59 |
onehorse | 4:8d11bfc7cac0 | 55 | #define EM7180_LoadParamByte0 0x60 |
onehorse | 4:8d11bfc7cac0 | 56 | #define EM7180_LoadParamByte1 0x61 |
onehorse | 4:8d11bfc7cac0 | 57 | #define EM7180_LoadParamByte2 0x62 |
onehorse | 4:8d11bfc7cac0 | 58 | #define EM7180_LoadParamByte3 0x63 |
onehorse | 4:8d11bfc7cac0 | 59 | #define EM7180_ParamRequest 0x64 |
onehorse | 4:8d11bfc7cac0 | 60 | #define EM7180_ROMVersion1 0x70 |
onehorse | 4:8d11bfc7cac0 | 61 | #define EM7180_ROMVersion2 0x71 |
onehorse | 4:8d11bfc7cac0 | 62 | #define EM7180_RAMVersion1 0x72 |
onehorse | 4:8d11bfc7cac0 | 63 | #define EM7180_RAMVersion2 0x73 |
onehorse | 4:8d11bfc7cac0 | 64 | #define EM7180_ProductID 0x90 |
onehorse | 4:8d11bfc7cac0 | 65 | #define EM7180_RevisionID 0x91 |
onehorse | 4:8d11bfc7cac0 | 66 | #define EM7180_RunStatus 0x92 |
onehorse | 4:8d11bfc7cac0 | 67 | #define EM7180_UploadAddress 0x94 // uint16_t registers 0x94 (MSB)-5(LSB) |
onehorse | 4:8d11bfc7cac0 | 68 | #define EM7180_UploadData 0x96 |
onehorse | 4:8d11bfc7cac0 | 69 | #define EM7180_CRCHost 0x97 // uint32_t from registers 0x97-9A |
onehorse | 4:8d11bfc7cac0 | 70 | #define EM7180_ResetRequest 0x9B |
onehorse | 4:8d11bfc7cac0 | 71 | #define EM7180_PassThruStatus 0x9E |
onehorse | 4:8d11bfc7cac0 | 72 | #define EM7180_PassThruControl 0xA0 |
onehorse | 4:8d11bfc7cac0 | 73 | #define EM7180_ACC_LPF_BW 0x5B //Register GP36 |
onehorse | 4:8d11bfc7cac0 | 74 | #define EM7180_GYRO_LPF_BW 0x5C //Register GP37 |
onehorse | 4:8d11bfc7cac0 | 75 | #define EM7180_BARO_LPF_BW 0x5D //Register GP38 |
onehorse | 4:8d11bfc7cac0 | 76 | |
onehorse | 4:8d11bfc7cac0 | 77 | #define EM7180_ADDRESS 0x28<<1 // Address of the EM7180 SENtral sensor hub |
onehorse | 4:8d11bfc7cac0 | 78 | |
onehorse | 4:8d11bfc7cac0 | 79 | |
onehorse | 4:8d11bfc7cac0 | 80 | class EM7180 { |
onehorse | 4:8d11bfc7cac0 | 81 | |
onehorse | 4:8d11bfc7cac0 | 82 | protected: |
onehorse | 4:8d11bfc7cac0 | 83 | |
onehorse | 4:8d11bfc7cac0 | 84 | public: |
onehorse | 4:8d11bfc7cac0 | 85 | //=================================================================================================================== |
onehorse | 4:8d11bfc7cac0 | 86 | //====== Set of useful function to access pressure and temperature data |
onehorse | 4:8d11bfc7cac0 | 87 | //=================================================================================================================== |
onehorse | 4:8d11bfc7cac0 | 88 | |
onehorse | 4:8d11bfc7cac0 | 89 | |
onehorse | 4:8d11bfc7cac0 | 90 | void writeByte(uint8_t address, uint8_t subAddress, uint8_t data) |
onehorse | 4:8d11bfc7cac0 | 91 | { |
onehorse | 4:8d11bfc7cac0 | 92 | char data_write[2]; |
onehorse | 4:8d11bfc7cac0 | 93 | data_write[0] = subAddress; |
onehorse | 4:8d11bfc7cac0 | 94 | data_write[1] = data; |
onehorse | 4:8d11bfc7cac0 | 95 | i2c.write(address, data_write, 2, 0); |
onehorse | 4:8d11bfc7cac0 | 96 | } |
onehorse | 4:8d11bfc7cac0 | 97 | |
onehorse | 4:8d11bfc7cac0 | 98 | char readByte(uint8_t address, uint8_t subAddress) |
onehorse | 4:8d11bfc7cac0 | 99 | { |
onehorse | 4:8d11bfc7cac0 | 100 | char data[1]; // `data` will store the register data |
onehorse | 4:8d11bfc7cac0 | 101 | char data_write[1]; |
onehorse | 4:8d11bfc7cac0 | 102 | data_write[0] = subAddress; |
onehorse | 4:8d11bfc7cac0 | 103 | i2c.write(address, data_write, 1, 1); // no stop |
onehorse | 4:8d11bfc7cac0 | 104 | i2c.read(address, data, 1, 0); |
onehorse | 4:8d11bfc7cac0 | 105 | return data[0]; |
onehorse | 4:8d11bfc7cac0 | 106 | } |
onehorse | 4:8d11bfc7cac0 | 107 | |
onehorse | 4:8d11bfc7cac0 | 108 | void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t * dest) |
onehorse | 4:8d11bfc7cac0 | 109 | { |
onehorse | 4:8d11bfc7cac0 | 110 | char data[24]; |
onehorse | 4:8d11bfc7cac0 | 111 | char data_write[1]; |
onehorse | 4:8d11bfc7cac0 | 112 | data_write[0] = subAddress; |
onehorse | 4:8d11bfc7cac0 | 113 | i2c.write(address, data_write, 1, 1); // no stop |
onehorse | 4:8d11bfc7cac0 | 114 | i2c.read(address, data, count, 0); |
onehorse | 4:8d11bfc7cac0 | 115 | for(int ii = 0; ii < count; ii++) { |
onehorse | 4:8d11bfc7cac0 | 116 | dest[ii] = data[ii]; |
onehorse | 4:8d11bfc7cac0 | 117 | } |
onehorse | 4:8d11bfc7cac0 | 118 | } |
onehorse | 4:8d11bfc7cac0 | 119 | |
onehorse | 4:8d11bfc7cac0 | 120 | |
onehorse | 4:8d11bfc7cac0 | 121 | |
onehorse | 4:8d11bfc7cac0 | 122 | |
onehorse | 4:8d11bfc7cac0 | 123 | }; |
onehorse | 4:8d11bfc7cac0 | 124 | #endif |