Add functions to get Mx, My and Mz.

Dependents:   9DOF-Stick aigamozu_program_ver2 aigamozu_program_ver2_yokokawa aigamozu_auto_ver1 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HMC5843.h Source File

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      * Read the memory location on the device which contains the address.
00145      *
00146      * @param Pointer to a buffer to hold the address value
00147      * Expected     H, 4 and 3.
00148      */
00149     void getAddress(char * address);
00150 
00151 
00152     
00153     /**
00154      * Set the operation mode.
00155      *
00156      * @param mode 0x00 -> Continuous
00157      *             0x01 -> Single
00158      *             0x02 -> Idle
00159      * @param ConfigA values
00160     * @param ConfigB values
00161      */
00162     void setOpMode(int mode, int ConfigA, int ConfigB);
00163     
00164      /**
00165      * Write to  on the device.
00166      *
00167      * @param address Address to write to.
00168      * @param data Data to write.
00169      */
00170     
00171     void write(int address, int data);
00172 
00173      /**
00174      * Get the output of all three axes.
00175      *
00176      * @param Pointer to a buffer to hold the magnetics value for the
00177      *        x-axis, y-axis and z-axis [in that order].
00178      */
00179     void readData(int* readings);
00180     
00181     /**
00182      * Get the output of X axis.
00183      *
00184      * @return x-axis magnetic value
00185      */
00186     int getMx();
00187     
00188     /**
00189      * Get the output of Y axis.
00190      *
00191      * @return y-axis magnetic value
00192      */
00193     int getMy();
00194     
00195     /**
00196      * Get the output of Z axis.
00197      *
00198      * @return z-axis magnetic value
00199      */
00200     int getMz();
00201    
00202     
00203     /**
00204      * Get the current operation mode.
00205      *
00206      * @return Status register values
00207      */
00208     int getStatus(void);
00209 
00210   
00211 
00212     I2C* i2c_;
00213 
00214    
00215 
00216 };
00217 
00218 #endif /* HMC5843_H */