hige dura
/
IMU
HMC5883L.h@11:b32b3d6be8d2, 2012-03-15 (annotated)
- Committer:
- higedura
- Date:
- Thu Mar 15 10:41:22 2012 +0000
- Revision:
- 11:b32b3d6be8d2
- Parent:
- 0:b61f317f452e
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
higedura | 0:b61f317f452e | 1 | /** |
higedura | 0:b61f317f452e | 2 | * @author Uwe Gartmann |
higedura | 0:b61f317f452e | 3 | * @author Used HMC5883L library developed by Jose R. Padron and Aaron Berk as template |
higedura | 0:b61f317f452e | 4 | * |
higedura | 0:b61f317f452e | 5 | * @section LICENSE |
higedura | 0:b61f317f452e | 6 | * |
higedura | 0:b61f317f452e | 7 | * Copyright (c) 2010 ARM Limited |
higedura | 0:b61f317f452e | 8 | * |
higedura | 0:b61f317f452e | 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
higedura | 0:b61f317f452e | 10 | * of this software and associated documentation files (the "Software"), to deal |
higedura | 0:b61f317f452e | 11 | * in the Software without restriction, including without limitation the rights |
higedura | 0:b61f317f452e | 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
higedura | 0:b61f317f452e | 13 | * copies of the Software, and to permit persons to whom the Software is |
higedura | 0:b61f317f452e | 14 | * furnished to do so, subject to the following conditions: |
higedura | 0:b61f317f452e | 15 | * |
higedura | 0:b61f317f452e | 16 | * The above copyright notice and this permission notice shall be included in |
higedura | 0:b61f317f452e | 17 | * all copies or substantial portions of the Software. |
higedura | 0:b61f317f452e | 18 | * |
higedura | 0:b61f317f452e | 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
higedura | 0:b61f317f452e | 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
higedura | 0:b61f317f452e | 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
higedura | 0:b61f317f452e | 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
higedura | 0:b61f317f452e | 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
higedura | 0:b61f317f452e | 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
higedura | 0:b61f317f452e | 25 | * THE SOFTWARE. |
higedura | 0:b61f317f452e | 26 | * |
higedura | 0:b61f317f452e | 27 | * @section DESCRIPTION |
higedura | 0:b61f317f452e | 28 | * |
higedura | 0:b61f317f452e | 29 | * Honeywell HMC5883L digital compass. |
higedura | 0:b61f317f452e | 30 | * |
higedura | 0:b61f317f452e | 31 | * Datasheet: |
higedura | 0:b61f317f452e | 32 | * |
higedura | 0:b61f317f452e | 33 | * http://www.ssec.honeywell.com/magnetic/datasheets/HMC5883L.pdf |
higedura | 0:b61f317f452e | 34 | */ |
higedura | 0:b61f317f452e | 35 | |
higedura | 0:b61f317f452e | 36 | #ifndef HMC5883L_H |
higedura | 0:b61f317f452e | 37 | #define HMC5883L_H |
higedura | 0:b61f317f452e | 38 | |
higedura | 0:b61f317f452e | 39 | /** |
higedura | 0:b61f317f452e | 40 | * Includes |
higedura | 0:b61f317f452e | 41 | */ |
higedura | 0:b61f317f452e | 42 | #include "mbed.h" |
higedura | 0:b61f317f452e | 43 | |
higedura | 0:b61f317f452e | 44 | /** |
higedura | 0:b61f317f452e | 45 | * Defines |
higedura | 0:b61f317f452e | 46 | */ |
higedura | 0:b61f317f452e | 47 | #define HMC5883L_I2C_ADDRESS 0x1E //7-bit address. 0x3C write, 0x3D read. |
higedura | 0:b61f317f452e | 48 | #define HMC5883L_I2C_WRITE 0x3C |
higedura | 0:b61f317f452e | 49 | #define HMC5883L_I2C_READ 0x3D |
higedura | 0:b61f317f452e | 50 | |
higedura | 0:b61f317f452e | 51 | //Values Config A |
higedura | 0:b61f317f452e | 52 | #define HMC5883L_0_5HZ_NORMAL 0x00 |
higedura | 0:b61f317f452e | 53 | #define HMC5883L_0_5HZ_POSITIVE 0x01 |
higedura | 0:b61f317f452e | 54 | #define HMC5883L_0_5HZ_NEGATIVE 0x02 |
higedura | 0:b61f317f452e | 55 | |
higedura | 0:b61f317f452e | 56 | #define HMC5883L_1HZ_NORMAL 0x04 |
higedura | 0:b61f317f452e | 57 | #define HMC5883L_1HZ_POSITIVE 0x05 |
higedura | 0:b61f317f452e | 58 | #define HMC5883L_1HZ_NEGATIVE 0x06 |
higedura | 0:b61f317f452e | 59 | |
higedura | 0:b61f317f452e | 60 | #define HMC5883L_2HZ_NORMAL 0x08 |
higedura | 0:b61f317f452e | 61 | #define HMC5883L_2HZ_POSITIVE 0x09 |
higedura | 0:b61f317f452e | 62 | #define HMC5883L_2HZ_NEGATIVE 0x0A |
higedura | 0:b61f317f452e | 63 | |
higedura | 0:b61f317f452e | 64 | #define HMC5883L_5HZ_NORMAL 0x0C |
higedura | 0:b61f317f452e | 65 | #define HMC5883L_5HZ_POSITIVE 0x0D |
higedura | 0:b61f317f452e | 66 | #define HMC5883L_5HZ_NEGATIVE 0x0E |
higedura | 0:b61f317f452e | 67 | |
higedura | 0:b61f317f452e | 68 | #define HMC5883L_10HZ_NORMAL 0x10 |
higedura | 0:b61f317f452e | 69 | #define HMC5883L_10HZ_POSITIVE 0x11 |
higedura | 0:b61f317f452e | 70 | #define HMC5883L_10HZ_NEGATIVE 0x12 |
higedura | 0:b61f317f452e | 71 | |
higedura | 0:b61f317f452e | 72 | #define HMC5883L_20HZ_NORMAL 0x14 |
higedura | 0:b61f317f452e | 73 | #define HMC5883L_20HZ_POSITIVE 0x15 |
higedura | 0:b61f317f452e | 74 | #define HMC5883L_20HZ_NEGATIVE 0x16 |
higedura | 0:b61f317f452e | 75 | |
higedura | 0:b61f317f452e | 76 | #define HMC5883L_50HZ_NORMAL 0x18 |
higedura | 0:b61f317f452e | 77 | #define HMC5883L_50HZ_POSITIVE 0x19 |
higedura | 0:b61f317f452e | 78 | #define HMC5883L_50HZ_NEGATIVE 0x1A |
higedura | 0:b61f317f452e | 79 | |
higedura | 0:b61f317f452e | 80 | //Values Config B |
higedura | 0:b61f317f452e | 81 | #define HMC5883L_0_7GA 0x00 |
higedura | 0:b61f317f452e | 82 | #define HMC5883L_1_0GA 0x20 |
higedura | 0:b61f317f452e | 83 | #define HMC5883L_1_5GA 0x40 |
higedura | 0:b61f317f452e | 84 | #define HMC5883L_2_0GA 0x60 |
higedura | 0:b61f317f452e | 85 | #define HMC5883L_3_2GA 0x80 |
higedura | 0:b61f317f452e | 86 | #define HMC5883L_3_8GA 0xA0 |
higedura | 0:b61f317f452e | 87 | #define HMC5883L_4_5GA 0xC0 |
higedura | 0:b61f317f452e | 88 | #define HMC5883L_6_5GA 0xE0 |
higedura | 0:b61f317f452e | 89 | |
higedura | 0:b61f317f452e | 90 | //Values MODE |
higedura | 0:b61f317f452e | 91 | #define HMC5883L_CONTINUOUS 0x00 |
higedura | 0:b61f317f452e | 92 | #define HMC5883L_SINGLE 0x01 |
higedura | 0:b61f317f452e | 93 | #define HMC5883L_IDLE 0x02 |
higedura | 0:b61f317f452e | 94 | #define HMC5883L_SLEEP 0x03 |
higedura | 0:b61f317f452e | 95 | |
higedura | 0:b61f317f452e | 96 | |
higedura | 0:b61f317f452e | 97 | |
higedura | 0:b61f317f452e | 98 | #define HMC5883L_CONFIG_A 0x00 |
higedura | 0:b61f317f452e | 99 | #define HMC5883L_CONFIG_B 0x01 |
higedura | 0:b61f317f452e | 100 | #define HMC5883L_MODE 0x02 |
higedura | 0:b61f317f452e | 101 | #define HMC5883L_X_MSB 0x03 |
higedura | 0:b61f317f452e | 102 | #define HMC5883L_X_LSB 0x04 |
higedura | 0:b61f317f452e | 103 | #define HMC5883L_Z_MSB 0x05 |
higedura | 0:b61f317f452e | 104 | #define HMC5883L_Z_LSB 0x06 |
higedura | 0:b61f317f452e | 105 | #define HMC5883L_Y_MSB 0x07 |
higedura | 0:b61f317f452e | 106 | #define HMC5883L_Y_LSB 0x08 |
higedura | 0:b61f317f452e | 107 | #define HMC5883L_STATUS 0x09 |
higedura | 0:b61f317f452e | 108 | #define HMC5883L_IDENT_A 0x0A |
higedura | 0:b61f317f452e | 109 | #define HMC5883L_IDENT_B 0x0B |
higedura | 0:b61f317f452e | 110 | #define HMC5883L_IDENT_C 0x0C |
higedura | 0:b61f317f452e | 111 | |
higedura | 0:b61f317f452e | 112 | |
higedura | 0:b61f317f452e | 113 | |
higedura | 0:b61f317f452e | 114 | /** |
higedura | 0:b61f317f452e | 115 | * Honeywell HMC5883L digital compass. |
higedura | 0:b61f317f452e | 116 | */ |
higedura | 0:b61f317f452e | 117 | class HMC5883L { |
higedura | 0:b61f317f452e | 118 | |
higedura | 0:b61f317f452e | 119 | public: |
higedura | 0:b61f317f452e | 120 | |
higedura | 0:b61f317f452e | 121 | /** |
higedura | 0:b61f317f452e | 122 | * Constructor. |
higedura | 0:b61f317f452e | 123 | * |
higedura | 0:b61f317f452e | 124 | * @param sda mbed pin to use for SDA line of I2C interface. |
higedura | 0:b61f317f452e | 125 | * @param scl mbed pin to use for SCL line of I2C interface. |
higedura | 0:b61f317f452e | 126 | */ |
higedura | 0:b61f317f452e | 127 | HMC5883L(PinName sda, PinName scl); |
higedura | 0:b61f317f452e | 128 | |
higedura | 0:b61f317f452e | 129 | |
higedura | 0:b61f317f452e | 130 | /** |
higedura | 0:b61f317f452e | 131 | * Enter into sleep mode. |
higedura | 0:b61f317f452e | 132 | * |
higedura | 0:b61f317f452e | 133 | */ |
higedura | 0:b61f317f452e | 134 | void setSleepMode(); |
higedura | 0:b61f317f452e | 135 | |
higedura | 0:b61f317f452e | 136 | |
higedura | 0:b61f317f452e | 137 | /** |
higedura | 0:b61f317f452e | 138 | * Set Device in Default Mode. |
higedura | 0:b61f317f452e | 139 | * HMC5883L_CONTINUOUS, HMC5883L_10HZ_NORMAL HMC5883L_1_0GA |
higedura | 0:b61f317f452e | 140 | */ |
higedura | 0:b61f317f452e | 141 | void setDefault(); |
higedura | 0:b61f317f452e | 142 | |
higedura | 0:b61f317f452e | 143 | |
higedura | 0:b61f317f452e | 144 | /** |
higedura | 0:b61f317f452e | 145 | * Read the memory location on the device which contains the address. |
higedura | 0:b61f317f452e | 146 | * |
higedura | 0:b61f317f452e | 147 | * @param Pointer to a buffer to hold the address value |
higedura | 0:b61f317f452e | 148 | * Expected H, 4 and 3. |
higedura | 0:b61f317f452e | 149 | */ |
higedura | 0:b61f317f452e | 150 | void getAddress(char * address); |
higedura | 0:b61f317f452e | 151 | |
higedura | 0:b61f317f452e | 152 | |
higedura | 0:b61f317f452e | 153 | |
higedura | 0:b61f317f452e | 154 | /** |
higedura | 0:b61f317f452e | 155 | * Set the operation mode. |
higedura | 0:b61f317f452e | 156 | * |
higedura | 0:b61f317f452e | 157 | * @param mode 0x00 -> Continuous |
higedura | 0:b61f317f452e | 158 | * 0x01 -> Single |
higedura | 0:b61f317f452e | 159 | * 0x02 -> Idle |
higedura | 0:b61f317f452e | 160 | * @param ConfigA values |
higedura | 0:b61f317f452e | 161 | * @param ConfigB values |
higedura | 0:b61f317f452e | 162 | */ |
higedura | 0:b61f317f452e | 163 | void setOpMode(int mode, int ConfigA, int ConfigB); |
higedura | 0:b61f317f452e | 164 | |
higedura | 0:b61f317f452e | 165 | /** |
higedura | 0:b61f317f452e | 166 | * Write to on the device. |
higedura | 0:b61f317f452e | 167 | * |
higedura | 0:b61f317f452e | 168 | * @param address Address to write to. |
higedura | 0:b61f317f452e | 169 | * @param data Data to write. |
higedura | 0:b61f317f452e | 170 | */ |
higedura | 0:b61f317f452e | 171 | |
higedura | 0:b61f317f452e | 172 | void write(int address, int data); |
higedura | 0:b61f317f452e | 173 | |
higedura | 0:b61f317f452e | 174 | /** |
higedura | 0:b61f317f452e | 175 | * Get the output of all three axes. |
higedura | 0:b61f317f452e | 176 | * |
higedura | 0:b61f317f452e | 177 | * @param Pointer to a buffer to hold the magnetics value for the |
higedura | 0:b61f317f452e | 178 | * x-axis, y-axis and z-axis [in that order]. |
higedura | 0:b61f317f452e | 179 | */ |
higedura | 0:b61f317f452e | 180 | void readData(int* getMag); |
higedura | 0:b61f317f452e | 181 | |
higedura | 0:b61f317f452e | 182 | /** |
higedura | 0:b61f317f452e | 183 | * Get the output of X axis. |
higedura | 0:b61f317f452e | 184 | * |
higedura | 0:b61f317f452e | 185 | * @return x-axis magnetic value |
higedura | 0:b61f317f452e | 186 | */ |
higedura | 0:b61f317f452e | 187 | int getMx(); |
higedura | 0:b61f317f452e | 188 | |
higedura | 0:b61f317f452e | 189 | /** |
higedura | 0:b61f317f452e | 190 | * Get the output of Y axis. |
higedura | 0:b61f317f452e | 191 | * |
higedura | 0:b61f317f452e | 192 | * @return y-axis magnetic value |
higedura | 0:b61f317f452e | 193 | */ |
higedura | 0:b61f317f452e | 194 | int getMy(); |
higedura | 0:b61f317f452e | 195 | |
higedura | 0:b61f317f452e | 196 | /** |
higedura | 0:b61f317f452e | 197 | * Get the output of Z axis. |
higedura | 0:b61f317f452e | 198 | * |
higedura | 0:b61f317f452e | 199 | * @return z-axis magnetic value |
higedura | 0:b61f317f452e | 200 | */ |
higedura | 0:b61f317f452e | 201 | int getMz(); |
higedura | 0:b61f317f452e | 202 | |
higedura | 0:b61f317f452e | 203 | |
higedura | 0:b61f317f452e | 204 | /** |
higedura | 0:b61f317f452e | 205 | * Get the current operation mode. |
higedura | 0:b61f317f452e | 206 | * |
higedura | 0:b61f317f452e | 207 | * @return Status register values |
higedura | 0:b61f317f452e | 208 | */ |
higedura | 0:b61f317f452e | 209 | int getStatus(void); |
higedura | 0:b61f317f452e | 210 | |
higedura | 0:b61f317f452e | 211 | |
higedura | 0:b61f317f452e | 212 | |
higedura | 0:b61f317f452e | 213 | I2C* i2c_; |
higedura | 0:b61f317f452e | 214 | |
higedura | 0:b61f317f452e | 215 | |
higedura | 0:b61f317f452e | 216 | |
higedura | 0:b61f317f452e | 217 | }; |
higedura | 0:b61f317f452e | 218 | |
higedura | 0:b61f317f452e | 219 | #endif /* HMC5883L_H */ |