Single and Dual Zone Infra Red Thermometer
Revision 4:c5344a5f3266, committed 2017-12-26
- Comitter:
- mcm
- Date:
- Tue Dec 26 11:14:36 2017 +0000
- Parent:
- 3:6a5b6fcff28e
- Commit message:
- The driver was completed and tested, it works as expected. It was tested using the NUCLEO-L152RE.
Changed in this revision
MLX90614.cpp | Show annotated file Show diff for this revision Revisions of this file |
MLX90614.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/MLX90614.cpp Tue Dec 26 11:07:58 2017 +0000 +++ b/MLX90614.cpp Tue Dec 26 11:14:36 2017 +0000 @@ -599,6 +599,122 @@ /** + * @brief MLX90614_GetTemperatureSource ( MLX90614_vector_data_t* ) + * + * @details It gets the temperature source. + * + * @param[in] NaN + * + * @param[out] myTempSource: Temperature source. + * + * + * @return Status of MLX90614_GetTemperatureSource. + * + * + * @author Manuel Caballero + * @date 26/December/2017 + * @version 26/December/2017 The ORIGIN + * @pre NaN. + * @warning NaN. + */ +MLX90614::MLX90614_status_t MLX90614::MLX90614_GetTemperatureSource ( MLX90614_vector_data_t* myTempSource ) +{ + char cmd[] = { MLX90614_CONFIG_REGISTER_1, 0, 0 }; + uint32_t aux = 0; + + + // It gets the temperature source + aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); + aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); + + + myTempSource->TempSource = ( MLX90614_configregister1_temp_t )( cmd[0] & CONFIGREG1_TEMP_MASK ); + myTempSource->PEC = cmd[2]; + + + + + if ( aux == I2C_SUCCESS ) + return MLX90614_SUCCESS; + else + return MLX90614_FAILURE; +} + + +/** + * @brief MLX90614_SetTemperatureSource ( I2C_parameters_t , MLX90614_configregister1_temp_t ) + * + * @details It sets the temperature source. + * + * @param[in] myTempSource: Temperature source. + * + * @param[out] NaN. + * + * + * @return Status of MLX90614_SetTemperatureSource. + * + * + * @author Manuel Caballero + * @date 26/December/2017 + * @version 26/December/2017 The ORIGIN + * @pre NaN. + * @warning NaN. + */ +MLX90614::MLX90614_status_t MLX90614::MLX90614_SetTemperatureSource ( MLX90614_configregister1_temp_t myTempSource ) +{ + char cmd[] = { MLX90614_CONFIG_REGISTER_1, 0, 0 }; + uint32_t aux = 0; + uint32_t ii = 0; + + + // It gets the IIR + aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); + aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); + + // Erase EEPROM + cmd[2] = cmd[1]; // MSB + cmd[1] = ( cmd[0] & ~CONFIGREG1_TEMP_MASK ); // LSB + cmd[0] = MLX90614_CONFIG_REGISTER_1; // Command + aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 3, false ); + + // It takes EEPROM about 5ms to write/read + do + { + cmd[0] = MLX90614_FLAGS; + aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); + aux = _i2c.read ( _MLX90614_Addr, &cmd[0], 3 ); + ii++; // Increase the timeout + } + while ( ( ( cmd[0] & FLAG_EEBUSY_HIGH ) == FLAG_EEBUSY_HIGH ) && ( ii < MLX90614_TIMEOUT ) ); + + + // If TIMEOUT, exit with failure. + if ( ii >= MLX90614_TIMEOUT ) + return MLX90614_FAILURE; + else + { + // It gets the IIR + aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); + aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); + + // Update the new value + cmd[2] = cmd[1]; // MSB + cmd[1] = ( ( cmd[0] & ~CONFIGREG1_TEMP_MASK ) | myTempSource ); // LSB + cmd[0] = MLX90614_CONFIG_REGISTER_1; // Command + aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 2, false ); + } + + + + + if ( aux == I2C_SUCCESS ) + return MLX90614_SUCCESS; + else + return MLX90614_FAILURE; +} + + +/** * @brief MLX90614_GetFLAGS ( MLX90614_vector_data_t* ) * * @details It gets the flags.
--- a/MLX90614.h Tue Dec 26 11:07:58 2017 +0000 +++ b/MLX90614.h Tue Dec 26 11:14:36 2017 +0000 @@ -162,7 +162,14 @@ CONFIGREG1_IIR_13 = ( 3 << 0 ) /*!< IIR (13%) a1=0.125, b1=0.875 */ } MLX90614_configregister1_iir_t; - +// TEMPERATURE SOURCES + typedef enum { + CONFIGREG1_TEMP_MASK = ( 3 << 4 ), /*!< Temp Mask */ + CONFIGREG1_TEMP_TA_TOBJ1 = ( 0 << 4 ), /*!< Ta, Tobj1 */ + CONFIGREG1_TEMP_TA_TOBJ2 = ( 1 << 4 ), /*!< Ta, Tobj2 */ + CONFIGREG1_TEMP_TOBJ2 = ( 2 << 4 ), /*!< Tobj2 */ + CONFIGREG1_TEMP_TOBJ1_TOBJ2 = ( 3 << 4 ) /*!< Tobj1, Tobj2 */ + } MLX90614_configregister1_temp_t; @@ -184,6 +191,7 @@ float Emissivity; MLX90614_configregister1_iir_t IIR; MLX90614_flags_t Flags; + MLX90614_configregister1_temp_t TempSource; } MLX90614_vector_data_t; #endif