HMC5843 Digital Compass

HMC5843

The HMC5843 is a 3-axis digital compass with an I2C interface.

Hello World!

Import program

00001 #include "HMC5843.h"
00002  
00003 HMC5843 compass(p28, p27);
00004 Serial pc(USBTX, USBRX);
00005 
00006 //Magnetics values x,y,z
00007 int readings[3];
00008 
00009 //ID Buffer
00010 char buffer[3];
00011 
00012  
00013 int main() {
00014 
00015      pc.printf("Starting HMC5843 test...%c%c",13,10);
00016      
00017      //ID should be H43
00018      compass.getAddress(buffer);
00019      pc.printf("Magnetic Compass  Id=%c%c%c \n\r",buffer[0],buffer[1],buffer[2]);
00020      
00021     //Continuous mode, , 10Hz measurement rate.
00022     // HMC5843_CONTINUOUS, HMC5843_10HZ_NORMAL HMC5843_1_0GA
00023      compass.setDefault();
00024      
00025      //Wait some time(Need at least 5ms)
00026      wait(.1);
00027      
00028         
00029      while(1){
00030     
00031     
00032         compass.readData(readings);
00033     
00034         pc.printf("Magnetic Values  Mx=%i, My=%i and Mz=%i %c%c",(int16_t)readings[0],(int16_t)readings[1],(int16_t)readings[2] ,13,10);
00035        
00036          wait(0.1);   
00037          
00038      
00039  
00040      }
00041  
00042 }
HMC6352 Signal Namembed pin
VccVout
GndGnd
SCLp27
SDAp28

Library

Import library

Public Member Functions

  HMC5843 (PinName sda, PinName scl)
  Constructor.
void  setSleepMode ()
  Enter into sleep mode.
void  setDefault ()
  Set Device in Default Mode.
void  getAddress (char *address)
  Read the memory location on the device which contains the address.
void  setOpMode (int mode, int ConfigA, int ConfigB)
  Set the operation mode.
void  write (int address, int data)
  Write to on the device.
void  readData (int *readings)
  Get the output of all three axes.
int  getMx ()
  Get the output of X axis.
int  getMy ()
  Get the output of Y axis.
int  getMz ()
  Get the output of Z axis.
int  getStatus (void)
  Get the current operation mode.

Reference


Discussion topics

Nothing here yet!

Questions

Nothing here yet!