COSA
An Object-Oriented Platform for Arduino Programming
HMC5883L Class Reference

#include <HMC5883L.hh>

Inheritance diagram for HMC5883L:
Inheritance graph
Collaboration diagram for HMC5883L:
Collaboration graph

Classes

struct  config_t
 
struct  data_t
 
struct  status_t
 

Public Types

enum  Bias { NORMAL_BIAS = 0x00, POSITIVE_BIAS = 0x01, NEGATIVE_BIAS = 0x02 }
 
enum  Rate {
  OUTPUT_RATE_0_75_HZ, OUTPUT_RATE_1_5_HZ, OUTPUT_RATE_3_HZ, OUTPUT_RATE_7_5_HZ,
  OUTPUT_RATE_15_HZ, OUTPUT_RATE_30_HZ, OUTPUT_RATE_75_HZ
}
 
enum  Avg { SAMPLES_AVG_1, SAMPLES_AVG_2, SAMPLES_AVG_4, SAMPLES_AVG_8 }
 
enum  Range {
  RANGE_0_88_GA, RANGE_1_3_GA, RANGE_1_9_GA, RANGE_2_5_GA,
  RANGE_4_0_GA, RANGE_4_7_GA, RANGE_5_6_GA, RANGE_8_1_GA
}
 
enum  Mode { CONTINOUS_MEASUREMENT_MODE, SINGLE_MEASUREMENT_MODE, IDLE_MEASUREMENT_MODE }
 

Public Member Functions

 HMC5883L (uint8_t mode=SLEEP_MODE_IDLE)
 
bool begin ()
 
bool end ()
 
void await_mode (uint8_t mode)
 
void bias (Bias bias)
 
void output_rate (Rate rate)
 
void samples_avg (Avg avg)
 
void range (Range range)
 
bool write_config ()
 
void heading (data_t &data) const
 
bool mode (Mode mode)
 
bool read_status (status_t &status)
 
bool available ()
 
bool sample_heading_request ()
 
void await ()
 
bool read_heading ()
 
bool read_heading (data_t &data)
 
bool is_overflow () const
 
void to_milli_gauss ()
 
bool is_async () const
 
void sync_request ()
 
void async_request ()
 
virtual void on_completion (uint8_t type, int count)
 

Protected Types

enum  Register {
  CONFIG = 0x00, MODE = 0x02, OUTPUT = 0x03, STATUS = 0x09,
  IDENTITY = 0x0a
}
 

Protected Attributes

config_t m_config
 
uint8_t m_mode
 
bool m_overflow
 
data_t m_output
 
uint8_t m_addr
 
bool m_async
 

Static Protected Attributes

static const uint16_t s_gain []
 

Detailed Description

Driver for the HMC5883L 3-Axis Digital Compass IC, a vector magnetometer.

Circuit

The GY-80 10DOF module with pull-up resistors (4K7) for TWI signals and 3V3 internal voltage converter.

GY-80
+------------+
(VCC)---------------1-|VCC |
2-|3V3 |
(GND)---------------3-|GND |
(A5/SCL)------------4-|SCL |
(A4/SDA)------------5-|SDA |
6-|M-DRDY |
7-|A-INT1 |
8-|T-INT1 |
9-|P-XCLR |
10-|P-EOC |
+------------+

References

  1. Honeywell product description (Rev. E, February 2013). http://www51.honeywell.com/aero/common/documents/ myaerospacecatalog-documents/Defense_Brochures-documents/ HMC5883L_3-Axis_Digital_Compass_IC.pdf

Definition at line 57 of file HMC5883L.hh.

Member Enumeration Documentation

Enumerator
SAMPLES_AVG_1 

Number of averaged samples per output.

SAMPLES_AVG_2 
SAMPLES_AVG_4 
SAMPLES_AVG_8 

Definition at line 78 of file HMC5883L.hh.

Configuration Register A (pp. 12).

Enumerator
NORMAL_BIAS 

Table 6: Measurement Modes.

POSITIVE_BIAS 
NEGATIVE_BIAS 

Definition at line 62 of file HMC5883L.hh.

Mode Register (pp. 14).

Enumerator
CONTINOUS_MEASUREMENT_MODE 
SINGLE_MEASUREMENT_MODE 
IDLE_MEASUREMENT_MODE 

Definition at line 102 of file HMC5883L.hh.

Configuration Register B (pp. 13)

Enumerator
RANGE_0_88_GA 

Table 9: Gain Setting.

RANGE_1_3_GA 
RANGE_1_9_GA 
RANGE_2_5_GA 
RANGE_4_0_GA 
RANGE_4_7_GA 
RANGE_5_6_GA 
RANGE_8_1_GA 

Definition at line 88 of file HMC5883L.hh.

Enumerator
OUTPUT_RATE_0_75_HZ 

Table 5: Data Output Rates.

OUTPUT_RATE_1_5_HZ 
OUTPUT_RATE_3_HZ 
OUTPUT_RATE_7_5_HZ 
OUTPUT_RATE_15_HZ 
OUTPUT_RATE_30_HZ 
OUTPUT_RATE_75_HZ 

Definition at line 68 of file HMC5883L.hh.

enum HMC5883L::Register
protected

Register List (Table 2, pp 11).

Enumerator
CONFIG 

Configuration register A, B.

MODE 

Mode register.

OUTPUT 

Output data register X, Y, Z.

STATUS 

Status register.

IDENTITY 

Identity register(0-2).

Definition at line 323 of file HMC5883L.hh.

Constructor & Destructor Documentation

HMC5883L::HMC5883L ( uint8_t  mode = SLEEP_MODE_IDLE)
inline

Construct HMC5883L device with bus address(0x1e) (pp. 11).

Definition at line 140 of file HMC5883L.hh.

Member Function Documentation

void TWI::Driver::async_request ( )
inlineinherited

Set asynchronous request mode.

Definition at line 94 of file TWI.hh.

bool HMC5883L::available ( )
inline

Return true(1) if output data is available otherwise false(0).

Returns
bool

Definition at line 254 of file HMC5883L.hh.

void HMC5883L::await ( )
inline

Wait for measurement to complete. Processor is put to sleep with the mode given by set_sleep_mode() or constructor.

Definition at line 276 of file HMC5883L.hh.

void HMC5883L::await_mode ( uint8_t  mode)
inline

Set await sleep mode.

Parameters
[in]modepower sleep mode.

Definition at line 169 of file HMC5883L.hh.

bool HMC5883L::begin ( )

Begin interaction with device. Return true(1) if successful otherwise false(0).

Returns
bool

Definition at line 35 of file HMC5883L.cpp.

void HMC5883L::bias ( Bias  bias)
inline

Set device bias pin configuration. Call write_config() after configuration changes.

Parameters
[in]biascurrent configuration.

Definition at line 179 of file HMC5883L.hh.

bool HMC5883L::end ( )
inline

End interaction with device. Put into idle mode. Return true(1) if successful otherwise false(0).

Returns
bool

Definition at line 160 of file HMC5883L.hh.

void HMC5883L::heading ( data_t data) const
inline

Get output data from device driver.

Parameters
[out]data.

Definition at line 226 of file HMC5883L.hh.

bool TWI::Driver::is_async ( ) const
inlineinherited

Return true(1) if the request is asyncrhonous otherwise false(0).

Definition at line 78 of file TWI.hh.

bool HMC5883L::is_overflow ( ) const
inline

Returns true(1) if the latest reading contained an overflow on any of the channels.

Returns
bool.

Definition at line 308 of file HMC5883L.hh.

bool HMC5883L::mode ( Mode  mode)

Set device operation mode and write mode change to device. Return true(1) if successful otherwise false(0). Must be called for each sample in SINGLE_MEASUREMENT_MODE. There is a delay before the output data becomes available from the device (rate setting). Monitor with available() or the ready pin.

Parameters
[in]modeof operation.
Returns
bool

Definition at line 62 of file HMC5883L.cpp.

virtual void TWI::Driver::on_completion ( uint8_t  type,
int  count 
)
inlinevirtualinherited

Service completion callback when a read/write has been completed.

Parameters
[in]typeevent code.
[in]countnumber of bytes in request.

Reimplemented in TWI::Slave.

Definition at line 106 of file TWI.hh.

void HMC5883L::output_rate ( Rate  rate)
inline

Set device output rates in continous measurement mode. Call write_config() after configuration changes.

Parameters
[in]rateof data output.

Definition at line 189 of file HMC5883L.hh.

void HMC5883L::range ( Range  range)
inline

Set gain configuration bits for a given recommended sensor field range. Call write_config() after configuration changes.

Parameters
[in]rangegauss.

Definition at line 209 of file HMC5883L.hh.

bool HMC5883L::read_heading ( )

Read output data from device. Return true(1) if successful otherwise false(0).

Returns
bool

Definition at line 81 of file HMC5883L.cpp.

bool HMC5883L::read_heading ( data_t data)
inline

Read output data from device. Return true(1) if successful otherwise false(0).

Parameters
[out]data.
Returns
bool

Definition at line 295 of file HMC5883L.hh.

bool HMC5883L::read_status ( status_t status)

Read status from device. Return true(1) if successful otherwise false(0).

Parameters
[out]status.
Returns
bool

Definition at line 71 of file HMC5883L.cpp.

bool HMC5883L::sample_heading_request ( )
inline

Issue single measurement. Return true(1) if successful otherwise false(0).

Returns
bool

Definition at line 267 of file HMC5883L.hh.

void HMC5883L::samples_avg ( Avg  avg)
inline

Set number of samples averaged per measurement output. Call write_config() after configuration changes.

Parameters
[in]avgnumber of samples.

Definition at line 199 of file HMC5883L.hh.

void TWI::Driver::sync_request ( )
inlineinherited

Set synchronous request mode.

Definition at line 86 of file TWI.hh.

void HMC5883L::to_milli_gauss ( )

Convert the latest reading to milli-gauss using the current gain setting and the gain table.

Definition at line 102 of file HMC5883L.cpp.

bool HMC5883L::write_config ( )

Write configuration change to device. Return true(1) if successful otherwise false(0). Should be called after configuration changes.

Returns
bool

Definition at line 53 of file HMC5883L.cpp.

Member Data Documentation

uint8_t TWI::Driver::m_addr
protectedinherited

Device bus address.

Definition at line 114 of file TWI.hh.

bool TWI::Driver::m_async
protectedinherited

Asynchronious mode.

Definition at line 117 of file TWI.hh.

config_t HMC5883L::m_config
protected

Configuration mirror register.

Definition at line 351 of file HMC5883L.hh.

uint8_t HMC5883L::m_mode
protected

Sleep mode while waiting for data.

Definition at line 354 of file HMC5883L.hh.

data_t HMC5883L::m_output
protected

Output register latest read.

Definition at line 360 of file HMC5883L.hh.

bool HMC5883L::m_overflow
protected

Overflow detected.

Definition at line 357 of file HMC5883L.hh.

const uint16_t HMC5883L::s_gain[]
staticprotected

Gain conversion table.

Definition at line 332 of file HMC5883L.hh.


The documentation for this class was generated from the following files: