Private HMC5843 library
HMC5843.h@0:63ccd7376105, 2011-01-07 (annotated)
- Committer:
- atommota
- Date:
- Fri Jan 07 19:12:42 2011 +0000
- Revision:
- 0:63ccd7376105
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
atommota | 0:63ccd7376105 | 1 | /** |
atommota | 0:63ccd7376105 | 2 | * @author Jose R. Padron |
atommota | 0:63ccd7376105 | 3 | *@author Used HMC5843 library developed by Aaron Berk as template |
atommota | 0:63ccd7376105 | 4 | * @section LICENSE |
atommota | 0:63ccd7376105 | 5 | * |
atommota | 0:63ccd7376105 | 6 | * Copyright (c) 2010 ARM Limited |
atommota | 0:63ccd7376105 | 7 | * |
atommota | 0:63ccd7376105 | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
atommota | 0:63ccd7376105 | 9 | * of this software and associated documentation files (the "Software"), to deal |
atommota | 0:63ccd7376105 | 10 | * in the Software without restriction, including without limitation the rights |
atommota | 0:63ccd7376105 | 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
atommota | 0:63ccd7376105 | 12 | * copies of the Software, and to permit persons to whom the Software is |
atommota | 0:63ccd7376105 | 13 | * furnished to do so, subject to the following conditions: |
atommota | 0:63ccd7376105 | 14 | * |
atommota | 0:63ccd7376105 | 15 | * The above copyright notice and this permission notice shall be included in |
atommota | 0:63ccd7376105 | 16 | * all copies or substantial portions of the Software. |
atommota | 0:63ccd7376105 | 17 | * |
atommota | 0:63ccd7376105 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
atommota | 0:63ccd7376105 | 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
atommota | 0:63ccd7376105 | 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
atommota | 0:63ccd7376105 | 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
atommota | 0:63ccd7376105 | 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
atommota | 0:63ccd7376105 | 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
atommota | 0:63ccd7376105 | 24 | * THE SOFTWARE. |
atommota | 0:63ccd7376105 | 25 | * |
atommota | 0:63ccd7376105 | 26 | * @section DESCRIPTION |
atommota | 0:63ccd7376105 | 27 | * |
atommota | 0:63ccd7376105 | 28 | * Honeywell HMC5843 digital compass. |
atommota | 0:63ccd7376105 | 29 | * |
atommota | 0:63ccd7376105 | 30 | * Datasheet: |
atommota | 0:63ccd7376105 | 31 | * |
atommota | 0:63ccd7376105 | 32 | * http://www.ssec.honeywell.com/magnetic/datasheets/HMC5843.pdf |
atommota | 0:63ccd7376105 | 33 | */ |
atommota | 0:63ccd7376105 | 34 | |
atommota | 0:63ccd7376105 | 35 | #ifndef HMC5843_H |
atommota | 0:63ccd7376105 | 36 | #define HMC5843_H |
atommota | 0:63ccd7376105 | 37 | |
atommota | 0:63ccd7376105 | 38 | /** |
atommota | 0:63ccd7376105 | 39 | * Includes |
atommota | 0:63ccd7376105 | 40 | */ |
atommota | 0:63ccd7376105 | 41 | #include "mbed.h" |
atommota | 0:63ccd7376105 | 42 | |
atommota | 0:63ccd7376105 | 43 | /** |
atommota | 0:63ccd7376105 | 44 | * Defines |
atommota | 0:63ccd7376105 | 45 | */ |
atommota | 0:63ccd7376105 | 46 | #define HMC5843_I2C_ADDRESS 0x1E //7-bit address. 0x3C write, 0x3D read. |
atommota | 0:63ccd7376105 | 47 | #define HMC5843_I2C_WRITE 0x3C |
atommota | 0:63ccd7376105 | 48 | #define HMC5843_I2C_READ 0x3D |
atommota | 0:63ccd7376105 | 49 | |
atommota | 0:63ccd7376105 | 50 | //Values Config A |
atommota | 0:63ccd7376105 | 51 | #define HMC5843_0_5HZ_NORMAL 0x00 |
atommota | 0:63ccd7376105 | 52 | #define HMC5843_0_5HZ_POSITIVE 0x01 |
atommota | 0:63ccd7376105 | 53 | #define HMC5843_0_5HZ_NEGATIVE 0x02 |
atommota | 0:63ccd7376105 | 54 | |
atommota | 0:63ccd7376105 | 55 | #define HMC5843_1HZ_NORMAL 0x04 |
atommota | 0:63ccd7376105 | 56 | #define HMC5843_1HZ_POSITIVE 0x05 |
atommota | 0:63ccd7376105 | 57 | #define HMC5843_1HZ_NEGATIVE 0x06 |
atommota | 0:63ccd7376105 | 58 | |
atommota | 0:63ccd7376105 | 59 | #define HMC5843_2HZ_NORMAL 0x08 |
atommota | 0:63ccd7376105 | 60 | #define HMC5843_2HZ_POSITIVE 0x09 |
atommota | 0:63ccd7376105 | 61 | #define HMC5843_2HZ_NEGATIVE 0x0A |
atommota | 0:63ccd7376105 | 62 | |
atommota | 0:63ccd7376105 | 63 | #define HMC5843_5HZ_NORMAL 0x0C |
atommota | 0:63ccd7376105 | 64 | #define HMC5843_5HZ_POSITIVE 0x0D |
atommota | 0:63ccd7376105 | 65 | #define HMC5843_5HZ_NEGATIVE 0x0E |
atommota | 0:63ccd7376105 | 66 | |
atommota | 0:63ccd7376105 | 67 | #define HMC5843_10HZ_NORMAL 0x10 |
atommota | 0:63ccd7376105 | 68 | #define HMC5843_10HZ_POSITIVE 0x11 |
atommota | 0:63ccd7376105 | 69 | #define HMC5843_10HZ_NEGATIVE 0x12 |
atommota | 0:63ccd7376105 | 70 | |
atommota | 0:63ccd7376105 | 71 | #define HMC5843_20HZ_NORMAL 0x14 |
atommota | 0:63ccd7376105 | 72 | #define HMC5843_20HZ_POSITIVE 0x15 |
atommota | 0:63ccd7376105 | 73 | #define HMC5843_20HZ_NEGATIVE 0x16 |
atommota | 0:63ccd7376105 | 74 | |
atommota | 0:63ccd7376105 | 75 | #define HMC5843_50HZ_NORMAL 0x18 |
atommota | 0:63ccd7376105 | 76 | #define HMC5843_50HZ_POSITIVE 0x19 |
atommota | 0:63ccd7376105 | 77 | #define HMC5843_50HZ_NEGATIVE 0x1A |
atommota | 0:63ccd7376105 | 78 | |
atommota | 0:63ccd7376105 | 79 | //Values Config B |
atommota | 0:63ccd7376105 | 80 | #define HMC5843_0_7GA 0x00 |
atommota | 0:63ccd7376105 | 81 | #define HMC5843_1_0GA 0x20 |
atommota | 0:63ccd7376105 | 82 | #define HMC5843_1_5GA 0x40 |
atommota | 0:63ccd7376105 | 83 | #define HMC5843_2_0GA 0x60 |
atommota | 0:63ccd7376105 | 84 | #define HMC5843_3_2GA 0x80 |
atommota | 0:63ccd7376105 | 85 | #define HMC5843_3_8GA 0xA0 |
atommota | 0:63ccd7376105 | 86 | #define HMC5843_4_5GA 0xC0 |
atommota | 0:63ccd7376105 | 87 | #define HMC5843_6_5GA 0xE0 |
atommota | 0:63ccd7376105 | 88 | |
atommota | 0:63ccd7376105 | 89 | //Values MODE |
atommota | 0:63ccd7376105 | 90 | #define HMC5843_CONTINUOUS 0x00 |
atommota | 0:63ccd7376105 | 91 | #define HMC5843_SINGLE 0x01 |
atommota | 0:63ccd7376105 | 92 | #define HMC5843_IDLE 0x02 |
atommota | 0:63ccd7376105 | 93 | #define HMC5843_SLEEP 0x03 |
atommota | 0:63ccd7376105 | 94 | |
atommota | 0:63ccd7376105 | 95 | |
atommota | 0:63ccd7376105 | 96 | |
atommota | 0:63ccd7376105 | 97 | #define HMC5843_CONFIG_A 0x00 |
atommota | 0:63ccd7376105 | 98 | #define HMC5843_CONFIG_B 0x01 |
atommota | 0:63ccd7376105 | 99 | #define HMC5843_MODE 0x02 |
atommota | 0:63ccd7376105 | 100 | #define HMC5843_X_MSB 0x03 |
atommota | 0:63ccd7376105 | 101 | #define HMC5843_X_LSB 0x04 |
atommota | 0:63ccd7376105 | 102 | #define HMC5843_Y_MSB 0x05 |
atommota | 0:63ccd7376105 | 103 | #define HMC5843_Y_LSB 0x06 |
atommota | 0:63ccd7376105 | 104 | #define HMC5843_Z_MSB 0x07 |
atommota | 0:63ccd7376105 | 105 | #define HMC5843_Z_LSB 0x08 |
atommota | 0:63ccd7376105 | 106 | #define HMC5843_STATUS 0x09 |
atommota | 0:63ccd7376105 | 107 | #define HMC5843_IDENT_A 0x0A |
atommota | 0:63ccd7376105 | 108 | #define HMC5843_IDENT_B 0x0B |
atommota | 0:63ccd7376105 | 109 | #define HMC5843_IDENT_C 0x0C |
atommota | 0:63ccd7376105 | 110 | |
atommota | 0:63ccd7376105 | 111 | |
atommota | 0:63ccd7376105 | 112 | |
atommota | 0:63ccd7376105 | 113 | /** |
atommota | 0:63ccd7376105 | 114 | * Honeywell HMC5843 digital compass. |
atommota | 0:63ccd7376105 | 115 | */ |
atommota | 0:63ccd7376105 | 116 | class HMC5843 { |
atommota | 0:63ccd7376105 | 117 | |
atommota | 0:63ccd7376105 | 118 | public: |
atommota | 0:63ccd7376105 | 119 | |
atommota | 0:63ccd7376105 | 120 | /** |
atommota | 0:63ccd7376105 | 121 | * Constructor. |
atommota | 0:63ccd7376105 | 122 | * |
atommota | 0:63ccd7376105 | 123 | * @param sda mbed pin to use for SDA line of I2C interface. |
atommota | 0:63ccd7376105 | 124 | * @param scl mbed pin to use for SCL line of I2C interface. |
atommota | 0:63ccd7376105 | 125 | */ |
atommota | 0:63ccd7376105 | 126 | HMC5843(PinName sda, PinName scl); |
atommota | 0:63ccd7376105 | 127 | |
atommota | 0:63ccd7376105 | 128 | |
atommota | 0:63ccd7376105 | 129 | /** |
atommota | 0:63ccd7376105 | 130 | * Enter into sleep mode. |
atommota | 0:63ccd7376105 | 131 | * |
atommota | 0:63ccd7376105 | 132 | */ |
atommota | 0:63ccd7376105 | 133 | void setSleepMode(); |
atommota | 0:63ccd7376105 | 134 | |
atommota | 0:63ccd7376105 | 135 | |
atommota | 0:63ccd7376105 | 136 | /** |
atommota | 0:63ccd7376105 | 137 | * Set Device in Default Mode. |
atommota | 0:63ccd7376105 | 138 | * HMC5843_CONTINUOUS, HMC5843_10HZ_NORMAL HMC5843_1_0GA |
atommota | 0:63ccd7376105 | 139 | */ |
atommota | 0:63ccd7376105 | 140 | void setDefault(); |
atommota | 0:63ccd7376105 | 141 | |
atommota | 0:63ccd7376105 | 142 | |
atommota | 0:63ccd7376105 | 143 | |
atommota | 0:63ccd7376105 | 144 | /** |
atommota | 0:63ccd7376105 | 145 | * Perform Self Test. |
atommota | 0:63ccd7376105 | 146 | * |
atommota | 0:63ccd7376105 | 147 | */ |
atommota | 0:63ccd7376105 | 148 | // void SelfTest(); |
atommota | 0:63ccd7376105 | 149 | |
atommota | 0:63ccd7376105 | 150 | |
atommota | 0:63ccd7376105 | 151 | /** |
atommota | 0:63ccd7376105 | 152 | * Read the memory location on the device which contains the address. |
atommota | 0:63ccd7376105 | 153 | * |
atommota | 0:63ccd7376105 | 154 | * @param Pointer to a buffer to hold the address value |
atommota | 0:63ccd7376105 | 155 | * Expected H, 4 and 3. |
atommota | 0:63ccd7376105 | 156 | */ |
atommota | 0:63ccd7376105 | 157 | void getAddress(char * address); |
atommota | 0:63ccd7376105 | 158 | |
atommota | 0:63ccd7376105 | 159 | |
atommota | 0:63ccd7376105 | 160 | |
atommota | 0:63ccd7376105 | 161 | /** |
atommota | 0:63ccd7376105 | 162 | * Set the operation mode. |
atommota | 0:63ccd7376105 | 163 | * |
atommota | 0:63ccd7376105 | 164 | * @param mode 0x00 -> Continuous |
atommota | 0:63ccd7376105 | 165 | * 0x01 -> Single |
atommota | 0:63ccd7376105 | 166 | * 0x02 -> Idle |
atommota | 0:63ccd7376105 | 167 | * @param ConfigA values |
atommota | 0:63ccd7376105 | 168 | * @param ConfigB values |
atommota | 0:63ccd7376105 | 169 | */ |
atommota | 0:63ccd7376105 | 170 | void setOpMode(int mode, int ConfigA, int ConfigB); |
atommota | 0:63ccd7376105 | 171 | |
atommota | 0:63ccd7376105 | 172 | /** |
atommota | 0:63ccd7376105 | 173 | * Write to on the device. |
atommota | 0:63ccd7376105 | 174 | * |
atommota | 0:63ccd7376105 | 175 | * @param address Address to write to. |
atommota | 0:63ccd7376105 | 176 | * @param data Data to write. |
atommota | 0:63ccd7376105 | 177 | */ |
atommota | 0:63ccd7376105 | 178 | void write(int address, int data); |
atommota | 0:63ccd7376105 | 179 | |
atommota | 0:63ccd7376105 | 180 | /* Get the output of all three axes. |
atommota | 0:63ccd7376105 | 181 | * |
atommota | 0:63ccd7376105 | 182 | * @param Pointer to a buffer to hold the magnetics value for the |
atommota | 0:63ccd7376105 | 183 | * x-axis, y-axis and z-axis [in that order]. |
atommota | 0:63ccd7376105 | 184 | */ |
atommota | 0:63ccd7376105 | 185 | void readData(int* readings); |
atommota | 0:63ccd7376105 | 186 | |
atommota | 0:63ccd7376105 | 187 | /* Get the current operation mode. |
atommota | 0:63ccd7376105 | 188 | * |
atommota | 0:63ccd7376105 | 189 | * @return Staus register values |
atommota | 0:63ccd7376105 | 190 | */ |
atommota | 0:63ccd7376105 | 191 | int getStatus(void); |
atommota | 0:63ccd7376105 | 192 | |
atommota | 0:63ccd7376105 | 193 | |
atommota | 0:63ccd7376105 | 194 | |
atommota | 0:63ccd7376105 | 195 | I2C* i2c_; |
atommota | 0:63ccd7376105 | 196 | |
atommota | 0:63ccd7376105 | 197 | |
atommota | 0:63ccd7376105 | 198 | |
atommota | 0:63ccd7376105 | 199 | }; |
atommota | 0:63ccd7376105 | 200 | |
atommota | 0:63ccd7376105 | 201 | #endif /* HMC5843_H */ |