HMC5883L  0.2
Library for I2C communication with HMC5883L over Arduino
 All Classes Files Functions Variables Modules
I2CDev Class Reference

Public Member Functions

 I2CDev (uint8_t address)
 
void start (void)
 
uint8_t write_data (uint8_t register_addr, uint8_t data)
 
uint8_t * read_data (uint8_t register_addr, uint8_t length)
 
uint8_t read_data_byte (uint8_t register_addr)
 
uint8_t get_err_code (void)
 

Constructor & Destructor Documentation

I2CDev::I2CDev ( uint8_t  address)

I2C device class constructor

Member Function Documentation

uint8_t I2CDev::get_err_code ( void  )

Retrieve the error code stored on the I2C device.

Retrieves the error code stored in err_code variable. If non-zero, use I2CGetErrorString() from I2CErrorStrings.h to retrieve the human-readable error string, or see I2CDev.h for details.

Returns
Returns the error code set in the current object. Non-zero value is an error.
uint8_t * I2CDev::read_data ( uint8_t  register_addr,
uint8_t  length 
)

Reads data of length length from register register_addr

This is a private function, called by specific-use functions such as read_RDAC() and read_EEMEM() to read a data array of length length (in bytes) from the register specified by register_addr.

Parameters
[in]register_addrThe address of the register to read from.
[in]lengthThe length of the data stored in the register.
Returns
On success, returns a pointer to an array of uint8_t unsigned bytes retrieved from the register. The returned array has length length, which in most cases will be 1. On error, this function returns a NULL pointer and sets err_code (query get_err_code() to get the value of this variable) to one of the I2C errors:
  • EC_NO_ERR: No error.
  • EC_DATA_LONG: Data too long to fit in transmit buffer
  • EC_NACK_ADDR: Received NACK on transmit of address.
  • EC_NACK_DATA: Received NACK on transmit of data.
  • EC_I2C_OTHER: Other I2C error.
uint8_t I2CDev::read_data_byte ( uint8_t  register_addr)

Reads a single byte from the specified register. Convenience wrapper for read_data().

This reads a single byte from the register specified at register_addr via a call to read_data(). In most cases, only a single byte is stored at the specified register address.

Parameters
[in]register_addrThe register address from which to read a single byte.
Returns
Returns the requested value. If there is an error, returns 0 and err_code (retrieved via get_err_code()) is set to a non-zero value. This is a simple wrapper for read_data(), so it raises only the errors raised by that function.
void I2CDev::start ( void  )

Start I2C communication with the specified device. Alias for Wire.begin().

uint8_t I2CDev::write_data ( uint8_t  register_addr,
uint8_t  data 
)

Writes data to the specified register address.

This is a private function, called by specific-use functions such as write_RDAC() and write_EEMEM() to write data (specified by data) into the register specified by register_addr using the Wire.h library.

Parameters
register_addrThe register address to query.
dataThe data to write to the specified address.
Returns
Returns 0 on no error, otherwise returns I2C errors:
  • EC_NO_ERR: No error.
  • EC_DATA_LONG: Data too long to fit in transmit buffer
  • EC_NACK_ADDR: Received NACK on transmit of address.
  • EC_NACK_DATA: Received NACK on transmit of data.
  • EC_I2C_OTHER: Other I2C error.

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