Private HMC5843 library
Embed:
(wiki syntax)
Show/hide line numbers
HMC5843.h
00001 /** 00002 * @author Jose R. Padron 00003 *@author Used HMC5843 library developed by Aaron Berk as template 00004 * @section LICENSE 00005 * 00006 * Copyright (c) 2010 ARM Limited 00007 * 00008 * Permission is hereby granted, free of charge, to any person obtaining a copy 00009 * of this software and associated documentation files (the "Software"), to deal 00010 * in the Software without restriction, including without limitation the rights 00011 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00012 * copies of the Software, and to permit persons to whom the Software is 00013 * furnished to do so, subject to the following conditions: 00014 * 00015 * The above copyright notice and this permission notice shall be included in 00016 * all copies or substantial portions of the Software. 00017 * 00018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00019 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00020 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00021 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00022 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00023 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00024 * THE SOFTWARE. 00025 * 00026 * @section DESCRIPTION 00027 * 00028 * Honeywell HMC5843 digital compass. 00029 * 00030 * Datasheet: 00031 * 00032 * http://www.ssec.honeywell.com/magnetic/datasheets/HMC5843.pdf 00033 */ 00034 00035 #ifndef HMC5843_H 00036 #define HMC5843_H 00037 00038 /** 00039 * Includes 00040 */ 00041 #include "mbed.h" 00042 00043 /** 00044 * Defines 00045 */ 00046 #define HMC5843_I2C_ADDRESS 0x1E //7-bit address. 0x3C write, 0x3D read. 00047 #define HMC5843_I2C_WRITE 0x3C 00048 #define HMC5843_I2C_READ 0x3D 00049 00050 //Values Config A 00051 #define HMC5843_0_5HZ_NORMAL 0x00 00052 #define HMC5843_0_5HZ_POSITIVE 0x01 00053 #define HMC5843_0_5HZ_NEGATIVE 0x02 00054 00055 #define HMC5843_1HZ_NORMAL 0x04 00056 #define HMC5843_1HZ_POSITIVE 0x05 00057 #define HMC5843_1HZ_NEGATIVE 0x06 00058 00059 #define HMC5843_2HZ_NORMAL 0x08 00060 #define HMC5843_2HZ_POSITIVE 0x09 00061 #define HMC5843_2HZ_NEGATIVE 0x0A 00062 00063 #define HMC5843_5HZ_NORMAL 0x0C 00064 #define HMC5843_5HZ_POSITIVE 0x0D 00065 #define HMC5843_5HZ_NEGATIVE 0x0E 00066 00067 #define HMC5843_10HZ_NORMAL 0x10 00068 #define HMC5843_10HZ_POSITIVE 0x11 00069 #define HMC5843_10HZ_NEGATIVE 0x12 00070 00071 #define HMC5843_20HZ_NORMAL 0x14 00072 #define HMC5843_20HZ_POSITIVE 0x15 00073 #define HMC5843_20HZ_NEGATIVE 0x16 00074 00075 #define HMC5843_50HZ_NORMAL 0x18 00076 #define HMC5843_50HZ_POSITIVE 0x19 00077 #define HMC5843_50HZ_NEGATIVE 0x1A 00078 00079 //Values Config B 00080 #define HMC5843_0_7GA 0x00 00081 #define HMC5843_1_0GA 0x20 00082 #define HMC5843_1_5GA 0x40 00083 #define HMC5843_2_0GA 0x60 00084 #define HMC5843_3_2GA 0x80 00085 #define HMC5843_3_8GA 0xA0 00086 #define HMC5843_4_5GA 0xC0 00087 #define HMC5843_6_5GA 0xE0 00088 00089 //Values MODE 00090 #define HMC5843_CONTINUOUS 0x00 00091 #define HMC5843_SINGLE 0x01 00092 #define HMC5843_IDLE 0x02 00093 #define HMC5843_SLEEP 0x03 00094 00095 00096 00097 #define HMC5843_CONFIG_A 0x00 00098 #define HMC5843_CONFIG_B 0x01 00099 #define HMC5843_MODE 0x02 00100 #define HMC5843_X_MSB 0x03 00101 #define HMC5843_X_LSB 0x04 00102 #define HMC5843_Y_MSB 0x05 00103 #define HMC5843_Y_LSB 0x06 00104 #define HMC5843_Z_MSB 0x07 00105 #define HMC5843_Z_LSB 0x08 00106 #define HMC5843_STATUS 0x09 00107 #define HMC5843_IDENT_A 0x0A 00108 #define HMC5843_IDENT_B 0x0B 00109 #define HMC5843_IDENT_C 0x0C 00110 00111 00112 00113 /** 00114 * Honeywell HMC5843 digital compass. 00115 */ 00116 class HMC5843 { 00117 00118 public: 00119 00120 /** 00121 * Constructor. 00122 * 00123 * @param sda mbed pin to use for SDA line of I2C interface. 00124 * @param scl mbed pin to use for SCL line of I2C interface. 00125 */ 00126 HMC5843(PinName sda, PinName scl); 00127 00128 00129 /** 00130 * Enter into sleep mode. 00131 * 00132 */ 00133 void setSleepMode(); 00134 00135 00136 /** 00137 * Set Device in Default Mode. 00138 * HMC5843_CONTINUOUS, HMC5843_10HZ_NORMAL HMC5843_1_0GA 00139 */ 00140 void setDefault(); 00141 00142 00143 00144 /** 00145 * Perform Self Test. 00146 * 00147 */ 00148 // void SelfTest(); 00149 00150 00151 /** 00152 * Read the memory location on the device which contains the address. 00153 * 00154 * @param Pointer to a buffer to hold the address value 00155 * Expected H, 4 and 3. 00156 */ 00157 void getAddress(char * address); 00158 00159 00160 00161 /** 00162 * Set the operation mode. 00163 * 00164 * @param mode 0x00 -> Continuous 00165 * 0x01 -> Single 00166 * 0x02 -> Idle 00167 * @param ConfigA values 00168 * @param ConfigB values 00169 */ 00170 void setOpMode(int mode, int ConfigA, int ConfigB); 00171 00172 /** 00173 * Write to on the device. 00174 * 00175 * @param address Address to write to. 00176 * @param data Data to write. 00177 */ 00178 void write(int address, int data); 00179 00180 /* Get the output of all three axes. 00181 * 00182 * @param Pointer to a buffer to hold the magnetics value for the 00183 * x-axis, y-axis and z-axis [in that order]. 00184 */ 00185 void readData(int* readings); 00186 00187 /* Get the current operation mode. 00188 * 00189 * @return Staus register values 00190 */ 00191 int getStatus(void); 00192 00193 00194 00195 I2C* i2c_; 00196 00197 00198 00199 }; 00200 00201 #endif /* HMC5843_H */
Generated on Tue Aug 23 2022 08:55:47 by 1.7.2