MLX90632 Driver Library  a258525c
Universal MCU library for the 90632
MLX90632 Driver Library API

Implementation of MLX90632 driver with virtual i2c read/write functions. More...

Macros

#define ETIMEDOUT   110
 From linux errno.h. More...
 
#define EINVAL   22
 From linux errno.h. More...
 
#define EPROTONOSUPPORT   93
 From linux errno.h. More...
 
#define ERANGE   34
 From linux errno.h. More...
 
#define ENOKEY   126
 From linux errno.h. More...
 
#define BIT(x)   (1UL << (x))
 
#define BITS_PER_LONG   64
 Define how many bits per long your CPU has. More...
 
#define GENMASK(h, l)   (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
 
#define ARRAY_SIZE(arr)   (sizeof(arr) / sizeof(arr[0]))
 Return number of elements in array. More...
 
#define MLX90632_ADDR_RAM   0x4000
 Start address of ram. More...
 
#define MLX90632_ADDR_EEPROM   0x2480
 Start address of user eeprom. More...
 
#define MLX90632_EE_CTRL   0x24d4
 Control register initial value. More...
 
#define MLX90632_EE_CONTROL   MLX90632_EE_CTRL
 More human readable for Control register. More...
 
#define MLX90632_EE_I2C_ADDRESS   0x24d5
 I2C address register initial value. More...
 
#define MLX90632_EE_VERSION   0x240b
 EEPROM version reg - assumed 0x101. More...
 
#define MLX90632_EE_P_R   0x240c
 Calibration constant ambient reference register 32bit. More...
 
#define MLX90632_EE_P_G   0x240e
 Calibration constant ambient gain register 32bit. More...
 
#define MLX90632_EE_P_T   0x2410
 Calibration constant ambient tc2 register 32bit. More...
 
#define MLX90632_EE_P_O   0x2412
 Calibration constant ambient offset register 32bit. More...
 
#define MLX90632_EE_Aa   0x2414
 Aa calibration const register 32bit. More...
 
#define MLX90632_EE_Ab   0x2416
 Ab calibration const register 32bit. More...
 
#define MLX90632_EE_Ba   0x2418
 Ba calibration const register 32bit. More...
 
#define MLX90632_EE_Bb   0x241a
 Bb calibration const register 32bit. More...
 
#define MLX90632_EE_Ca   0x241c
 Ca calibration const register 32bit. More...
 
#define MLX90632_EE_Cb   0x241e
 Cb calibration const register 32bit. More...
 
#define MLX90632_EE_Da   0x2420
 Da calibration const register 32bit. More...
 
#define MLX90632_EE_Db   0x2422
 Db calibration const register 32bit. More...
 
#define MLX90632_EE_Ea   0x2424
 Ea calibration constant register 32bit. More...
 
#define MLX90632_EE_Eb   0x2426
 Eb calibration constant register 32bit. More...
 
#define MLX90632_EE_Fa   0x2428
 Fa calibration constant register 32bit. More...
 
#define MLX90632_EE_Fb   0x242a
 Fb calibration constant register 32bit. More...
 
#define MLX90632_EE_Ga   0x242c
 Ga calibration constant register 32bit. More...
 
#define MLX90632_EE_Gb   0x242e
 Ambient Beta calibration constant 16bit. More...
 
#define MLX90632_EE_Ka   0x242f
 IR Beta calibration constant 16bit. More...
 
#define MLX90632_EE_Ha   0x2481
 Ha customer calibration value register 16bit. More...
 
#define MLX90632_EE_Hb   0x2482
 Hb customer calibration value register 16bit. More...
 
#define MLX90632_EE_MEDICAL_MEAS1   0x24E1
 Medical measurement 1 16bit. More...
 
#define MLX90632_EE_MEDICAL_MEAS2   0x24E2
 Medical measurement 2 16bit. More...
 
#define MLX90632_EE_EXTENDED_MEAS1   0x24F1
 Extended measurement 1 16bit. More...
 
#define MLX90632_EE_EXTENDED_MEAS2   0x24F2
 Extended measurement 2 16bit. More...
 
#define MLX90632_EE_EXTENDED_MEAS3   0x24F3
 Extended measurement 3 16bit. More...
 
#define MLX90632_EE_REFRESH_RATE_START   10
 Refresh Rate Start bit. More...
 
#define MLX90632_EE_REFRESH_RATE_SHIFT   8
 Refresh Rate shift. More...
 
#define MLX90632_EE_REFRESH_RATE_MASK   GENMASK(MLX90632_EE_REFRESH_RATE_START, MLX90632_EE_REFRESH_RATE_SHIFT)
 Refresh Rate Mask. More...
 
#define MLX90632_EE_REFRESH_RATE(ee_val)   (ee_val & MLX90632_EE_REFRESH_RATE_MASK)
 Extract the Refresh Rate bits. More...
 
#define MLX90632_REFRESH_RATE(ee_val)   (MLX90632_EE_REFRESH_RATE(ee_val) >> MLX90632_EE_REFRESH_RATE_SHIFT)
 Extract Refresh Rate from ee register. More...
 
#define MLX90632_REFRESH_RATE_STATUS(mlx90632_meas)   (mlx90632_meas << MLX90632_EE_REFRESH_RATE_SHIFT)
 Extract the Refresh Rate bits. More...
 
#define MLX90632_REG_I2C_ADDR   0x3000
 Chip I2C address register. More...
 
#define MLX90632_REG_CTRL   0x3001
 Control Register address. More...
 
#define MLX90632_CFG_SOC_SHIFT   3
 Start measurement in step mode. More...
 
#define MLX90632_CFG_SOC_MASK   BIT(MLX90632_CFG_SOC_SHIFT)
 
#define MLX90632_CFG_PWR_MASK   GENMASK(2, 1)
 PowerMode Mask. More...
 
#define MLX90632_CFG_PWR(ctrl_val)   (ctrl_val & MLX90632_CFG_PWR_MASK)
 Extract the PowerMode bits. More...
 
#define MLX90632_CFG_MTYP_SHIFT   4
 Meas select start shift. More...
 
#define MLX90632_CFG_MTYP_MASK   GENMASK(8, MLX90632_CFG_MTYP_SHIFT)
 Meas select Mask. More...
 
#define MLX90632_CFG_MTYP(ctrl_val)   (ctrl_val & MLX90632_CFG_MTYP_MASK)
 Extract the MeasType bits. More...
 
#define MLX90632_CFG_SOB_SHIFT   11
 Start burst measurement in step mode. More...
 
#define MLX90632_CFG_SOB_MASK   BIT(MLX90632_CFG_SOB_SHIFT)
 
#define MLX90632_CFG_SOB(ctrl_val)   (ctrl_val << MLX90632_CFG_SOB_SHIFT)
 
#define MLX90632_PWR_STATUS(ctrl_val)   (ctrl_val << 1)
 
#define MLX90632_PWR_STATUS_HALT   MLX90632_PWR_STATUS(0)
 Pwrmode hold. More...
 
#define MLX90632_PWR_STATUS_SLEEP_STEP   MLX90632_PWR_STATUS(1)
 Pwrmode sleep step. More...
 
#define MLX90632_PWR_STATUS_STEP   MLX90632_PWR_STATUS(2)
 Pwrmode step. More...
 
#define MLX90632_PWR_STATUS_CONTINUOUS   MLX90632_PWR_STATUS(3)
 Pwrmode continuous. More...
 
#define MLX90632_MTYP_STATUS(ctrl_val)   (ctrl_val << MLX90632_CFG_MTYP_SHIFT)
 
#define MLX90632_MTYP_STATUS_MEDICAL   MLX90632_MTYP_STATUS(0)
 Medical measurement type. More...
 
#define MLX90632_MTYP_STATUS_EXTENDED   MLX90632_MTYP_STATUS(17)
 Extended measurement type. More...
 
#define MLX90632_MTYP(reg_val)   (MLX90632_CFG_MTYP(reg_val) >> MLX90632_CFG_MTYP_SHIFT)
 Extract MTYP from Control register. More...
 
#define MLX90632_START_BURST_MEAS   MLX90632_CFG_SOB(1)
 
#define MLX90632_BURST_MEAS_NOT_PENDING   MLX90632_CFG_SOB(0)
 
#define MLX90632_REG_STATUS   0x3fff
 Device status register. More...
 
#define MLX90632_STAT_BUSY   BIT(10)
 Device busy indicator. More...
 
#define MLX90632_STAT_EE_BUSY   BIT(9)
 Device EEPROM busy indicator. More...
 
#define MLX90632_STAT_BRST   BIT(8)
 Device brown out reset indicator. More...
 
#define MLX90632_STAT_CYCLE_POS   GENMASK(6, 2)
 Data position in measurement table. More...
 
#define MLX90632_STAT_DATA_RDY   BIT(0)
 Data ready indicator. More...
 
#define MLX90632_RAM_1(meas_num)   (MLX90632_ADDR_RAM + 3 * meas_num)
 
#define MLX90632_RAM_2(meas_num)   (MLX90632_ADDR_RAM + 3 * meas_num + 1)
 
#define MLX90632_RAM_3(meas_num)   (MLX90632_ADDR_RAM + 3 * meas_num + 2)
 
#define MLX90632_TIMING_EEPROM   100
 Time between EEPROM writes. More...
 
#define MLX90632_DSPv5   0x05 /* EEPROM DSP version */
 
#define MLX90632_EEPROM_VERSION   MLX90632_ID_MEDICAL
 Legacy define - to be deprecated. More...
 
#define MLX90632_EEPROM_WRITE_KEY   0x554C
 EEPROM write key 0x55 and 0x4c. More...
 
#define MLX90632_RESET_CMD   0x0006
 Reset sensor (address or global) More...
 
#define MLX90632_MAX_MEAS_NUM   31
 Maximum number of measurements in list. More...
 
#define MLX90632_EE_SEED   0x3f6d
 Seed for the CRC calculations. More...
 
#define MLX90632_REF_12   12.0
 ResCtrlRef value of Channel 1 or Channel 2. More...
 
#define MLX90632_REF_3   12.0
 ResCtrlRef value of Channel 3. More...
 
#define MLX90632_XTD_RNG_KEY   0x0500 /**Extended range support indication key */
 
#define MLX90632_MTYP_MEDICAL   0x00
 
#define MLX90632_MTYP_EXTENDED   0x11
 
#define MLX90632_MTYP_MEDICAL_BURST   0x80
 
#define MLX90632_MTYP_EXTENDED_BURST   0x91
 
#define MLX90632_BURST_MEASUREMENT_TYPE(meas_type)   (meas_type + 0x80)
 The MSBit is only used in the software to indicate burst type measurement. More...
 
#define MLX90632_MEASUREMENT_TYPE_STATUS(mtyp_type)   (mtyp_type & 0x7F)
 Extract the measurement type from MTYP. More...
 
#define MLX90632_MEASUREMENT_BURST_STATUS(mtyp_type)   (mtyp_type & 0x80)
 Extract the measurement burst/continuous type from MTYP. More...
 
#define MLX90632_MEAS_MAX_TIME   2000
 Maximum measurement time in ms for the lowest possible refresh rate. More...
 
#define MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES   100
 Maximum number of read tries before quiting with timeout error. More...
 
#define MLX90632_NEW_REG_VALUE(old_reg, new_value, h, l)   ((old_reg & (0xFFFF ^ GENMASK(h, l))) | (new_value << MLX90632_EE_REFRESH_RATE_SHIFT))
 

Typedefs

typedef enum mlx90632_meas_e mlx90632_meas_t
 

Enumerations

Functions

int32_t mlx90632_read_temp_raw (int16_t *ambient_new_raw, int16_t *ambient_old_raw, int16_t *object_new_raw, int16_t *object_old_raw)
 Read raw ambient and object temperature. More...
 
int32_t mlx90632_read_temp_raw_burst (int16_t *ambient_new_raw, int16_t *ambient_old_raw, int16_t *object_new_raw, int16_t *object_old_raw)
 Read raw ambient and object temperature in sleeping step mode. More...
 
double mlx90632_preprocess_temp_ambient (int16_t ambient_new_raw, int16_t ambient_old_raw, int16_t Gb)
 Calculation of raw ambient output. More...
 
double mlx90632_preprocess_temp_object (int16_t object_new_raw, int16_t object_old_raw, int16_t ambient_new_raw, int16_t ambient_old_raw, int16_t Ka)
 Calculation of raw object output. More...
 
double mlx90632_calc_temp_ambient (int16_t ambient_new_raw, int16_t ambient_old_raw, int32_t P_T, int32_t P_R, int32_t P_G, int32_t P_O, int16_t Gb)
 Calculation of ambient temperature. More...
 
double mlx90632_calc_temp_object (int32_t object, int32_t ambient, int32_t Ea, int32_t Eb, int32_t Ga, int32_t Fa, int32_t Fb, int16_t Ha, int16_t Hb)
 Calculation of object temperature. More...
 
double mlx90632_calc_temp_object_reflected (int32_t object, int32_t ambient, double reflected, int32_t Ea, int32_t Eb, int32_t Ga, int32_t Fa, int32_t Fb, int16_t Ha, int16_t Hb)
 Calculation of object temperature when the environment temperature differs from the sensor temperature. More...
 
int32_t mlx90632_init (void)
 Initialize MLX90632 driver and confirm EEPROM version. More...
 
int mlx90632_start_measurement (void)
 Trigger start measurement for mlx90632. More...
 
void mlx90632_set_emissivity (double value)
 Set emissivity which is retained in single variable. More...
 
double mlx90632_get_emissivity (void)
 Read value of emissivity. More...
 
int32_t mlx90632_start_measurement_burst (void)
 Trigger start of burst measurement for mlx90632. More...
 
int32_t mlx90632_get_measurement_time (uint16_t meas)
 Reads the refresh rate and calculates the time needed for a single measurment from the EEPROM settings. More...
 
int32_t mlx90632_calculate_dataset_ready_time (void)
 Reads the refresh rate and calculates the time needed for a whole measurment table from the EEPROM settings. More...
 
int32_t mlx90632_addressed_reset (void)
 Trigger system reset for mlx90632. More...
 
int32_t mlx90632_set_refresh_rate (mlx90632_meas_t measRate)
 Sets the refresh rate of the sensor using the MLX90632_EE_MEAS_1 and MLX90632_EE_MEAS_2 registers. More...
 
mlx90632_meas_t mlx90632_get_refresh_rate (void)
 Gets the value in MLX90632_EE_MEAS_1 and converts it to the appropriate MLX90632_MEAS enum. More...
 

Detailed Description

Implementation of MLX90632 driver with virtual i2c read/write functions.

Copy of Kernel driver, except that it is stripped of Linux kernel specifics which are replaced by simple i2c read/write functions. There are some Linux kernel macros left behind as they make code more readable and easier to understand, but if you already have your own implementation then preprocessor should handle it just fine.

Repository contains README.md for compilation and unit-test instructions.

Macro Definition Documentation

#define ARRAY_SIZE (   arr)    (sizeof(arr) / sizeof(arr[0]))

Return number of elements in array.

Definition at line 75 of file mlx90632.h.

#define BIT (   x)    (1UL << (x))

Definition at line 64 of file mlx90632.h.

#define BITS_PER_LONG   64

Define how many bits per long your CPU has.

Definition at line 69 of file mlx90632.h.

#define EINVAL   22

From linux errno.h.

Definition at line 49 of file mlx90632.h.

#define ENOKEY   126

From linux errno.h.

Definition at line 58 of file mlx90632.h.

#define EPROTONOSUPPORT   93

From linux errno.h.

Definition at line 52 of file mlx90632.h.

#define ERANGE   34

From linux errno.h.

Definition at line 55 of file mlx90632.h.

#define ETIMEDOUT   110

From linux errno.h.

Definition at line 46 of file mlx90632.h.

#define GENMASK (   h,
 
)    (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))

Definition at line 71 of file mlx90632.h.

#define MLX90632_ADDR_EEPROM   0x2480

Start address of user eeprom.

Definition at line 80 of file mlx90632.h.

#define MLX90632_ADDR_RAM   0x4000

Start address of ram.

Definition at line 79 of file mlx90632.h.

#define MLX90632_BURST_MEAS_NOT_PENDING   MLX90632_CFG_SOB(0)

Definition at line 165 of file mlx90632.h.

#define MLX90632_BURST_MEASUREMENT_TYPE (   meas_type)    (meas_type + 0x80)

The MSBit is only used in the software to indicate burst type measurement.

The 5 LS Bits define medical or extended measurement and are used to set the hardware

Definition at line 199 of file mlx90632.h.

#define MLX90632_CFG_MTYP (   ctrl_val)    (ctrl_val & MLX90632_CFG_MTYP_MASK)

Extract the MeasType bits.

Definition at line 147 of file mlx90632.h.

#define MLX90632_CFG_MTYP_MASK   GENMASK(8, MLX90632_CFG_MTYP_SHIFT)

Meas select Mask.

Definition at line 146 of file mlx90632.h.

#define MLX90632_CFG_MTYP_SHIFT   4

Meas select start shift.

Definition at line 145 of file mlx90632.h.

#define MLX90632_CFG_PWR (   ctrl_val)    (ctrl_val & MLX90632_CFG_PWR_MASK)

Extract the PowerMode bits.

Definition at line 144 of file mlx90632.h.

#define MLX90632_CFG_PWR_MASK   GENMASK(2, 1)

PowerMode Mask.

Definition at line 143 of file mlx90632.h.

#define MLX90632_CFG_SOB (   ctrl_val)    (ctrl_val << MLX90632_CFG_SOB_SHIFT)

Definition at line 150 of file mlx90632.h.

#define MLX90632_CFG_SOB_MASK   BIT(MLX90632_CFG_SOB_SHIFT)

Definition at line 149 of file mlx90632.h.

#define MLX90632_CFG_SOB_SHIFT   11

Start burst measurement in step mode.

Definition at line 148 of file mlx90632.h.

#define MLX90632_CFG_SOC_MASK   BIT(MLX90632_CFG_SOC_SHIFT)

Definition at line 142 of file mlx90632.h.

#define MLX90632_CFG_SOC_SHIFT   3

Start measurement in step mode.

Definition at line 141 of file mlx90632.h.

#define MLX90632_DSPv5   0x05 /* EEPROM DSP version */

Definition at line 184 of file mlx90632.h.

#define MLX90632_EE_Aa   0x2414

Aa calibration const register 32bit.

Definition at line 93 of file mlx90632.h.

#define MLX90632_EE_Ab   0x2416

Ab calibration const register 32bit.

Definition at line 94 of file mlx90632.h.

#define MLX90632_EE_Ba   0x2418

Ba calibration const register 32bit.

Definition at line 95 of file mlx90632.h.

#define MLX90632_EE_Bb   0x241a

Bb calibration const register 32bit.

Definition at line 96 of file mlx90632.h.

#define MLX90632_EE_Ca   0x241c

Ca calibration const register 32bit.

Definition at line 97 of file mlx90632.h.

#define MLX90632_EE_Cb   0x241e

Cb calibration const register 32bit.

Definition at line 98 of file mlx90632.h.

#define MLX90632_EE_CONTROL   MLX90632_EE_CTRL

More human readable for Control register.

Definition at line 84 of file mlx90632.h.

#define MLX90632_EE_CTRL   0x24d4

Control register initial value.

Definition at line 83 of file mlx90632.h.

#define MLX90632_EE_Da   0x2420

Da calibration const register 32bit.

Definition at line 99 of file mlx90632.h.

#define MLX90632_EE_Db   0x2422

Db calibration const register 32bit.

Definition at line 100 of file mlx90632.h.

#define MLX90632_EE_Ea   0x2424

Ea calibration constant register 32bit.

Definition at line 101 of file mlx90632.h.

#define MLX90632_EE_Eb   0x2426

Eb calibration constant register 32bit.

Definition at line 102 of file mlx90632.h.

#define MLX90632_EE_EXTENDED_MEAS1   0x24F1

Extended measurement 1 16bit.

Definition at line 113 of file mlx90632.h.

#define MLX90632_EE_EXTENDED_MEAS2   0x24F2

Extended measurement 2 16bit.

Definition at line 114 of file mlx90632.h.

#define MLX90632_EE_EXTENDED_MEAS3   0x24F3

Extended measurement 3 16bit.

Definition at line 115 of file mlx90632.h.

#define MLX90632_EE_Fa   0x2428

Fa calibration constant register 32bit.

Definition at line 103 of file mlx90632.h.

#define MLX90632_EE_Fb   0x242a

Fb calibration constant register 32bit.

Definition at line 104 of file mlx90632.h.

#define MLX90632_EE_Ga   0x242c

Ga calibration constant register 32bit.

Definition at line 105 of file mlx90632.h.

#define MLX90632_EE_Gb   0x242e

Ambient Beta calibration constant 16bit.

Definition at line 106 of file mlx90632.h.

#define MLX90632_EE_Ha   0x2481

Ha customer calibration value register 16bit.

Definition at line 108 of file mlx90632.h.

#define MLX90632_EE_Hb   0x2482

Hb customer calibration value register 16bit.

Definition at line 109 of file mlx90632.h.

#define MLX90632_EE_I2C_ADDRESS   0x24d5

I2C address register initial value.

Definition at line 86 of file mlx90632.h.

#define MLX90632_EE_Ka   0x242f

IR Beta calibration constant 16bit.

Definition at line 107 of file mlx90632.h.

#define MLX90632_EE_MEDICAL_MEAS1   0x24E1

Medical measurement 1 16bit.

Definition at line 111 of file mlx90632.h.

#define MLX90632_EE_MEDICAL_MEAS2   0x24E2

Medical measurement 2 16bit.

Definition at line 112 of file mlx90632.h.

#define MLX90632_EE_P_G   0x240e

Calibration constant ambient gain register 32bit.

Definition at line 90 of file mlx90632.h.

#define MLX90632_EE_P_O   0x2412

Calibration constant ambient offset register 32bit.

Definition at line 92 of file mlx90632.h.

#define MLX90632_EE_P_R   0x240c

Calibration constant ambient reference register 32bit.

Definition at line 89 of file mlx90632.h.

#define MLX90632_EE_P_T   0x2410

Calibration constant ambient tc2 register 32bit.

Definition at line 91 of file mlx90632.h.

#define MLX90632_EE_REFRESH_RATE (   ee_val)    (ee_val & MLX90632_EE_REFRESH_RATE_MASK)

Extract the Refresh Rate bits.

Definition at line 132 of file mlx90632.h.

#define MLX90632_EE_REFRESH_RATE_MASK   GENMASK(MLX90632_EE_REFRESH_RATE_START, MLX90632_EE_REFRESH_RATE_SHIFT)

Refresh Rate Mask.

Definition at line 131 of file mlx90632.h.

#define MLX90632_EE_REFRESH_RATE_SHIFT   8

Refresh Rate shift.

Definition at line 130 of file mlx90632.h.

#define MLX90632_EE_REFRESH_RATE_START   10

Refresh Rate Start bit.

Definition at line 129 of file mlx90632.h.

#define MLX90632_EE_SEED   0x3f6d

Seed for the CRC calculations.

Definition at line 189 of file mlx90632.h.

#define MLX90632_EE_VERSION   0x240b

EEPROM version reg - assumed 0x101.

Definition at line 87 of file mlx90632.h.

#define MLX90632_EEPROM_VERSION   MLX90632_ID_MEDICAL

Legacy define - to be deprecated.

Definition at line 185 of file mlx90632.h.

#define MLX90632_EEPROM_WRITE_KEY   0x554C

EEPROM write key 0x55 and 0x4c.

Definition at line 186 of file mlx90632.h.

#define MLX90632_MAX_MEAS_NUM   31

Maximum number of measurements in list.

Definition at line 188 of file mlx90632.h.

#define MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES   100

Maximum number of read tries before quiting with timeout error.

Definition at line 205 of file mlx90632.h.

#define MLX90632_MEAS_MAX_TIME   2000

Maximum measurement time in ms for the lowest possible refresh rate.

Definition at line 204 of file mlx90632.h.

#define MLX90632_MEASUREMENT_BURST_STATUS (   mtyp_type)    (mtyp_type & 0x80)

Extract the measurement burst/continuous type from MTYP.

Definition at line 202 of file mlx90632.h.

#define MLX90632_MEASUREMENT_TYPE_STATUS (   mtyp_type)    (mtyp_type & 0x7F)

Extract the measurement type from MTYP.

Definition at line 201 of file mlx90632.h.

#define MLX90632_MTYP (   reg_val)    (MLX90632_CFG_MTYP(reg_val) >> MLX90632_CFG_MTYP_SHIFT)

Extract MTYP from Control register.

Definition at line 162 of file mlx90632.h.

#define MLX90632_MTYP_EXTENDED   0x11

Definition at line 196 of file mlx90632.h.

#define MLX90632_MTYP_EXTENDED_BURST   0x91

Definition at line 198 of file mlx90632.h.

#define MLX90632_MTYP_MEDICAL   0x00

Definition at line 195 of file mlx90632.h.

#define MLX90632_MTYP_MEDICAL_BURST   0x80

Definition at line 197 of file mlx90632.h.

#define MLX90632_MTYP_STATUS (   ctrl_val)    (ctrl_val << MLX90632_CFG_MTYP_SHIFT)

Definition at line 159 of file mlx90632.h.

#define MLX90632_MTYP_STATUS_EXTENDED   MLX90632_MTYP_STATUS(17)

Extended measurement type.

Definition at line 161 of file mlx90632.h.

#define MLX90632_MTYP_STATUS_MEDICAL   MLX90632_MTYP_STATUS(0)

Medical measurement type.

Definition at line 160 of file mlx90632.h.

#define MLX90632_NEW_REG_VALUE (   old_reg,
  new_value,
  h,
 
)    ((old_reg & (0xFFFF ^ GENMASK(h, l))) | (new_value << MLX90632_EE_REFRESH_RATE_SHIFT))

Definition at line 210 of file mlx90632.h.

#define MLX90632_PWR_STATUS (   ctrl_val)    (ctrl_val << 1)

Definition at line 153 of file mlx90632.h.

#define MLX90632_PWR_STATUS_CONTINUOUS   MLX90632_PWR_STATUS(3)

Pwrmode continuous.

Definition at line 157 of file mlx90632.h.

#define MLX90632_PWR_STATUS_HALT   MLX90632_PWR_STATUS(0)

Pwrmode hold.

Definition at line 154 of file mlx90632.h.

#define MLX90632_PWR_STATUS_SLEEP_STEP   MLX90632_PWR_STATUS(1)

Pwrmode sleep step.

Definition at line 155 of file mlx90632.h.

#define MLX90632_PWR_STATUS_STEP   MLX90632_PWR_STATUS(2)

Pwrmode step.

Definition at line 156 of file mlx90632.h.

#define MLX90632_RAM_1 (   meas_num)    (MLX90632_ADDR_RAM + 3 * meas_num)

Definition at line 176 of file mlx90632.h.

#define MLX90632_RAM_2 (   meas_num)    (MLX90632_ADDR_RAM + 3 * meas_num + 1)

Definition at line 177 of file mlx90632.h.

#define MLX90632_RAM_3 (   meas_num)    (MLX90632_ADDR_RAM + 3 * meas_num + 2)

Definition at line 178 of file mlx90632.h.

#define MLX90632_REF_12   12.0

ResCtrlRef value of Channel 1 or Channel 2.

Definition at line 190 of file mlx90632.h.

#define MLX90632_REF_3   12.0

ResCtrlRef value of Channel 3.

Definition at line 191 of file mlx90632.h.

#define MLX90632_REFRESH_RATE (   ee_val)    (MLX90632_EE_REFRESH_RATE(ee_val) >> MLX90632_EE_REFRESH_RATE_SHIFT)

Extract Refresh Rate from ee register.

Definition at line 133 of file mlx90632.h.

#define MLX90632_REFRESH_RATE_STATUS (   mlx90632_meas)    (mlx90632_meas << MLX90632_EE_REFRESH_RATE_SHIFT)

Extract the Refresh Rate bits.

Definition at line 134 of file mlx90632.h.

#define MLX90632_REG_CTRL   0x3001

Control Register address.

Definition at line 140 of file mlx90632.h.

#define MLX90632_REG_I2C_ADDR   0x3000

Chip I2C address register.

Definition at line 137 of file mlx90632.h.

#define MLX90632_REG_STATUS   0x3fff

Device status register.

Definition at line 168 of file mlx90632.h.

#define MLX90632_RESET_CMD   0x0006

Reset sensor (address or global)

Definition at line 187 of file mlx90632.h.

#define MLX90632_START_BURST_MEAS   MLX90632_CFG_SOB(1)

Definition at line 164 of file mlx90632.h.

#define MLX90632_STAT_BRST   BIT(8)

Device brown out reset indicator.

Definition at line 171 of file mlx90632.h.

#define MLX90632_STAT_BUSY   BIT(10)

Device busy indicator.

Definition at line 169 of file mlx90632.h.

#define MLX90632_STAT_CYCLE_POS   GENMASK(6, 2)

Data position in measurement table.

Definition at line 172 of file mlx90632.h.

#define MLX90632_STAT_DATA_RDY   BIT(0)

Data ready indicator.

Definition at line 173 of file mlx90632.h.

#define MLX90632_STAT_EE_BUSY   BIT(9)

Device EEPROM busy indicator.

Definition at line 170 of file mlx90632.h.

#define MLX90632_TIMING_EEPROM   100

Time between EEPROM writes.

Definition at line 181 of file mlx90632.h.

#define MLX90632_XTD_RNG_KEY   0x0500 /**Extended range support indication key */

Definition at line 192 of file mlx90632.h.

Typedef Documentation

Enumeration Type Documentation

Enumerator
MLX90632_MEAS_HZ_ERROR 
MLX90632_MEAS_HZ_HALF 
MLX90632_MEAS_HZ_1 
MLX90632_MEAS_HZ_2 
MLX90632_MEAS_HZ_4 
MLX90632_MEAS_HZ_8 
MLX90632_MEAS_HZ_16 
MLX90632_MEAS_HZ_32 
MLX90632_MEAS_HZ_64 

Definition at line 118 of file mlx90632.h.

Function Documentation

int32_t mlx90632_addressed_reset ( void  )

Trigger system reset for mlx90632.

Perform full reset of mlx90632 using reset command. It also waits for at least 150us to ensure the mlx90632 device is properly reset and ready for further communications.

Return values
<0Something failed. Check errno.h for more information
0The mlx90632 device was properly reset and is now ready for communication.
Note
This function is using usleep so it is blocking!

Definition at line 475 of file mlx90632.c.

476 {
477  int32_t ret;
478 
479  ret = mlx90632_i2c_write(0x3005, MLX90632_RESET_CMD);
480  if (ret < 0)
481  return ret;
482 
483  usleep(150, 200);
484 
485  return 0;
486 }
int32_t mlx90632_i2c_write(int16_t register_address, uint16_t value)
Write value to register_address of the mlx90632.
void usleep(int min_range, int max_range)
Blocking function for sleeping in microseconds.
#define MLX90632_RESET_CMD
Reset sensor (address or global)
Definition: mlx90632.h:187
double mlx90632_calc_temp_ambient ( int16_t  ambient_new_raw,
int16_t  ambient_old_raw,
int32_t  P_T,
int32_t  P_R,
int32_t  P_G,
int32_t  P_O,
int16_t  Gb 
)

Calculation of ambient temperature.

DSPv5 implementation of ambient temperature calculation

Parameters
[in]ambient_new_rawambient temperature from MLX90632_RAM_3. The channel 1 or 2 is determined by value in MLX90632_STAT_CYCLE_POS
[in]ambient_old_rawambient temperature from MLX90632_RAM_3. The channel 1 or 2 is determined by value not in MLX90632_STAT_CYCLE_POS
[in]P_TRegister value on MLX90632_EE_P_T
[in]P_RRegister value on MLX90632_EE_P_R
[in]P_GRegister value on MLX90632_EE_P_G
[in]P_ORegister value on MLX90632_EE_P_O
[in]GbRegister value on MLX90632_EE_Gb
Returns
Calculated ambient temperature degrees Celsius

Definition at line 264 of file mlx90632.c.

266 {
267  double Asub, Bsub, Ablock, Bblock, Cblock, AMB;
268 
269  AMB = mlx90632_preprocess_temp_ambient(ambient_new_raw, ambient_old_raw, Gb);
270 
271  Asub = ((double)P_T) / (double)17592186044416.0;
272  Bsub = (double)AMB - ((double)P_R / (double)256.0);
273  Ablock = Asub * (Bsub * Bsub);
274  Bblock = (Bsub / (double)P_G) * (double)1048576.0;
275  Cblock = (double)P_O / (double)256.0;
276 
277  return Bblock + Ablock + Cblock;
278 }
double mlx90632_preprocess_temp_ambient(int16_t ambient_new_raw, int16_t ambient_old_raw, int16_t Gb)
Calculation of raw ambient output.
Definition: mlx90632.c:242
double mlx90632_calc_temp_object ( int32_t  object,
int32_t  ambient,
int32_t  Ea,
int32_t  Eb,
int32_t  Ga,
int32_t  Fa,
int32_t  Fb,
int16_t  Ha,
int16_t  Hb 
)

Calculation of object temperature.

DSPv5 implementation of object temperature calculation with customer calibration data

Parameters
[in]objectobject temperature from mlx90632_preprocess_temp_object
[in]ambientambient temperature from mlx90632_preprocess_temp_ambient
[in]EaRegister value on MLX90632_EE_Ea
[in]EbRegister value on MLX90632_EE_Eb
[in]GaRegister value on MLX90632_EE_Ga
[in]FbRegister value on MLX90632_EE_Fb
[in]FaRegister value on MLX90632_EE_Fa
[in]HaRegister value on MLX90632_EE_Ha
[in]HbRegister value on MLX90632_EE_Hb
Note
emissivity Value provided by user of the object emissivity using mlx90632_set_emissivity function.
Returns
Calculated object temperature in milliCelsius

Definition at line 389 of file mlx90632.c.

392 {
393  double kEa, kEb, TAdut;
394  double temp = 25.0;
395  double tmp_emi = mlx90632_get_emissivity();
396  int8_t i;
397 
398  kEa = ((double)Ea) / ((double)65536.0);
399  kEb = ((double)Eb) / ((double)256.0);
400  TAdut = (((double)ambient) - kEb) / kEa + 25;
401 
402  //iterate through calculations
403  for (i = 0; i < 5; ++i)
404  {
405  temp = mlx90632_calc_temp_object_iteration(temp, object, TAdut, Ga, Fa, Fb, Ha, Hb, tmp_emi);
406  }
407  return temp;
408 }
STATIC double mlx90632_calc_temp_object_iteration(double prev_object_temp, int32_t object, double TAdut, int32_t Ga, int32_t Fa, int32_t Fb, int16_t Ha, int16_t Hb, double emissivity)
Iterative calculation of object temperature.
Definition: mlx90632.c:300
double mlx90632_get_emissivity(void)
Read value of emissivity.
Definition: mlx90632.c:377
double mlx90632_calc_temp_object_reflected ( int32_t  object,
int32_t  ambient,
double  reflected,
int32_t  Ea,
int32_t  Eb,
int32_t  Ga,
int32_t  Fa,
int32_t  Fb,
int16_t  Ha,
int16_t  Hb 
)

Calculation of object temperature when the environment temperature differs from the sensor temperature.

when the object has emissivity lower than 1 then it does not just emit InfraRed light, but also reflects it. That is why measurement of the ambient temperature around object is important to help calculating more precise object temperature. This function makes it possible to add object environment temperature and offset it with sensor's ambient temperature to calculate more precise object temperature. DSPv5 implementation of object temperature calculation with customer calibration data

Parameters
[in]objectobject temperature from mlx90632_preprocess_temp_object
[in]ambientsensor ambient temperature from mlx90632_preprocess_temp_ambient
[in]reflectedreflected (environment) temperature from a sensor different than the MLX90632 or acquired by other means
[in]EaRegister value on MLX90632_EE_Ea
[in]EbRegister value on MLX90632_EE_Eb
[in]GaRegister value on MLX90632_EE_Ga
[in]FbRegister value on MLX90632_EE_Fb
[in]FaRegister value on MLX90632_EE_Fa
[in]HaRegister value on MLX90632_EE_Ha
[in]HbRegister value on MLX90632_EE_Hb
Note
emissivity Value provided by user of the object emissivity using mlx90632_set_emissivity function.
Returns
Calculated object temperature in milliCelsius

Definition at line 410 of file mlx90632.c.

413 {
414  double kEa, kEb, TAdut;
415  double temp = 25.0;
416  double tmp_emi = mlx90632_get_emissivity();
417  double TaTr4;
418  double ta4;
419  int8_t i;
420 
421  kEa = ((double)Ea) / ((double)65536.0);
422  kEb = ((double)Eb) / ((double)256.0);
423  TAdut = (((double)ambient) - kEb) / kEa + 25;
424 
425  TaTr4 = reflected + 273.15;
426  TaTr4 = TaTr4 * TaTr4;
427  TaTr4 = TaTr4 * TaTr4;
428  ta4 = TAdut + 273.15;
429  ta4 = ta4 * ta4;
430  ta4 = ta4 * ta4;
431  TaTr4 = TaTr4 - (TaTr4 - ta4) / tmp_emi;
432 
433  //iterate through calculations
434  for (i = 0; i < 5; ++i)
435  {
436  temp = mlx90632_calc_temp_object_iteration_reflected(temp, object, TAdut, TaTr4, Ga, Fa, Fb, Ha, Hb, tmp_emi);
437  }
438  return temp;
439 }
double mlx90632_get_emissivity(void)
Read value of emissivity.
Definition: mlx90632.c:377
STATIC double mlx90632_calc_temp_object_iteration_reflected(double prev_object_temp, int32_t object, double TAdut, double TaTr4, int32_t Ga, int32_t Fa, int32_t Fb, int16_t Ha, int16_t Hb, double emissivity)
Iterative calculation of object temperature when the environment temperature differs from the sensor ...
Definition: mlx90632.c:348
int32_t mlx90632_calculate_dataset_ready_time ( void  )

Reads the refresh rate and calculates the time needed for a whole measurment table from the EEPROM settings.

The function is returning valid measurement time only for burst mode measurements. An error will be returned if it is called with a continuous measurement type parameter.

Return values
>=0Refresh time in ms
<0Something went wrong. Check errno.h for more details.

Definition at line 503 of file mlx90632.c.

504 {
505  int32_t ret;
506  int32_t refresh_time;
507 
508  ret = mlx90632_get_meas_type();
509  if (ret < 0)
510  return ret;
511 
513  return -EINVAL;
514 
515  if (ret == MLX90632_MTYP_MEDICAL_BURST)
516  {
518  if (ret < 0)
519  return ret;
520 
521  refresh_time = ret;
522 
524  if (ret < 0)
525  return ret;
526 
527  refresh_time = refresh_time + ret;
528  }
529  else
530  {
532  if (ret < 0)
533  return ret;
534 
535  refresh_time = ret;
536 
538  if (ret < 0)
539  return ret;
540 
541  refresh_time = refresh_time + ret;
542 
544  if (ret < 0)
545  return ret;
546 
547  refresh_time = refresh_time + ret;
548  }
549 
550  return refresh_time;
551 }
#define MLX90632_MTYP_MEDICAL_BURST
Definition: mlx90632.h:197
#define MLX90632_EE_MEDICAL_MEAS2
Medical measurement 2 16bit.
Definition: mlx90632.h:112
#define MLX90632_EE_MEDICAL_MEAS1
Medical measurement 1 16bit.
Definition: mlx90632.h:111
#define MLX90632_EE_EXTENDED_MEAS3
Extended measurement 3 16bit.
Definition: mlx90632.h:115
int32_t mlx90632_get_measurement_time(uint16_t meas)
Reads the refresh rate and calculates the time needed for a single measurment from the EEPROM setting...
Definition: mlx90632.c:488
#define MLX90632_MTYP_EXTENDED_BURST
Definition: mlx90632.h:198
int32_t mlx90632_get_meas_type(void)
Get the current measurement type set in the MLX90632.
#define MLX90632_EE_EXTENDED_MEAS2
Extended measurement 2 16bit.
Definition: mlx90632.h:114
#define EINVAL
From linux errno.h.
Definition: mlx90632.h:49
#define MLX90632_EE_EXTENDED_MEAS1
Extended measurement 1 16bit.
Definition: mlx90632.h:113
double mlx90632_get_emissivity ( void  )

Read value of emissivity.

Definition at line 377 of file mlx90632.c.

378 {
379  if (emissivity == 0.0)
380  {
381  return 1.0;
382  }
383  else
384  {
385  return emissivity;
386  }
387 }
static double emissivity
Definition: mlx90632.c:371
int32_t mlx90632_get_measurement_time ( uint16_t  meas)

Reads the refresh rate and calculates the time needed for a single measurment from the EEPROM settings.

Parameters
[in]measMeasurement to read the frefresh rate for
Return values
>=0Refresh time in ms
<0Something went wrong. Check errno.h for more details.

Definition at line 488 of file mlx90632.c.

489 {
490  int32_t ret;
491  uint16_t reg;
492 
493  ret = mlx90632_i2c_read(meas, &reg);
494  if (ret < 0)
495  return ret;
496 
498  reg = reg >> 8;
499 
500  return MLX90632_MEAS_MAX_TIME >> reg;
501 }
#define MLX90632_MEAS_MAX_TIME
Maximum measurement time in ms for the lowest possible refresh rate.
Definition: mlx90632.h:204
#define MLX90632_EE_REFRESH_RATE_MASK
Refresh Rate Mask.
Definition: mlx90632.h:131
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value)
Read the register_address value from the mlx90632.
mlx90632_meas_t mlx90632_get_refresh_rate ( void  )

Gets the value in MLX90632_EE_MEAS_1 and converts it to the appropriate MLX90632_MEAS enum.

Return values
MLX90632_MEAS_HZ_ERRORif there is an error
refresh_rateas the mlx90632_meas_e

Definition at line 681 of file mlx90632.c.

682 {
683  int32_t ret;
684  uint16_t meas1;
685 
687  if (ret < 0)
688  return MLX90632_MEAS_HZ_ERROR;
689 
690  return MLX90632_REFRESH_RATE(meas1);
691 }
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value)
Read the register_address value from the mlx90632.
#define MLX90632_EE_MEDICAL_MEAS1
Medical measurement 1 16bit.
Definition: mlx90632.h:111
#define MLX90632_REFRESH_RATE(ee_val)
Extract Refresh Rate from ee register.
Definition: mlx90632.h:133
int32_t mlx90632_init ( void  )

Initialize MLX90632 driver and confirm EEPROM version.

EEPROM version is important to match sensor EEPROM content and calculations. This is why this function checks for correct EEPROM version before it does checksum validation of the EEPROM content.

Note
EEPROM version can have swapped high and low bytes due to CPU or I2C. Please confirm that i2c read (16bit) is functioning as expected.
Return values
0Successfully initialized MLX90632 driver, extended range measurement not supported

Definition at line 441 of file mlx90632.c.

442 {
443  int32_t ret;
444  uint16_t eeprom_version, reg_status;
445 
446  ret = mlx90632_i2c_read(MLX90632_EE_VERSION, &eeprom_version);
447  if (ret < 0)
448  {
449  return ret;
450  }
451 
452  if ((eeprom_version & 0x00FF) != MLX90632_DSPv5)
453  {
454  // this here can fail because of big/little endian of cpu/i2c
455  return -EPROTONOSUPPORT;
456  }
457 
458  ret = mlx90632_i2c_read(MLX90632_REG_STATUS, &reg_status);
459  if (ret < 0)
460  return ret;
461 
462  // Prepare a clean start with setting NEW_DATA to 0
464  if (ret < 0)
465  return ret;
466 
467  if ((eeprom_version & 0x7F00) == MLX90632_XTD_RNG_KEY)
468  {
469  return ERANGE;
470  }
471 
472  return 0;
473 }
#define MLX90632_EE_VERSION
EEPROM version reg - assumed 0x101.
Definition: mlx90632.h:87
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value)
Read the register_address value from the mlx90632.
#define EPROTONOSUPPORT
From linux errno.h.
Definition: mlx90632.h:52
#define MLX90632_XTD_RNG_KEY
Definition: mlx90632.h:192
int32_t mlx90632_i2c_write(int16_t register_address, uint16_t value)
Write value to register_address of the mlx90632.
#define ERANGE
From linux errno.h.
Definition: mlx90632.h:55
#define MLX90632_REG_STATUS
Device status register.
Definition: mlx90632.h:168
#define MLX90632_STAT_DATA_RDY
Data ready indicator.
Definition: mlx90632.h:173
#define MLX90632_DSPv5
Definition: mlx90632.h:184
double mlx90632_preprocess_temp_ambient ( int16_t  ambient_new_raw,
int16_t  ambient_old_raw,
int16_t  Gb 
)

Calculation of raw ambient output.

Preprocessing of the raw ambient value

Parameters
[in]ambient_new_rawambient temperature from MLX90632_RAM_3. The meas_num 1 or 2 is determined by value in MLX90632_STAT_CYCLE_POS
[in]ambient_old_rawambient temperature from MLX90632_RAM_3. The meas_num 1 or 2 is determined by value not in MLX90632_STAT_CYCLE_POS
[in]GbRegister value on MLX90632_EE_Gb
Returns
Calculated ambient raw output

Definition at line 242 of file mlx90632.c.

243 {
244  double VR_Ta, kGb;
245 
246  kGb = ((double)Gb) / 1024.0;
247 
248  VR_Ta = ambient_old_raw + kGb * (ambient_new_raw / (MLX90632_REF_3));
249  return ((ambient_new_raw / (MLX90632_REF_3)) / VR_Ta) * 524288.0;
250 }
#define MLX90632_REF_3
ResCtrlRef value of Channel 3.
Definition: mlx90632.h:191
double mlx90632_preprocess_temp_object ( int16_t  object_new_raw,
int16_t  object_old_raw,
int16_t  ambient_new_raw,
int16_t  ambient_old_raw,
int16_t  Ka 
)

Calculation of raw object output.

Preprocessing of the raw object value

Parameters
[in]object_new_rawobject temperature from MLX90632_RAM_1 or MLX90632_RAM_2. The meas_number 1 or 2 is determined by value in MLX90632_STAT_CYCLE_POS
[in]object_old_rawobject temperature from MLX90632_RAM_1 or MLX90632_RAM_2. The meas_number 1 or 2 is determined by value not in MLX90632_STAT_CYCLE_POS
[in]ambient_new_rawambient temperature from MLX90632_RAM_3. The meas_number 1 or 2 is determined by value in MLX90632_STAT_CYCLE_POS
[in]ambient_old_rawambient temperature from MLX90632_RAM_3. The meas_number 1 or 2 is determined by value not in MLX90632_STAT_CYCLE_POS
[in]KaRegister value on MLX90632_EE_Ka
Returns
Calculated object raw output

Definition at line 252 of file mlx90632.c.

255 {
256  double VR_IR, kKa;
257 
258  kKa = ((double)Ka) / 1024.0;
259 
260  VR_IR = ambient_old_raw + kKa * (ambient_new_raw / (MLX90632_REF_3));
261  return ((((object_new_raw + object_old_raw) / 2) / (MLX90632_REF_12)) / VR_IR) * 524288.0;
262 }
#define MLX90632_REF_3
ResCtrlRef value of Channel 3.
Definition: mlx90632.h:191
#define MLX90632_REF_12
ResCtrlRef value of Channel 1 or Channel 2.
Definition: mlx90632.h:190
int32_t mlx90632_read_temp_raw ( int16_t *  ambient_new_raw,
int16_t *  ambient_old_raw,
int16_t *  object_new_raw,
int16_t *  object_old_raw 
)

Read raw ambient and object temperature.

Trigger and read raw ambient and object temperatures. This values still need to be pre-processed via mlx90632_preprocess_temp_ambient and mlx90632_preprocess_temp_object functions and then processed via mlx90632_calc_temp_ambient and mlx90632_calc_temp_object to retrieve values in milliCelsius

Parameters
[out]ambient_new_rawPointer to where new raw ambient temperature is written
[out]object_new_rawPointer to where new raw object temperature is written
[out]ambient_old_rawPointer to where old raw ambient temperature is written
[out]object_old_rawPointer to where old raw object temperature is written
Return values
0Successfully read both temperatures
<0Something went wrong. Check errno.h for more details

Read new and old ambient values from sensor

Read new and old object values from sensor

Definition at line 198 of file mlx90632.c.

200 {
201  int32_t ret, start_measurement_ret;
202 
203  // trigger and wait for measurement to complete
204  start_measurement_ret = mlx90632_start_measurement();
205  if (start_measurement_ret < 0)
206  return start_measurement_ret;
207 
209  ret = mlx90632_read_temp_ambient_raw(ambient_new_raw, ambient_old_raw);
210  if (ret < 0)
211  return ret;
212 
214  ret = mlx90632_read_temp_object_raw(start_measurement_ret, object_new_raw, object_old_raw);
215 
216  return ret;
217 }
STATIC int32_t mlx90632_read_temp_ambient_raw(int16_t *ambient_new_raw, int16_t *ambient_old_raw)
Read ambient raw old and new values based on mlx90632_start_measurement return value.
Definition: mlx90632.c:130
int mlx90632_start_measurement(void)
Trigger start measurement for mlx90632.
Definition: mlx90632.c:47
STATIC int32_t mlx90632_read_temp_object_raw(int32_t start_measurement_ret, int16_t *object_new_raw, int16_t *object_old_raw)
Read object raw old and new values based on mlx90632_start_measurement return value.
Definition: mlx90632.c:162
int32_t mlx90632_read_temp_raw_burst ( int16_t *  ambient_new_raw,
int16_t *  ambient_old_raw,
int16_t *  object_new_raw,
int16_t *  object_old_raw 
)

Read raw ambient and object temperature in sleeping step mode.

Trigger and read raw ambient and object temperatures. This values still need to be pre-processed via mlx90632_preprocess_temp_ambient and mlx90632_preprocess_temp_object functions and then processed via mlx90632_calc_temp_ambient and mlx90632_calc_temp_object to retrieve values in milliCelsius

Parameters
[out]ambient_new_rawPointer to where new raw ambient temperature is written
[out]object_new_rawPointer to where new raw object temperature is written
[out]ambient_old_rawPointer to where old raw ambient temperature is written
[out]object_old_rawPointer to where old raw object temperature is written
Return values
0Successfully read both temperatures
<0Something went wrong. Check errno.h for more details

Read new and old ambient values from sensor

Read new and old object values from sensor

Definition at line 219 of file mlx90632.c.

221 {
222  int32_t ret, start_measurement_ret;
223 
224  // trigger and wait for measurement to complete
225  start_measurement_ret = mlx90632_start_measurement_burst();
226  if (start_measurement_ret < 0)
227  return start_measurement_ret;
228 
230  ret = mlx90632_read_temp_ambient_raw(ambient_new_raw, ambient_old_raw);
231  if (ret < 0)
232  return ret;
233 
235  ret = mlx90632_read_temp_object_raw(2, object_new_raw, object_old_raw);
236 
237  return ret;
238 }
int32_t mlx90632_start_measurement_burst(void)
Trigger start of burst measurement for mlx90632.
Definition: mlx90632.c:553
STATIC int32_t mlx90632_read_temp_ambient_raw(int16_t *ambient_new_raw, int16_t *ambient_old_raw)
Read ambient raw old and new values based on mlx90632_start_measurement return value.
Definition: mlx90632.c:130
STATIC int32_t mlx90632_read_temp_object_raw(int32_t start_measurement_ret, int16_t *object_new_raw, int16_t *object_old_raw)
Read object raw old and new values based on mlx90632_start_measurement return value.
Definition: mlx90632.c:162
void mlx90632_set_emissivity ( double  value)

Set emissivity which is retained in single variable.

Parameters
[in]valueValue provided by user of object emissivity. Defaults to 1.0 and cannot be 0.0.
Warning
This is not suitable for multi-process calculations as we do not use instances

Definition at line 372 of file mlx90632.c.

373 {
374  emissivity = value;
375 }
static double emissivity
Definition: mlx90632.c:371
int32_t mlx90632_set_refresh_rate ( mlx90632_meas_t  measRate)

Sets the refresh rate of the sensor using the MLX90632_EE_MEAS_1 and MLX90632_EE_MEAS_2 registers.

Parameters
[in]measRaterefresh rate to set with mlx90632_meas_e
Return values
<0Something went wrong. Consult errno.h for more details.

Definition at line 650 of file mlx90632.c.

651 {
652  uint16_t meas1, meas2;
653 
654  int32_t ret = mlx90632_i2c_read(MLX90632_EE_MEDICAL_MEAS1, &meas1);
655 
656  if (ret < 0)
657  return ret;
658 
660 
661  if (meas1 != new_value)
662  {
664  if (ret < 0)
665  return ret;
666  }
667 
669  if (ret < 0)
670  return ret;
671 
673  if (meas2 != new_value)
674  {
676  }
677 
678  return ret;
679 }
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value)
Read the register_address value from the mlx90632.
#define MLX90632_EE_MEDICAL_MEAS2
Medical measurement 2 16bit.
Definition: mlx90632.h:112
#define MLX90632_NEW_REG_VALUE(old_reg, new_value, h, l)
Definition: mlx90632.h:210
#define MLX90632_EE_MEDICAL_MEAS1
Medical measurement 1 16bit.
Definition: mlx90632.h:111
STATIC int32_t mlx90632_write_eeprom(uint16_t address, uint16_t data)
Definition: mlx90632.c:631
#define MLX90632_EE_REFRESH_RATE_SHIFT
Refresh Rate shift.
Definition: mlx90632.h:130
#define MLX90632_EE_REFRESH_RATE_START
Refresh Rate Start bit.
Definition: mlx90632.h:129
int mlx90632_start_measurement ( void  )

Trigger start measurement for mlx90632.

Trigger measurement cycle and wait for data to be ready. It does not read anything, just triggers and completes.

Return values
<0Something failed. Check errno.h for more information
>=0Channel position where new (recently updated) measurement can be found
Note
This function is using usleep so it is blocking!

Definition at line 47 of file mlx90632.c.

48 {
50  uint16_t reg_status;
51 
52  ret = mlx90632_i2c_read(MLX90632_REG_STATUS, &reg_status);
53  if (ret < 0)
54  return ret;
55 
57  if (ret < 0)
58  return ret;
59 
60  while (tries-- > 0)
61  {
62  ret = mlx90632_i2c_read(MLX90632_REG_STATUS, &reg_status);
63  if (ret < 0)
64  return ret;
65  if (reg_status & MLX90632_STAT_DATA_RDY)
66  break;
67  /* minimum wait time to complete measurement
68  * should be calculated according to refresh rate
69  * atm 10ms - 11ms
70  */
71  usleep(10000, 11000);
72  }
73 
74  if (tries < 0)
75  {
76  // data not ready
77  return -ETIMEDOUT;
78  }
79 
80  return (reg_status & MLX90632_STAT_CYCLE_POS) >> 2;
81 }
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value)
Read the register_address value from the mlx90632.
#define MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES
Maximum number of read tries before quiting with timeout error.
Definition: mlx90632.h:205
#define MLX90632_STAT_CYCLE_POS
Data position in measurement table.
Definition: mlx90632.h:172
int32_t mlx90632_i2c_write(int16_t register_address, uint16_t value)
Write value to register_address of the mlx90632.
#define MLX90632_REG_STATUS
Device status register.
Definition: mlx90632.h:168
#define MLX90632_STAT_DATA_RDY
Data ready indicator.
Definition: mlx90632.h:173
void usleep(int min_range, int max_range)
Blocking function for sleeping in microseconds.
#define ETIMEDOUT
From linux errno.h.
Definition: mlx90632.h:46
int32_t mlx90632_start_measurement_burst ( void  )

Trigger start of burst measurement for mlx90632.

Trigger a single measurement cycle and wait for data to be ready. It does not read anything, just triggers and completes. The SOB bit is set so that the complete measurement table is re-freshed.

Note
The SOB bit is cleared internally by the mlx90632 immediately after the measurement has started.
Return values
<0Something failed. Check errno.h for more information
0New data is available and waiting to be processed
Note
This function is using usleep and msleep. Because of usleep it is blocking, while msleep implementation can have a thread switch! In case both are blocking expect up to 2 second freeze of CPU in worse case scenario (depending on Refresh rate setting), so you might also need to take care of Watch Dog.

Definition at line 553 of file mlx90632.c.

554 {
555  int32_t ret;
557  uint16_t reg;
558 
560  if (ret < 0)
561  return ret;
562 
564 
566  if (ret < 0)
567  return ret;
568 
570  if (ret < 0)
571  return ret;
572  msleep(ret); /* Waiting for refresh of all the measurement tables */
573 
574  while (tries-- > 0)
575  {
577  if (ret < 0)
578  return ret;
579  if ((reg & MLX90632_STAT_BUSY) == 0)
580  break;
581  /* minimum wait time to complete measurement
582  * should be calculated according to refresh rate
583  * atm 10ms - 11ms
584  */
585  usleep(10000, 11000);
586  }
587 
588  if (tries < 0)
589  {
590  // data not ready
591  return -ETIMEDOUT;
592  }
593 
594  return 0;
595 }
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value)
Read the register_address value from the mlx90632.
#define MLX90632_START_BURST_MEAS
Definition: mlx90632.h:164
#define MLX90632_STAT_BUSY
Device busy indicator.
Definition: mlx90632.h:169
void msleep(int msecs)
Blocking function for sleeping in milliseconds.
#define MLX90632_MAX_NUMBER_MESUREMENT_READ_TRIES
Maximum number of read tries before quiting with timeout error.
Definition: mlx90632.h:205
int32_t mlx90632_i2c_write(int16_t register_address, uint16_t value)
Write value to register_address of the mlx90632.
#define MLX90632_REG_STATUS
Device status register.
Definition: mlx90632.h:168
int32_t mlx90632_calculate_dataset_ready_time(void)
Reads the refresh rate and calculates the time needed for a whole measurment table from the EEPROM se...
Definition: mlx90632.c:503
void usleep(int min_range, int max_range)
Blocking function for sleeping in microseconds.
#define MLX90632_REG_CTRL
Control Register address.
Definition: mlx90632.h:140
#define ETIMEDOUT
From linux errno.h.
Definition: mlx90632.h:46