NOT FINISHED YET!!! My first try to get a self built fully working Quadrocopter based on an mbed, a self built frame and some other more or less cheap parts.
Sensors/Comp/HMC5883.h@14:cf260677ecde, 2012-10-27 (annotated)
- Committer:
- maetugr
- Date:
- Sat Oct 27 10:53:43 2012 +0000
- Revision:
- 14:cf260677ecde
- Parent:
- 12:67a06c9b69d5
- Child:
- 17:e096e85f6c36
I2C Workaround gefunden!!! erster Test geklappt, vor Umschreibung
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maetugr | 11:9bf69bc6df45 | 1 | #ifndef HMC5883_H |
maetugr | 11:9bf69bc6df45 | 2 | #define HMC5883_H |
maetugr | 11:9bf69bc6df45 | 3 | |
maetugr | 11:9bf69bc6df45 | 4 | #define HMC5883_CONF_REG_A 0x00 |
maetugr | 11:9bf69bc6df45 | 5 | #define HMC5883_CONF_REG_B 0x01 |
maetugr | 11:9bf69bc6df45 | 6 | #define HMC5883_MODE_REG 0x02 |
maetugr | 11:9bf69bc6df45 | 7 | #define HMC5883_DATA_OUT_X_MSB 0x03 |
maetugr | 11:9bf69bc6df45 | 8 | |
maetugr | 11:9bf69bc6df45 | 9 | // I2C addresses |
maetugr | 11:9bf69bc6df45 | 10 | #define HMC5883_ADDRESS 0x1E |
maetugr | 11:9bf69bc6df45 | 11 | #define I2CADR_W(ADR) (ADR << 1&0xFE) // ADR & 1111 1110 |
maetugr | 11:9bf69bc6df45 | 12 | #define I2CADR_R(ADR) (ADR << 1|0x01) // ADR | 0000 0001 |
maetugr | 11:9bf69bc6df45 | 13 | |
maetugr | 11:9bf69bc6df45 | 14 | class HMC5883 |
maetugr | 11:9bf69bc6df45 | 15 | { |
maetugr | 11:9bf69bc6df45 | 16 | public: |
maetugr | 11:9bf69bc6df45 | 17 | HMC5883(PinName sda, PinName scl); |
maetugr | 11:9bf69bc6df45 | 18 | |
maetugr | 11:9bf69bc6df45 | 19 | float data[3]; |
maetugr | 11:9bf69bc6df45 | 20 | void read(); |
maetugr | 12:67a06c9b69d5 | 21 | void calibrate(int s); |
maetugr | 12:67a06c9b69d5 | 22 | float get_angle(); |
maetugr | 12:67a06c9b69d5 | 23 | |
maetugr | 12:67a06c9b69d5 | 24 | private: |
maetugr | 12:67a06c9b69d5 | 25 | I2C i2c; |
maetugr | 12:67a06c9b69d5 | 26 | |
maetugr | 12:67a06c9b69d5 | 27 | // raw data and function to measure it |
maetugr | 12:67a06c9b69d5 | 28 | int raw[3]; |
maetugr | 12:67a06c9b69d5 | 29 | void readraw(); |
maetugr | 12:67a06c9b69d5 | 30 | |
maetugr | 12:67a06c9b69d5 | 31 | // I2C functions |
maetugr | 11:9bf69bc6df45 | 32 | void writeReg(char address, char data); |
maetugr | 11:9bf69bc6df45 | 33 | void readMultiReg(char address, char* output, int size); |
maetugr | 11:9bf69bc6df45 | 34 | |
maetugr | 14:cf260677ecde | 35 | // calibration parameters and their saving |
maetugr | 14:cf260677ecde | 36 | int Min[3]; |
maetugr | 14:cf260677ecde | 37 | int Max[3]; |
maetugr | 14:cf260677ecde | 38 | float scale[3]; |
maetugr | 14:cf260677ecde | 39 | float offset[3]; |
maetugr | 14:cf260677ecde | 40 | LocalFileSystem local; |
maetugr | 11:9bf69bc6df45 | 41 | }; |
maetugr | 11:9bf69bc6df45 | 42 | |
maetugr | 11:9bf69bc6df45 | 43 | #endif |