00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef _HMC5883L_H_
00035 #define _HMC5883L_H_
00036
00037 #include "I2Cdev.h"
00038
00039 #define HMC5883L_ADDRESS 0x1E // this device only has one address
00040 #define HMC5883L_DEFAULT_ADDRESS 0x1E
00041
00042 #define HMC5883L_RA_CONFIG_A 0x00
00043 #define HMC5883L_RA_CONFIG_B 0x01
00044 #define HMC5883L_RA_MODE 0x02
00045 #define HMC5883L_RA_DATAX_H 0x03
00046 #define HMC5883L_RA_DATAX_L 0x04
00047 #define HMC5883L_RA_DATAY_H 0x05
00048 #define HMC5883L_RA_DATAY_L 0x06
00049 #define HMC5883L_RA_DATAZ_H 0x07
00050 #define HMC5883L_RA_DATAZ_L 0x08
00051 #define HMC5883L_RA_STATUS 0x09
00052 #define HMC5883L_RA_ID_A 0x0A
00053 #define HMC5883L_RA_ID_B 0x0B
00054 #define HMC5883L_RA_ID_C 0x0C
00055
00056 #define HMC5883L_CRA_AVERAGE_BIT 6
00057 #define HMC5883L_CRA_AVERAGE_LENGTH 2
00058 #define HMC5883L_CRA_RATE_BIT 4
00059 #define HMC5883L_CRA_RATE_LENGTH 3
00060 #define HMC5883L_CRA_BIAS_BIT 1
00061 #define HMC5883L_CRA_BIAS_LENGTH 2
00062
00063 #define HMC5883L_AVERAGING_1 0x00
00064 #define HMC5883L_AVERAGING_2 0x01
00065 #define HMC5883L_AVERAGING_4 0x02
00066 #define HMC5883L_AVERAGING_8 0x03
00067
00068 #define HMC5883L_RATE_0P75 0x00
00069 #define HMC5883L_RATE_1P5 0x01
00070 #define HMC5883L_RATE_3 0x02
00071 #define HMC5883L_RATE_7P5 0x03
00072 #define HMC5883L_RATE_15 0x04
00073 #define HMC5883L_RATE_30 0x05
00074 #define HMC5883L_RATE_75 0x06
00075
00076 #define HMC5883L_BIAS_NORMAL 0x00
00077 #define HMC5883L_BIAS_POSITIVE 0x01
00078 #define HMC5883L_BIAS_NEGATIVE 0x02
00079
00080 #define HMC5883L_CRB_GAIN_BIT 7
00081 #define HMC5883L_CRB_GAIN_LENGTH 3
00082
00083 #define HMC5883L_GAIN_1370 0x00
00084 #define HMC5883L_GAIN_1090 0x01
00085 #define HMC5883L_GAIN_820 0x02
00086 #define HMC5883L_GAIN_660 0x03
00087 #define HMC5883L_GAIN_440 0x04
00088 #define HMC5883L_GAIN_390 0x05
00089 #define HMC5883L_GAIN_330 0x06
00090 #define HMC5883L_GAIN_220 0x07
00091
00092 #define HMC5883L_MODEREG_BIT 1
00093 #define HMC5883L_MODEREG_LENGTH 2
00094
00095 #define HMC5883L_MODE_CONTINUOUS 0x00
00096 #define HMC5883L_MODE_SINGLE 0x01
00097 #define HMC5883L_MODE_IDLE 0x02
00098
00099 #define HMC5883L_STATUS_LOCK_BIT 1
00100 #define HMC5883L_STATUS_READY_BIT 0
00101
00102 class HMC5883L {
00103 public:
00104 HMC5883L();
00105 HMC5883L(uint8_t address);
00106
00107 void initialize();
00108 bool testConnection();
00109
00110
00111 uint8_t getSampleAveraging();
00112 void setSampleAveraging(uint8_t averaging);
00113 uint8_t getDataRate();
00114 void setDataRate(uint8_t rate);
00115 uint8_t getMeasurementBias();
00116 void setMeasurementBias(uint8_t bias);
00117
00118
00119 uint8_t getGain();
00120 void setGain(uint8_t gain);
00121
00122
00123 uint8_t getMode();
00124 void setMode(uint8_t mode);
00125
00126
00127 void getHeading(int16_t *x, int16_t *y, int16_t *z);
00128 int16_t getHeadingX();
00129 int16_t getHeadingY();
00130 int16_t getHeadingZ();
00131
00132
00133 bool getLockStatus();
00134 bool getReadyStatus();
00135
00136
00137 uint8_t getIDA();
00138 uint8_t getIDB();
00139 uint8_t getIDC();
00140
00141 private:
00142 uint8_t devAddr;
00143 uint8_t buffer[6];
00144 uint8_t mode;
00145 };
00146
00147 #endif