James Watanabe / HMC5843

Fork of HMC5843 by Jose R Padron

Embed: (wiki syntax)

« Back to documentation index

HMC5843 Class Reference

Honeywell HMC5843 digital compass. More...

#include <HMC5843.h>

Public Member Functions

 HMC5843 (PinName sda, PinName scl)
 Constructor.
 HMC5843 (I2C &i2c)
 Constructor that accepts external i2c interface object.
 ~HMC5843 ()
 Destructor that frees self-allocated I2C object.
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.

Static Public Attributes

static const int I2C_ADDRESS = HMC5843_I2C_WRITE
 The I2C address that can be passed directly to i2c object (it's already shifted 1 bit left).

Protected Member Functions

int getWord (int regi)
 Reads a word (2 bytes) from the sensor via I2C bus.

Detailed Description

Honeywell HMC5843 digital compass.

Definition at line 112 of file HMC5843.h.


Constructor & Destructor Documentation

HMC5843 ( PinName  sda,
PinName  scl 
)

Constructor.

Parameters:
sdambed pin to use for SDA line of I2C interface.
sclmbed pin to use for SCL line of I2C interface.

Definition at line 39 of file HMC5843.cpp.

HMC5843 ( I2C &  i2c )

Constructor that accepts external i2c interface object.

Parameters:
i2cThe I2C interface object to use.

Definition at line 137 of file HMC5843.h.

~HMC5843 (  )

Destructor that frees self-allocated I2C object.

Definition at line 142 of file HMC5843.h.


Member Function Documentation

void getAddress ( char *  address )

Read the memory location on the device which contains the address.

Parameters:
Pointerto a buffer to hold the address value Expected H, 4 and 3.

Definition at line 76 of file HMC5843.cpp.

int getMx (  )

Get the output of X axis.

Returns:
x-axis magnetic value

Definition at line 204 of file HMC5843.h.

int getMy (  )

Get the output of Y axis.

Returns:
y-axis magnetic value

Definition at line 211 of file HMC5843.h.

int getMz (  )

Get the output of Z axis.

Returns:
z-axis magnetic value

Definition at line 218 of file HMC5843.h.

int getStatus ( void   )

Get the current operation mode.

Returns:
Status register values
int getWord ( int  regi ) [protected]

Reads a word (2 bytes) from the sensor via I2C bus.

The queried value is assumed big-endian, 2's complement value.

This protected function is added because we shouldn't write getMx(), getMy() and getMz() independently, but collect common codes.

Parameters:
regiRegister address to be read.

Definition at line 123 of file HMC5843.cpp.

void readData ( int *  readings )

Get the output of all three axes.

Parameters:
Pointerto a buffer to hold the magnetics value for the x-axis, y-axis and z-axis [in that order].

Definition at line 109 of file HMC5843.cpp.

void setDefault ( void   )

Set Device in Default Mode.

HMC5843_CONTINUOUS, HMC5843_10HZ_NORMAL HMC5843_1_0GA

Definition at line 67 of file HMC5843.cpp.

void setOpMode ( int  mode,
int  ConfigA,
int  ConfigB 
)

Set the operation mode.

Parameters:
mode0x00 -> Continuous 0x01 -> Single 0x02 -> Idle
ConfigAvalues
ConfigBvalues

Definition at line 96 of file HMC5843.cpp.

void setSleepMode (  )

Enter into sleep mode.

Definition at line 62 of file HMC5843.cpp.

void write ( int  address,
int  data 
)

Write to on the device.

Parameters:
addressAddress to write to.
dataData to write.

Definition at line 48 of file HMC5843.cpp.


Field Documentation

const int I2C_ADDRESS = HMC5843_I2C_WRITE [static]

The I2C address that can be passed directly to i2c object (it's already shifted 1 bit left).

You don't need to manually set or clear the LSB when calling I2C::read() or I2C::write(), the library takes care of it. We just always clear the LSB.

Definition at line 122 of file HMC5843.h.