43#define CHIP_NAME "Honeywell HMC5883L"
44#define MANUFACTURER_NAME "Honeywell"
45#define SUPPLY_VOLTAGE_MIN 2.16f
46#define SUPPLY_VOLTAGE_MAX 3.6f
47#define MAX_CURRENT 0.1f
48#define TEMPERATURE_MIN -30.0f
49#define TEMPERATURE_MAX 85.0f
50#define DRIVER_VERSION 2000
55#define HMC5883L_ADDRESS 0x3C
60#define HMC5883L_REG_CRA 0x00
61#define HMC5883L_REG_CRB 0x01
62#define HMC5883L_REG_MODE 0x02
63#define HMC5883L_REG_OUTXM 0x03
64#define HMC5883L_REG_OUTXL 0x04
65#define HMC5883L_REG_OUTYM 0x07
66#define HMC5883L_REG_OUTYL 0x08
67#define HMC5883L_REG_OUTZM 0x05
68#define HMC5883L_REG_OUTZL 0x06
69#define HMC5883L_REG_STATUS 0x09
70#define HMC5883L_REG_IDA 0x0A
71#define HMC5883L_REG_IDB 0x0B
72#define HMC5883L_REG_IDC 0x0C
84 uint8_t reg, times, status;
115 (uint8_t *)&status, 1) != 0)
121 status = status & 0x01;
143 data = (int16_t)(((uint16_t)buf[0] << 8) | buf[1]);
144 if ((data <= 243) || (data > 575))
146 handle->
debug_print(
"hmc5883l: x check failed.\n");
150 data = (int16_t)(((uint16_t)buf[2] << 8) | buf[3]);
151 if ((data <= 243) || (data > 575))
153 handle->
debug_print(
"hmc5883l: y check failed.\n");
157 data = (int16_t)(((uint16_t)buf[4] << 8) | buf[5]);
158 if ((data <= 243) || (data > 575))
160 handle->
debug_print(
"hmc5883l: z check failed.\n");
192 handle->
debug_print(
"hmc5883l: iic_init is null.\n");
198 handle->
debug_print(
"hmc5883l: iic_deinit is null.\n");
204 handle->
debug_print(
"hmc5883l: iic_read is null.\n");
210 handle->
debug_print(
"hmc5883l: iic_write is null.\n");
216 handle->
debug_print(
"hmc5883l: delay_ms is null.\n");
223 handle->
debug_print(
"hmc5883l: iic init failed.\n");
236 handle->
debug_print(
"hmc5883l: first id invalid.\n");
250 handle->
debug_print(
"hmc5883l: second id invalid.\n");
264 handle->
debug_print(
"hmc5883l: third id invalid.\n");
269 if (a_hmc5883l_test(handle) != 0)
271 handle->
debug_print(
"hmc5883l: test is not passed.\n");
324 handle->
debug_print(
"hmc5883l: iic deinit failed.\n");
366 prev |= average_sample << 5;
441 prev |= data_rate << 2;
719 uint8_t res, gain, status, prev;
824 if ((status & 0x01) != 0)
832 handle->
debug_print(
"hmc5883l: ready bit not be set.\n");
844 raw[0] = (int16_t)(((uint16_t)buf[0] << 8) | buf[1]);
845 raw[1] = (int16_t)(((uint16_t)buf[2] << 8) | buf[3]);
846 raw[2] = (int16_t)(((uint16_t)buf[4] << 8) | buf[5]);
847 m_gauss[0] = (float)(raw[0]) * resolution;
848 m_gauss[1] = (float)(raw[1]) * resolution;
849 m_gauss[2] = (float)(raw[2]) * resolution;
941 uint8_t res, gain, status;
1029 if ((status & 0x01) != 0)
1037 handle->
debug_print(
"hmc5883l: ready bit not be set.\n");
1049 raw[0] = (int16_t)(((uint16_t)buf[0] << 8) | buf[1]);
1050 raw[1] = (int16_t)(((uint16_t)buf[2] << 8) | buf[3]);
1051 raw[2] = (int16_t)(((uint16_t)buf[4] << 8) | buf[5]);
1052 m_gauss[0] = (float)(raw[0]) * resolution;
1053 m_gauss[1] = (float)(raw[1]) * resolution;
1054 m_gauss[2] = (float)(raw[2]) * resolution;
#define HMC5883L_REG_CRA
chip register definition
#define HMC5883L_REG_STATUS
#define SUPPLY_VOLTAGE_MAX
#define HMC5883L_ADDRESS
iic address definition
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define HMC5883L_REG_OUTXM
#define CHIP_NAME
chip information definition
#define HMC5883L_REG_MODE
driver hmc5883l header file
uint8_t hmc5883l_set_mode(hmc5883l_handle_t *handle, hmc5883l_mode_t mode)
set the chip mode
hmc5883l_average_sample_t
hmc5883l average sample enumeration definition
hmc5883l_mode_t
hmc5883l mode enumeration definition
uint8_t hmc5883l_disable_high_speed_iic(hmc5883l_handle_t *handle)
disable the high speed iic
uint8_t hmc5883l_get_mode(hmc5883l_handle_t *handle, hmc5883l_mode_t *mode)
get the chip mode
uint8_t hmc5883l_set_gain(hmc5883l_handle_t *handle, hmc5883l_gain_t gain)
set the chip gain
uint8_t hmc5883l_set_average_sample(hmc5883l_handle_t *handle, hmc5883l_average_sample_t average_sample)
set the average sample rate
uint8_t hmc5883l_init(hmc5883l_handle_t *handle)
initialize the chip
uint8_t hmc5883l_continuous_read(hmc5883l_handle_t *handle, int16_t raw[3], float m_gauss[3])
read data continuously
uint8_t hmc5883l_set_data_output_rate(hmc5883l_handle_t *handle, hmc5883l_data_output_rate_t data_rate)
set the data output rate
uint8_t hmc5883l_info(hmc5883l_info_t *info)
get chip's information
uint8_t hmc5883l_deinit(hmc5883l_handle_t *handle)
close the chip
struct hmc5883l_handle_s hmc5883l_handle_t
hmc5883l handle structure definition
struct hmc5883l_info_s hmc5883l_info_t
hmc5883l information structure definition
hmc5883l_gain_t
hmc5883l gain enumeration definition
uint8_t hmc5883l_get_gain(hmc5883l_handle_t *handle, hmc5883l_gain_t *gain)
get the chip gain
hmc5883l_data_output_rate_t
hmc5883l data output rate enumeration definition
uint8_t hmc5883l_get_average_sample(hmc5883l_handle_t *handle, hmc5883l_average_sample_t *average_sample)
get the average sample rate
uint8_t hmc5883l_single_read(hmc5883l_handle_t *handle, int16_t raw[3], float m_gauss[3])
read data once
uint8_t hmc5883l_get_data_output_rate(hmc5883l_handle_t *handle, hmc5883l_data_output_rate_t *data_rate)
get the data output rate
uint8_t hmc5883l_start_continuous_read(hmc5883l_handle_t *handle)
start reading data
uint8_t hmc5883l_enable_high_speed_iic(hmc5883l_handle_t *handle)
enable the high speed iic
uint8_t hmc5883l_stop_continuous_read(hmc5883l_handle_t *handle)
stop reading data
uint8_t hmc5883l_get_reg(hmc5883l_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t hmc5883l_set_reg(hmc5883l_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v