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 #ifndef _HMC5843_H_
00034 #define _HMC5843_H_
00035
00036 #include "I2Cdev.h"
00037
00038 #define HMC5843_ADDRESS 0x1E // this device only has one address
00039 #define HMC5843_DEFAULT_ADDRESS 0x1E
00040
00041 #define HMC5843_RA_CONFIG_A 0x00
00042 #define HMC5843_RA_CONFIG_B 0x01
00043 #define HMC5843_RA_MODE 0x02
00044 #define HMC5843_RA_DATAX_H 0x03
00045 #define HMC5843_RA_DATAX_L 0x04
00046 #define HMC5843_RA_DATAY_H 0x05
00047 #define HMC5843_RA_DATAY_L 0x06
00048 #define HMC5843_RA_DATAZ_H 0x07
00049 #define HMC5843_RA_DATAZ_L 0x08
00050 #define HMC5843_RA_STATUS 0x09
00051 #define HMC5843_RA_ID_A 0x0A
00052 #define HMC5843_RA_ID_B 0x0B
00053 #define HMC5843_RA_ID_C 0x0C
00054
00055 #define HMC5843_CRA_RATE_BIT 4
00056 #define HMC5843_CRA_RATE_LENGTH 3
00057 #define HMC5843_CRA_BIAS_BIT 1
00058 #define HMC5843_CRA_BIAS_LENGTH 2
00059
00060 #define HMC5843_RATE_0P5 0x00
00061 #define HMC5843_RATE_1 0x01
00062 #define HMC5843_RATE_2 0x02
00063 #define HMC5843_RATE_5 0x03
00064 #define HMC5843_RATE_10 0x04 // default
00065 #define HMC5843_RATE_20 0x05
00066 #define HMC5843_RATE_50 0x06
00067
00068 #define HMC5843_BIAS_NORMAL 0x00 // default
00069 #define HMC5843_BIAS_POSITIVE 0x01
00070 #define HMC5843_BIAS_NEGATIVE 0x02
00071
00072 #define HMC5843_CRB_GAIN_BIT 7
00073 #define HMC5843_CRB_GAIN_LENGTH 3
00074
00075 #define HMC5843_GAIN_1620 0x00
00076 #define HMC5843_GAIN_1300 0x01 // default
00077 #define HMC5843_GAIN_970 0x02
00078 #define HMC5843_GAIN_780 0x03
00079 #define HMC5843_GAIN_530 0x04
00080 #define HMC5843_GAIN_460 0x05
00081 #define HMC5843_GAIN_390 0x06
00082 #define HMC5843_GAIN_280 0x07 // not recommended
00083
00084 #define HMC5843_MODEREG_BIT 1
00085 #define HMC5843_MODEREG_LENGTH 2
00086
00101 #define HMC5843_MODE_CONTINUOUS 0x00
00102
00114 #define HMC5843_MODE_SINGLE 0x01
00115
00122 #define HMC5843_MODE_IDLE 0x02
00123
00136 #define HMC5843_MODE_SLEEP 0x03
00137
00138 #define HMC5843_STATUS_REN_BIT 2
00139 #define HMC5843_STATUS_LOCK_BIT 1
00140 #define HMC5843_STATUS_READY_BIT 0
00141
00142 class HMC5843 {
00143 public:
00144 HMC5843();
00145 HMC5843(uint8_t address);
00146
00147 void initialize();
00148 bool testConnection();
00149
00150
00151 uint8_t getDataRate();
00152 void setDataRate(uint8_t rate);
00153 uint8_t getMeasurementBias();
00154 void setMeasurementBias(uint8_t bias);
00155
00156
00157 uint8_t getGain();
00158 void setGain(uint8_t gain);
00159
00160
00161 uint8_t getMode();
00162 void setMode(uint8_t mode);
00163
00164
00165 void getHeading(int16_t *x, int16_t *y, int16_t *z);
00166 int16_t getHeadingX();
00167 int16_t getHeadingY();
00168 int16_t getHeadingZ();
00169
00170
00171 bool getRegulatorEnabledStatus();
00172 bool getLockStatus();
00173 bool getReadyStatus();
00174
00175
00176 uint8_t getIDA();
00177 uint8_t getIDB();
00178 uint8_t getIDC();
00179
00180 private:
00181 uint8_t devAddr;
00182 uint8_t buffer[6];
00183 uint8_t mode;
00184 };
00185
00186 #endif