43 #define CHIP_NAME "Melexis MLX90614"
44 #define MANUFACTURER_NAME "Melexis"
45 #define SUPPLY_VOLTAGE_MIN 4.5f
46 #define SUPPLY_VOLTAGE_MAX 5.5f
47 #define MAX_CURRENT 2.5f
48 #define TEMPERATURE_MIN -40.0f
49 #define TEMPERATURE_MAX 125.0f
50 #define DRIVER_VERSION 1000
55 #define COMMAND_READ_FLAGS 0xF0
56 #define COMMAND_ENTER_SLEEP 0xFF
61 #define MLX90614_REG_RAM_RAW_DATA_IR_CHANNEL_1 0x04
62 #define MLX90614_REG_RAM_RAW_DATA_IR_CHANNEL_2 0x05
63 #define MLX90614_REG_RAM_TA 0x06
64 #define MLX90614_REG_RAM_TOBJ1 0x07
65 #define MLX90614_REG_RAM_TOBJ2 0x08
66 #define MLX90614_REG_EEPROM_TO_MAX 0x20
67 #define MLX90614_REG_EEPROM_TO_MIN 0x21
68 #define MLX90614_REG_EEPROM_PWM_CTRL 0x22
69 #define MLX90614_REG_EEPROM_TA_RANGE 0x23
70 #define MLX90614_REG_EEPROM_EMISSIVITY 0x24
71 #define MLX90614_REG_EEPROM_CONFIG1 0x25
72 #define MLX90614_REG_EEPROM_ADDRESS 0x2E
73 #define MLX90614_REG_EEPROM_ID1_NUMBER 0x3C
74 #define MLX90614_REG_EEPROM_ID2_NUMBER 0x3D
75 #define MLX90614_REG_EEPROM_ID3_NUMBER 0x3E
76 #define MLX90614_REG_EEPROM_ID4_NUMBER 0x3F
85 static uint8_t a_mlx90614_calculate_crc(uint8_t *addr, uint8_t len)
92 uint8_t in_byte = *addr++;
94 for (i = 8; i != 0; i--)
96 uint8_t carry = (crc ^ in_byte ) & 0x80;
122 static uint8_t a_mlx90614_read(
mlx90614_handle_t *handle, uint8_t command, uint16_t *data)
127 uint8_t times = 0x03;
131 memset(buf, 0,
sizeof(uint8_t) * 3);
142 pec = a_mlx90614_calculate_crc((uint8_t *)arr, 5);
143 if ((pec != buf[2]) && (times != 0))
155 *data = (uint16_t)(((uint16_t)buf[1] << 8) | buf[0]);
171 static uint8_t a_mlx90614_write(
mlx90614_handle_t *handle, uint8_t command, uint16_t data)
179 if ((command & 0x20) != 0)
187 pec = a_mlx90614_calculate_crc((uint8_t *)arr, 4);
196 data_l = (uint8_t)(data & 0xFF);
197 data_h = (uint8_t)((data & 0xFF00U) >> 8);
202 pec = a_mlx90614_calculate_crc((uint8_t *)arr, 4);
216 data_l = (uint8_t)(data & 0xFF);
217 data_h = (uint8_t)((data & 0xFF00U) >> 8);
222 pec = a_mlx90614_calculate_crc((uint8_t *)arr, 4);
307 handle->
debug_print(
"mlx90614: read eeprom address failed.\n");
315 handle->
debug_print(
"mlx90614: write eeprom address failed.\n");
353 handle->
debug_print(
"mlx90614: read eeprom address failed.\n");
357 handle->
iic_addr = (uint8_t)((prev >> 0) & 0x0F);
391 handle->
debug_print(
"mlx90614: read config failed.\n");
395 prev &= ~(0x07 << 8);
429 handle->
debug_print(
"mlx90614: read config failed.\n");
467 handle->
debug_print(
"mlx90614: read config failed.\n");
505 handle->
debug_print(
"mlx90614: read config failed.\n");
543 handle->
debug_print(
"mlx90614: read config failed.\n");
547 prev &= ~(0x03 << 4);
581 handle->
debug_print(
"mlx90614: read config failed.\n");
619 handle->
debug_print(
"mlx90614: read config failed.\n");
623 prev &= ~(0x01 << 6);
657 handle->
debug_print(
"mlx90614: read config failed.\n");
695 handle->
debug_print(
"mlx90614: read config failed.\n");
699 prev &= ~(0x01 << 7);
733 handle->
debug_print(
"mlx90614: read config failed.\n");
771 handle->
debug_print(
"mlx90614: read config failed.\n");
775 prev &= ~(0x01 << 14);
809 handle->
debug_print(
"mlx90614: read config failed.\n");
813 prev &= (0x01 << 14);
847 handle->
debug_print(
"mlx90614: read config failed.\n");
851 prev &= ~(0x07 << 11);
885 handle->
debug_print(
"mlx90614: read config failed.\n");
923 handle->
debug_print(
"mlx90614: read config failed.\n");
927 prev &= ~(0x01 << 15);
928 prev |= enable << 15;
961 handle->
debug_print(
"mlx90614: read config failed.\n");
999 handle->
debug_print(
"mlx90614: read config failed.\n");
1003 prev &= ~(0x01 << 3);
1004 prev |= enable << 3;
1037 handle->
debug_print(
"mlx90614: read config failed.\n");
1122 handle->
debug_print(
"mlx90614: s is over 1.0.\n");
1127 *reg = (uint16_t)(round((
double)65535 * s));
1155 *s = (double) reg / 65535;
1188 handle->
debug_print(
"mlx90614: read raw channel 1 failed.\n");
1195 handle->
debug_print(
"mlx90614: read raw channel 2 failed.\n");
1231 handle->
debug_print(
"mlx90614: read raw ta failed.\n");
1235 *celsius = (float)(*raw) * 0.02f - 273.15f;
1269 handle->
debug_print(
"mlx90614: read ram tobj1 failed.\n");
1273 if (((*raw) & 0x8000U) != 0)
1279 *celsius = (float)(*raw) * 0.02f - 273.15f;
1313 handle->
debug_print(
"mlx90614: read ram tobj2 failed.\n");
1317 if (((*raw) & 0x8000U) != 0)
1323 *celsius = (float)(*raw) * 0.02f - 273.15f;
1355 handle->
debug_print(
"mlx90614: read id1 failed.\n");
1362 handle->
debug_print(
"mlx90614: read id2 failed.\n");
1369 handle->
debug_print(
"mlx90614: read id3 failed.\n");
1376 handle->
debug_print(
"mlx90614: read id4 failed.\n");
1442 crc = a_mlx90614_calculate_crc((uint8_t *)buf, 2);
1480 handle->
debug_print(
"mlx90614: write scl failed.\n");
1488 handle->
debug_print(
"mlx90614: write scl failed.\n");
1522 handle->
debug_print(
"mlx90614: write scl failed.\n");
1529 handle->
debug_print(
"mlx90614: write sda failed.\n");
1537 handle->
debug_print(
"mlx90614: write sda failed.\n");
1545 handle->
debug_print(
"mlx90614: write sda failed.\n");
1576 handle->
debug_print(
"mlx90614: iic_init is null.\n");
1582 handle->
debug_print(
"mlx90614: iic_deinit is null.\n");
1588 handle->
debug_print(
"mlx90614: iic_read is null.\n");
1594 handle->
debug_print(
"mlx90614: iic_write is null.\n");
1600 handle->
debug_print(
"mlx90614: scl_write is null.\n");
1606 handle->
debug_print(
"mlx90614: sda_write is null.\n");
1612 handle->
debug_print(
"mlx90614: delay_ms is null.\n");
1619 handle->
debug_print(
"mlx90614: iic init failed.\n");
1654 handle->
debug_print(
"mlx90614: iic deinit failed.\n");
1686 return a_mlx90614_write(handle, reg, data);
1712 return a_mlx90614_read(handle, reg, data);
#define MLX90614_REG_EEPROM_ID1_NUMBER
#define MLX90614_REG_EEPROM_EMISSIVITY
#define MLX90614_REG_RAM_TA
#define COMMAND_ENTER_SLEEP
#define MLX90614_REG_EEPROM_ID4_NUMBER
#define MLX90614_REG_EEPROM_ADDRESS
#define MLX90614_REG_EEPROM_ID3_NUMBER
#define SUPPLY_VOLTAGE_MAX
#define MLX90614_REG_RAM_TOBJ1
#define MLX90614_REG_EEPROM_ID2_NUMBER
#define MLX90614_REG_RAM_RAW_DATA_IR_CHANNEL_2
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define MLX90614_REG_RAM_TOBJ2
#define MLX90614_REG_RAM_RAW_DATA_IR_CHANNEL_1
chip register definition
#define MLX90614_REG_EEPROM_CONFIG1
#define CHIP_NAME
chip information definition
#define COMMAND_READ_FLAGS
chip command definition
driver mlx90614 header file
uint8_t mlx90614_set_gain(mlx90614_handle_t *handle, mlx90614_gain_t gain)
set the gain param
mlx90614_gain_t
mlx90614 gain enumeration definition
mlx90614_ir_sensor_t
mlx90614 ir sensor enumeration definition
mlx90614_ks_t
mlx90614 ks enumeration definition
uint8_t mlx90614_emissivity_correction_coefficient_convert_to_data(mlx90614_handle_t *handle, uint16_t reg, double *s)
emissivity correction coefficient convert to data
uint8_t mlx90614_set_fir_length(mlx90614_handle_t *handle, mlx90614_fir_length_t len)
set the ir sensor fir length
uint8_t mlx90614_get_emissivity_correction_coefficient(mlx90614_handle_t *handle, uint16_t *value)
get the emissivity correction coefficient
uint8_t mlx90614_set_repeat_sensor_test(mlx90614_handle_t *handle, mlx90614_bool_t enable)
enable or disable the repeat sensor test
uint8_t mlx90614_get_id(mlx90614_handle_t *handle, uint16_t id[4])
get the chip id
uint8_t mlx90614_get_mode(mlx90614_handle_t *handle, mlx90614_mode_t *mode)
get the mode
uint8_t mlx90614_set_mode(mlx90614_handle_t *handle, mlx90614_mode_t mode)
set the mode
uint8_t mlx90614_set_emissivity_correction_coefficient(mlx90614_handle_t *handle, uint16_t value)
set the emissivity correction coefficient
uint8_t mlx90614_get_kt2(mlx90614_handle_t *handle, mlx90614_kt2_t *kt2)
get the kt2 param
uint8_t mlx90614_get_sensor_test(mlx90614_handle_t *handle, mlx90614_bool_t *enable)
get the sensor test status
mlx90614_bool_t
mlx90614 bool enumeration definition
uint8_t mlx90614_get_flag(mlx90614_handle_t *handle, uint16_t *flag)
get the flag
uint8_t mlx90614_set_iir(mlx90614_handle_t *handle, mlx90614_iir_t iir)
set the iir param
uint8_t mlx90614_set_ir_sensor(mlx90614_handle_t *handle, mlx90614_ir_sensor_t sensor)
set the ir sensor mode
uint8_t mlx90614_get_gain(mlx90614_handle_t *handle, mlx90614_gain_t *gain)
get the gain param
uint8_t mlx90614_get_repeat_sensor_test(mlx90614_handle_t *handle, mlx90614_bool_t *enable)
get the repeat sensor test status
uint8_t mlx90614_get_iir(mlx90614_handle_t *handle, mlx90614_iir_t *iir)
get the iir param
uint8_t mlx90614_exit_sleep_mode(mlx90614_handle_t *handle)
exit from sleep mode
uint8_t mlx90614_set_ks(mlx90614_handle_t *handle, mlx90614_ks_t ks)
set the ks param
uint8_t mlx90614_get_ks(mlx90614_handle_t *handle, mlx90614_ks_t *ks)
get the ks param
mlx90614_mode_t
mlx90614 mode enumeration definition
uint8_t mlx90614_pwm_to_smbus(mlx90614_handle_t *handle)
change pwm mode to smbus mode
mlx90614_iir_t
mlx90614 iir enumeration definition
uint8_t mlx90614_get_ir_sensor(mlx90614_handle_t *handle, mlx90614_ir_sensor_t *sensor)
get the ir sensor mode
uint8_t mlx90614_set_kt2(mlx90614_handle_t *handle, mlx90614_kt2_t kt2)
set the kt2 param
uint8_t mlx90614_set_sensor_test(mlx90614_handle_t *handle, mlx90614_bool_t enable)
enable or disable the sensor test
uint8_t mlx90614_get_fir_length(mlx90614_handle_t *handle, mlx90614_fir_length_t *len)
get the ir sensor fir length
uint8_t mlx90614_enter_sleep_mode(mlx90614_handle_t *handle)
enter to sleep mode
mlx90614_kt2_t
mlx90614 kt2 enumeration definition
uint8_t mlx90614_emissivity_correction_coefficient_convert_to_register(mlx90614_handle_t *handle, double s, uint16_t *reg)
convert the emissivity correction coefficient to the register raw data
mlx90614_fir_length_t
mlx90614 fir length enumeration definition
uint8_t mlx90614_read_raw_ir_channel(mlx90614_handle_t *handle, uint16_t *channel_1, uint16_t *channel_2)
read the ir channel raw data
uint8_t mlx90614_read_object1(mlx90614_handle_t *handle, uint16_t *raw, float *celsius)
read the object1
uint8_t mlx90614_info(mlx90614_info_t *info)
get chip information
uint8_t mlx90614_get_addr(mlx90614_handle_t *handle, uint8_t *addr)
get the address
uint8_t mlx90614_init(mlx90614_handle_t *handle)
initialize the chip
uint8_t mlx90614_set_addr(mlx90614_handle_t *handle, uint8_t addr)
set the address
uint8_t mlx90614_read_ambient(mlx90614_handle_t *handle, uint16_t *raw, float *celsius)
read the ambient
uint8_t mlx90614_deinit(mlx90614_handle_t *handle)
close the chip
uint8_t mlx90614_read_object2(mlx90614_handle_t *handle, uint16_t *raw, float *celsius)
read the object2
uint8_t mlx90614_read_addr(mlx90614_handle_t *handle, uint8_t *addr)
read the address
uint8_t mlx90614_write_addr(mlx90614_handle_t *handle, uint8_t addr)
write the address
uint8_t mlx90614_get_reg(mlx90614_handle_t *handle, uint8_t reg, uint16_t *data)
get the chip register
uint8_t mlx90614_set_reg(mlx90614_handle_t *handle, uint8_t reg, uint16_t data)
set the chip register
mlx90614 handle structure definition
uint8_t(* sda_write)(uint8_t v)
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* scl_write)(uint8_t v)
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)
mlx90614 information structure definition
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v