HMC5883L
0.2
Library for I2C communication with HMC5883L over Arduino
|
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) |
I2CDev::I2CDev | ( | uint8_t | address | ) |
I2C device class constructor
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.
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
.
[in] | register_addr | The address of the register to read from. |
[in] | length | The length of the data stored in the register. |
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 bufferEC_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.
[in] | register_addr | The register address from which to read a single byte. |
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.
register_addr | The register address to query. |
data | The data to write to the specified address. |
EC_NO_ERR
: No error.EC_DATA_LONG
: Data too long to fit in transmit bufferEC_NACK_ADDR
: Received NACK on transmit of address.EC_NACK_DATA
: Received NACK on transmit of data.EC_I2C_OTHER
: Other I2C error.