Port from Avnet's Internet Of Things full WiGo demo: SmartConfig - WebServer - Exosite - Android sensor Fusion App

Dependencies:   NVIC_set_all_priorities mbed cc3000_hostdriver_mbedsocket TEMT6200 TSI Wi-Go_eCompass_Lib_V3 WiGo_BattCharger

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MAG3110.h Source File

MAG3110.h

00001 /* Copyright (c) 2010-2011 mbed.org, MIT License
00002 *
00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00004 * and associated documentation files (the "Software"), to deal in the Software without
00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
00007 * Software is furnished to do so, subject to the following conditions:
00008 *
00009 * The above copyright notice and this permission notice shall be included in all copies or
00010 * substantial portions of the Software.
00011 *
00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00017 */
00018  
00019 #ifndef MAG3110_H
00020 #define MAG3110_H
00021 
00022 #include "mbed.h"
00023 
00024 // define registers
00025 #define MAG_DR_STATUS 0x00
00026 #define MAG_OUT_X_MSB 0x01
00027 #define MAG_OUT_X_LSB 0x02
00028 #define MAG_OUT_Y_MSB 0x03
00029 #define MAG_OUT_Y_LSB 0x04
00030 #define MAG_OUT_Z_MSB 0x05
00031 #define MAG_OUT_Z_LSB 0x06
00032 #define MAG_WHO_AM_I  0x07
00033 #define MAG_SYSMOD    0x08
00034 #define MAG_OFF_X_MSB 0x09
00035 #define MAG_OFF_X_LSB 0x0A
00036 #define MAG_OFF_Y_MSB 0x0B
00037 #define MAG_OFF_Y_LSB 0x0C
00038 #define MAG_OFF_Z_MSB 0x0D
00039 #define MAG_OFF_Z_LSB 0x0E
00040 #define MAG_DIE_TEMP  0x0F
00041 #define MAG_CTRL_REG1 0x10
00042 #define MAG_CTRL_REG2 0x11
00043 
00044 // Fields in registers
00045 // CTRL_REG1: dr2,dr1,dr0  os1,os0  fr tm ac
00046 
00047 // Sampling rate from 80Hz down to 0.625Hz
00048 #define MAG_3110_SAMPLE80 0
00049 #define MAG_3110_SAMPLE40 0x20
00050 #define MAG_3110_SAMPLE20 0x40
00051 #define MAG_3110_SAMPLE10 0x60
00052 #define MAG_3110_SAMPLE5 0x80
00053 #define MAG_3110_SAMPLE2_5 0xA0
00054 #define MAG_3110_SAMPLE1_25 0xC0
00055 #define MAG_3110_SAMPLE0_625 0xE0
00056 
00057 // How many samples to average (lowers data rate)
00058 #define MAG_3110_OVERSAMPLE1 0
00059 #define MAG_3110_OVERSAMPLE2 0x08
00060 #define MAG_3110_OVERSAMPLE3 0x10
00061 #define MAG_3110_OVERSAMPLE4 0x18
00062 
00063 // read only 1 byte per axis
00064 #define MAG_3110_FASTREAD 0x04
00065 // do one measurement (even if in standby mode)
00066 #define MAG_3110_TRIGGER 0x02
00067 // put in active mode
00068 #define MAG_3110_ACTIVE 0x01
00069 
00070 // CTRL_REG2: AUTO_MRST_EN  _ RAW MAG_RST _ _ _ _ _
00071 // reset sensor after each reading
00072 #define MAG_3110_AUTO_MRST_EN 0x80
00073 // don't subtract user offsets
00074 #define MAG_3110_RAW 0x20
00075 // reset magnetic sensor after too-large field
00076 #define MAG_3110_MAG_RST 0x10
00077 
00078 // DR_STATUS Register ZYXOW ZOW YOW XOW ZYXDR ZDR YDR XDR
00079 #define MAG_3110_ZYXDR  0x08
00080 
00081 /**
00082  * MAG3110 Class to read X/Y/Z data from the magnetometer
00083  *
00084  */
00085 class MAG3110
00086 {
00087 public:
00088     /**
00089      * Main constructor
00090      * @param sda SDA pin
00091      * @param sdl SCL pin
00092      * @param addr addr of the I2C peripheral
00093      */
00094     MAG3110(PinName sda, PinName scl, int addr);
00095 
00096     uint8_t isDataAvailable(void);
00097     void readXYZ(uint8_t * data);
00098     uint8_t readReg(uint8_t addr);
00099     void writeRegs(uint8_t * data, int len);
00100 
00101 private:
00102     I2C m_i2c;
00103     int m_addr;
00104 };
00105 #endif