I2Cdevlib

I2C device library collection for AVR/Arduino or other C++-based MCUs

HMC5843/HMC5843.h
00001 // I2Cdev library collection - HMC5843 I2C device class header file
00002 // Based on Honeywell HMC5843 datasheet, 6/2010 (Form #900367)
00003 // 8/22/2011 by Jeff Rowberg <jeff@rowberg.net>
00004 // Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
00005 //
00006 // Changelog:
00007 //     2011-08-22 - initial release
00008 
00009 /* ============================================
00010 I2Cdev device library code is placed under the MIT license
00011 Copyright (c) 2011 Jeff Rowberg
00012 
00013 Permission is hereby granted, free of charge, to any person obtaining a copy
00014 of this software and associated documentation files (the "Software"), to deal
00015 in the Software without restriction, including without limitation the rights
00016 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00017 copies of the Software, and to permit persons to whom the Software is
00018 furnished to do so, subject to the following conditions:
00019 
00020 The above copyright notice and this permission notice shall be included in
00021 all copies or substantial portions of the Software.
00022 
00023 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00024 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00025 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00026 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00027 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00028 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00029 THE SOFTWARE.
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         // CONFIG_A register
00151         uint8_t getDataRate();
00152         void setDataRate(uint8_t rate);
00153         uint8_t getMeasurementBias();
00154         void setMeasurementBias(uint8_t bias);
00155 
00156         // CONFIG_B register
00157         uint8_t getGain();
00158         void setGain(uint8_t gain);
00159 
00160         // MODE register
00161         uint8_t getMode();
00162         void setMode(uint8_t mode);
00163 
00164         // DATA* registers
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         // STATUS register
00171         bool getRegulatorEnabledStatus();
00172         bool getLockStatus();
00173         bool getReadyStatus();
00174 
00175         // ID_* registers
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 /* _HMC5843_H_ */
 All Data Structures Functions Variables