ok
Fork of HMC5843 by
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 00048 #define HMC5843_I2C_WRITE 0x3C 00049 #define HMC5843_I2C_READ 0x3D 00050 00051 //Values Config A 00052 #define HMC5843_0_5HZ_NORMAL 0x00 00053 #define HMC5843_0_5HZ_POSITIVE 0x01 00054 #define HMC5843_0_5HZ_NEGATIVE 0x02 00055 00056 #define HMC5843_1HZ_NORMAL 0x04 00057 #define HMC5843_1HZ_POSITIVE 0x05 00058 #define HMC5843_1HZ_NEGATIVE 0x06 00059 00060 #define HMC5843_2HZ_NORMAL 0x08 00061 #define HMC5843_2HZ_POSITIVE 0x09 00062 #define HMC5843_2HZ_NEGATIVE 0x0A 00063 00064 #define HMC5843_5HZ_NORMAL 0x0C 00065 #define HMC5843_5HZ_POSITIVE 0x0D 00066 #define HMC5843_5HZ_NEGATIVE 0x0E 00067 00068 #define HMC5843_10HZ_NORMAL 0x10 00069 #define HMC5843_10HZ_POSITIVE 0x11 00070 #define HMC5843_10HZ_NEGATIVE 0x12 00071 00072 #define HMC5843_20HZ_NORMAL 0x14 00073 #define HMC5843_20HZ_POSITIVE 0x15 00074 #define HMC5843_20HZ_NEGATIVE 0x16 00075 00076 #define HMC5843_50HZ_NORMAL 0x18 00077 #define HMC5843_50HZ_POSITIVE 0x19 00078 #define HMC5843_50HZ_NEGATIVE 0x1A 00079 00080 //Values Config B 00081 #define HMC5843_0_7GA 0x00 00082 #define HMC5843_1_0GA 0x20 00083 #define HMC5843_1_5GA 0x40 00084 #define HMC5843_2_0GA 0x60 00085 #define HMC5843_3_2GA 0x80 00086 #define HMC5843_3_8GA 0xA0 00087 #define HMC5843_4_5GA 0xC0 00088 #define HMC5843_6_5GA 0xE0 00089 00090 //Values MODE 00091 #define HMC5843_CONTINUOUS 0x00 00092 #define HMC5843_SINGLE 0x01 00093 #define HMC5843_IDLE 0x02 00094 #define HMC5843_SLEEP 0x03 00095 00096 00097 00098 #define HMC5843_CONFIG_A 0x00 00099 #define HMC5843_CONFIG_B 0x01 00100 #define HMC5843_MODE 0x02 00101 #define HMC5843_X_MSB 0x03 00102 #define HMC5843_X_LSB 0x04 00103 #define HMC5843_Y_MSB 0x05 00104 #define HMC5843_Y_LSB 0x06 00105 #define HMC5843_Z_MSB 0x07 00106 #define HMC5843_Z_LSB 0x08 00107 #define HMC5843_STATUS 0x09 00108 #define HMC5843_IDENT_A 0x0A 00109 #define HMC5843_IDENT_B 0x0B 00110 #define HMC5843_IDENT_C 0x0C 00111 00112 00113 00114 /** 00115 * Honeywell HMC5843 digital compass. 00116 */ 00117 class HMC5843 { 00118 00119 public: 00120 00121 /** 00122 * Constructor. 00123 * 00124 * @param sda mbed pin to use for SDA line of I2C interface. 00125 * @param scl mbed pin to use for SCL line of I2C interface. 00126 */ 00127 HMC5843(PinName sda, PinName scl); 00128 00129 00130 /** 00131 * Enter into sleep mode. 00132 * 00133 */ 00134 void setSleepMode(); 00135 00136 00137 /** 00138 * Set Device in Default Mode. 00139 * HMC5843_CONTINUOUS, HMC5843_10HZ_NORMAL HMC5843_1_0GA 00140 */ 00141 void setDefault(); 00142 00143 00144 00145 /** 00146 * Perform Self Test. 00147 * 00148 */ 00149 // void SelfTest(); 00150 00151 00152 /** 00153 * Read the memory location on the device which contains the address. 00154 * 00155 * @param Pointer to a buffer to hold the address value 00156 * Expected H, 4 and 3. 00157 */ 00158 void getAddress(char * address); 00159 00160 00161 00162 /** 00163 * Set the operation mode. 00164 * 00165 * @param mode 0x00 -> Continuous 00166 * 0x01 -> Single 00167 * 0x02 -> Idle 00168 * @param ConfigA values 00169 * @param ConfigB values 00170 */ 00171 void setOpMode(int mode, int ConfigA, int ConfigB); 00172 00173 /** 00174 * Write to on the device. 00175 * 00176 * @param address Address to write to. 00177 * @param data Data to write. 00178 */ 00179 void write(int address, int data); 00180 00181 /* Get the output of all three axes. 00182 * 00183 * @param Pointer to a buffer to hold the magnetics value for the 00184 * x-axis, y-axis and z-axis [in that order]. 00185 */ 00186 void readData(int* readings); 00187 00188 /* Get the current operation mode. 00189 * 00190 * @return Staus register values 00191 */ 00192 int getStatus(void); 00193 00194 00195 00196 I2C* i2c_; 00197 00198 00199 00200 }; 00201 00202 #endif /* HMC5843_H */
Generated on Thu Jul 14 2022 00:02:07 by 1.7.2