Single and Dual Zone Infra Red Thermometer
MLX90614.cpp@4:c5344a5f3266, 2017-12-26 (annotated)
- Committer:
- mcm
- Date:
- Tue Dec 26 11:14:36 2017 +0000
- Revision:
- 4:c5344a5f3266
- Parent:
- 2:1d6817048eb1
The driver was completed and tested, it works as expected. It was tested using the NUCLEO-L152RE.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mcm | 2:1d6817048eb1 | 1 | /** |
mcm | 2:1d6817048eb1 | 2 | * @brief MLX90614.cpp |
mcm | 2:1d6817048eb1 | 3 | * @details Single and Dual Zone Infra Red Thermometer. |
mcm | 2:1d6817048eb1 | 4 | * Function file. |
mcm | 2:1d6817048eb1 | 5 | * |
mcm | 2:1d6817048eb1 | 6 | * |
mcm | 2:1d6817048eb1 | 7 | * @return NA |
mcm | 2:1d6817048eb1 | 8 | * |
mcm | 2:1d6817048eb1 | 9 | * @author Manuel Caballero |
mcm | 2:1d6817048eb1 | 10 | * @date 26/December/2017 |
mcm | 2:1d6817048eb1 | 11 | * @version 26/December/2017 The ORIGIN |
mcm | 2:1d6817048eb1 | 12 | * @pre NaN. |
mcm | 2:1d6817048eb1 | 13 | * @warning NaN |
mcm | 2:1d6817048eb1 | 14 | * @pre This code belongs to AqueronteBlog ( http://unbarquero.blogspot.com ). |
mcm | 2:1d6817048eb1 | 15 | */ |
mcm | 2:1d6817048eb1 | 16 | |
mcm | 2:1d6817048eb1 | 17 | #include "MLX90614.h" |
mcm | 2:1d6817048eb1 | 18 | |
mcm | 2:1d6817048eb1 | 19 | |
mcm | 2:1d6817048eb1 | 20 | MLX90614::MLX90614 ( PinName sda, PinName scl, uint32_t addr, uint32_t freq ) |
mcm | 2:1d6817048eb1 | 21 | : _i2c ( sda, scl ) |
mcm | 2:1d6817048eb1 | 22 | , _MLX90614_Addr ( addr ) |
mcm | 2:1d6817048eb1 | 23 | { |
mcm | 2:1d6817048eb1 | 24 | _i2c.frequency( freq ); |
mcm | 2:1d6817048eb1 | 25 | } |
mcm | 2:1d6817048eb1 | 26 | |
mcm | 2:1d6817048eb1 | 27 | |
mcm | 2:1d6817048eb1 | 28 | MLX90614::~MLX90614() |
mcm | 2:1d6817048eb1 | 29 | { |
mcm | 2:1d6817048eb1 | 30 | } |
mcm | 2:1d6817048eb1 | 31 | |
mcm | 2:1d6817048eb1 | 32 | |
mcm | 2:1d6817048eb1 | 33 | |
mcm | 2:1d6817048eb1 | 34 | |
mcm | 2:1d6817048eb1 | 35 | /** |
mcm | 2:1d6817048eb1 | 36 | * @brief MLX90614_GetID_Numbers ( MLX90614_vector_data_t* ) |
mcm | 2:1d6817048eb1 | 37 | * |
mcm | 2:1d6817048eb1 | 38 | * @details It gets the ID numbers. |
mcm | 2:1d6817048eb1 | 39 | * |
mcm | 2:1d6817048eb1 | 40 | * @param[in] NaN |
mcm | 2:1d6817048eb1 | 41 | * |
mcm | 2:1d6817048eb1 | 42 | * @param[out] myID: ID numbers. |
mcm | 2:1d6817048eb1 | 43 | * |
mcm | 2:1d6817048eb1 | 44 | * |
mcm | 2:1d6817048eb1 | 45 | * @return Status of MLX90614_GetID_Numbers. |
mcm | 2:1d6817048eb1 | 46 | * |
mcm | 2:1d6817048eb1 | 47 | * |
mcm | 2:1d6817048eb1 | 48 | * @author Manuel Caballero |
mcm | 2:1d6817048eb1 | 49 | * @date 26/December/2017 |
mcm | 2:1d6817048eb1 | 50 | * @version 26/December/2017 The ORIGIN |
mcm | 2:1d6817048eb1 | 51 | * @pre NaN. |
mcm | 2:1d6817048eb1 | 52 | * @warning NaN. |
mcm | 2:1d6817048eb1 | 53 | */ |
mcm | 2:1d6817048eb1 | 54 | MLX90614::MLX90614_status_t MLX90614::MLX90614_GetID_Numbers ( MLX90614_vector_data_t* myID ) |
mcm | 2:1d6817048eb1 | 55 | { |
mcm | 2:1d6817048eb1 | 56 | char cmd[] = { 0, 0, 0 }; |
mcm | 2:1d6817048eb1 | 57 | uint32_t aux = 0; |
mcm | 2:1d6817048eb1 | 58 | |
mcm | 2:1d6817048eb1 | 59 | |
mcm | 2:1d6817048eb1 | 60 | // It gets the ID 0 |
mcm | 2:1d6817048eb1 | 61 | cmd[0] = MLX90614_ID_NUMBER_0; |
mcm | 2:1d6817048eb1 | 62 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 2:1d6817048eb1 | 63 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 2:1d6817048eb1 | 64 | |
mcm | 2:1d6817048eb1 | 65 | myID->ID[0] = ( ( cmd[1] << 8 ) | cmd[0] ); |
mcm | 2:1d6817048eb1 | 66 | |
mcm | 2:1d6817048eb1 | 67 | |
mcm | 2:1d6817048eb1 | 68 | // It gets the ID 1 |
mcm | 2:1d6817048eb1 | 69 | cmd[0] = MLX90614_ID_NUMBER_1; |
mcm | 2:1d6817048eb1 | 70 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 2:1d6817048eb1 | 71 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 2:1d6817048eb1 | 72 | |
mcm | 2:1d6817048eb1 | 73 | myID->ID[1] = ( ( cmd[1] << 8 ) | cmd[0] ); |
mcm | 2:1d6817048eb1 | 74 | |
mcm | 2:1d6817048eb1 | 75 | |
mcm | 2:1d6817048eb1 | 76 | // It gets the ID 2 |
mcm | 2:1d6817048eb1 | 77 | cmd[0] = MLX90614_ID_NUMBER_2; |
mcm | 2:1d6817048eb1 | 78 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 2:1d6817048eb1 | 79 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 2:1d6817048eb1 | 80 | |
mcm | 2:1d6817048eb1 | 81 | myID->ID[2] = ( ( cmd[1] << 8 ) | cmd[0] ); |
mcm | 2:1d6817048eb1 | 82 | |
mcm | 2:1d6817048eb1 | 83 | |
mcm | 2:1d6817048eb1 | 84 | // It gets the ID 3 |
mcm | 2:1d6817048eb1 | 85 | cmd[0] = MLX90614_ID_NUMBER_3; |
mcm | 2:1d6817048eb1 | 86 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 2:1d6817048eb1 | 87 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 2:1d6817048eb1 | 88 | |
mcm | 2:1d6817048eb1 | 89 | myID->ID[3] = ( ( cmd[1] << 8 ) | cmd[0] ); |
mcm | 2:1d6817048eb1 | 90 | |
mcm | 2:1d6817048eb1 | 91 | |
mcm | 2:1d6817048eb1 | 92 | |
mcm | 2:1d6817048eb1 | 93 | |
mcm | 2:1d6817048eb1 | 94 | if ( aux == I2C_SUCCESS ) |
mcm | 2:1d6817048eb1 | 95 | return MLX90614_SUCCESS; |
mcm | 2:1d6817048eb1 | 96 | else |
mcm | 2:1d6817048eb1 | 97 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 98 | } |
mcm | 2:1d6817048eb1 | 99 | |
mcm | 2:1d6817048eb1 | 100 | |
mcm | 2:1d6817048eb1 | 101 | /** |
mcm | 2:1d6817048eb1 | 102 | * @brief MLX90614_ReadRawTA ( MLX90614_vector_data_t* ) |
mcm | 2:1d6817048eb1 | 103 | * |
mcm | 2:1d6817048eb1 | 104 | * @details It raw ambient temperature. |
mcm | 2:1d6817048eb1 | 105 | * |
mcm | 2:1d6817048eb1 | 106 | * @param[in] NaN. |
mcm | 2:1d6817048eb1 | 107 | * |
mcm | 2:1d6817048eb1 | 108 | * @param[out] myRawTA: Raw ambient temperature. |
mcm | 2:1d6817048eb1 | 109 | * |
mcm | 2:1d6817048eb1 | 110 | * |
mcm | 2:1d6817048eb1 | 111 | * @return Status of MLX90614_ReadRawTA. |
mcm | 2:1d6817048eb1 | 112 | * |
mcm | 2:1d6817048eb1 | 113 | * |
mcm | 2:1d6817048eb1 | 114 | * @author Manuel Caballero |
mcm | 2:1d6817048eb1 | 115 | * @date 26/December/2017 |
mcm | 2:1d6817048eb1 | 116 | * @version 26/December/2017 The ORIGIN |
mcm | 2:1d6817048eb1 | 117 | * @pre NaN. |
mcm | 2:1d6817048eb1 | 118 | * @warning NaN. |
mcm | 2:1d6817048eb1 | 119 | */ |
mcm | 2:1d6817048eb1 | 120 | MLX90614::MLX90614_status_t MLX90614::MLX90614_ReadRawTA ( MLX90614_vector_data_t* myRawTA ) |
mcm | 2:1d6817048eb1 | 121 | { |
mcm | 2:1d6817048eb1 | 122 | char cmd[] = { MLX90614_TA, 0, 0 }; |
mcm | 2:1d6817048eb1 | 123 | uint32_t aux = 0; |
mcm | 2:1d6817048eb1 | 124 | |
mcm | 2:1d6817048eb1 | 125 | |
mcm | 2:1d6817048eb1 | 126 | // It gets the raw ambient temperature |
mcm | 2:1d6817048eb1 | 127 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 2:1d6817048eb1 | 128 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 2:1d6817048eb1 | 129 | |
mcm | 2:1d6817048eb1 | 130 | |
mcm | 2:1d6817048eb1 | 131 | myRawTA->RawTA = ( ( cmd[1] << 8 ) | cmd[0] ); |
mcm | 2:1d6817048eb1 | 132 | myRawTA->PEC = cmd[2]; |
mcm | 2:1d6817048eb1 | 133 | |
mcm | 2:1d6817048eb1 | 134 | // Check if flag error is triggered ( faulty if so ) |
mcm | 2:1d6817048eb1 | 135 | if ( ( myRawTA->RawTA & MLX90614_FLAG_ERROR ) == MLX90614_FLAG_ERROR ) |
mcm | 2:1d6817048eb1 | 136 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 137 | |
mcm | 2:1d6817048eb1 | 138 | |
mcm | 2:1d6817048eb1 | 139 | if ( aux == I2C_SUCCESS ) |
mcm | 2:1d6817048eb1 | 140 | return MLX90614_SUCCESS; |
mcm | 2:1d6817048eb1 | 141 | else |
mcm | 2:1d6817048eb1 | 142 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 143 | } |
mcm | 2:1d6817048eb1 | 144 | |
mcm | 2:1d6817048eb1 | 145 | |
mcm | 2:1d6817048eb1 | 146 | /** |
mcm | 2:1d6817048eb1 | 147 | * @brief MLX90614_ReadTA ( MLX90614_vector_data_t* ) |
mcm | 2:1d6817048eb1 | 148 | * |
mcm | 2:1d6817048eb1 | 149 | * @details It ambient temperature. |
mcm | 2:1d6817048eb1 | 150 | * |
mcm | 2:1d6817048eb1 | 151 | * @param[in] NaN |
mcm | 2:1d6817048eb1 | 152 | * |
mcm | 2:1d6817048eb1 | 153 | * @param[out] myTA: Ambient temperature in Celsius. |
mcm | 2:1d6817048eb1 | 154 | * |
mcm | 2:1d6817048eb1 | 155 | * |
mcm | 2:1d6817048eb1 | 156 | * @return Status of MLX90614_ReadTA. |
mcm | 2:1d6817048eb1 | 157 | * |
mcm | 2:1d6817048eb1 | 158 | * |
mcm | 2:1d6817048eb1 | 159 | * @author Manuel Caballero |
mcm | 2:1d6817048eb1 | 160 | * @date 26/December/2017 |
mcm | 2:1d6817048eb1 | 161 | * @version 26/December/2017 The ORIGIN |
mcm | 2:1d6817048eb1 | 162 | * @pre NaN. |
mcm | 2:1d6817048eb1 | 163 | * @warning NaN. |
mcm | 2:1d6817048eb1 | 164 | */ |
mcm | 2:1d6817048eb1 | 165 | MLX90614::MLX90614_status_t MLX90614::MLX90614_ReadTA ( MLX90614_vector_data_t* myTA ) |
mcm | 2:1d6817048eb1 | 166 | { |
mcm | 2:1d6817048eb1 | 167 | char cmd[] = { MLX90614_TA, 0, 0 }; |
mcm | 2:1d6817048eb1 | 168 | uint32_t aux = 0; |
mcm | 2:1d6817048eb1 | 169 | |
mcm | 2:1d6817048eb1 | 170 | |
mcm | 2:1d6817048eb1 | 171 | // It gets the raw ambient temperature |
mcm | 2:1d6817048eb1 | 172 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 2:1d6817048eb1 | 173 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 2:1d6817048eb1 | 174 | |
mcm | 2:1d6817048eb1 | 175 | |
mcm | 2:1d6817048eb1 | 176 | myTA->TA = ( MLX90614_KELVIN_CONVERSION * ( ( ( cmd[1] << 8 ) | cmd[0] ) ) ) - MLX90614_KELVIN_TO_CELSIUS; |
mcm | 2:1d6817048eb1 | 177 | myTA->PEC = cmd[2]; |
mcm | 2:1d6817048eb1 | 178 | |
mcm | 2:1d6817048eb1 | 179 | // Check if flag error is triggered ( faulty if so ) |
mcm | 2:1d6817048eb1 | 180 | if ( ( cmd[1] & ( MLX90614_FLAG_ERROR >> 8 ) ) == ( MLX90614_FLAG_ERROR >> 8 ) ) |
mcm | 2:1d6817048eb1 | 181 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 182 | |
mcm | 2:1d6817048eb1 | 183 | |
mcm | 2:1d6817048eb1 | 184 | if ( aux == I2C_SUCCESS ) |
mcm | 2:1d6817048eb1 | 185 | return MLX90614_SUCCESS; |
mcm | 2:1d6817048eb1 | 186 | else |
mcm | 2:1d6817048eb1 | 187 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 188 | } |
mcm | 2:1d6817048eb1 | 189 | |
mcm | 2:1d6817048eb1 | 190 | |
mcm | 2:1d6817048eb1 | 191 | /** |
mcm | 2:1d6817048eb1 | 192 | * @brief MLX90614_ReadRawTObj1 ( MLX90614_vector_data_t* ) |
mcm | 2:1d6817048eb1 | 193 | * |
mcm | 2:1d6817048eb1 | 194 | * @details It raw object 1 temperature. |
mcm | 2:1d6817048eb1 | 195 | * |
mcm | 2:1d6817048eb1 | 196 | * @param[in] NaN. |
mcm | 2:1d6817048eb1 | 197 | * |
mcm | 2:1d6817048eb1 | 198 | * @param[out] myRawTObj1: Raw object 1 temperature. |
mcm | 2:1d6817048eb1 | 199 | * |
mcm | 2:1d6817048eb1 | 200 | * |
mcm | 2:1d6817048eb1 | 201 | * @return Status of MLX90614_ReadRawTObj1. |
mcm | 2:1d6817048eb1 | 202 | * |
mcm | 2:1d6817048eb1 | 203 | * |
mcm | 2:1d6817048eb1 | 204 | * @author Manuel Caballero |
mcm | 2:1d6817048eb1 | 205 | * @date 26/December/2017 |
mcm | 2:1d6817048eb1 | 206 | * @version 26/December/2017 The ORIGIN |
mcm | 2:1d6817048eb1 | 207 | * @pre NaN. |
mcm | 2:1d6817048eb1 | 208 | * @warning NaN. |
mcm | 2:1d6817048eb1 | 209 | */ |
mcm | 2:1d6817048eb1 | 210 | MLX90614::MLX90614_status_t MLX90614::MLX90614_ReadRawTObj1 ( MLX90614_vector_data_t* myRawTObj1 ) |
mcm | 2:1d6817048eb1 | 211 | { |
mcm | 2:1d6817048eb1 | 212 | char cmd[] = { MLX90614_TOBJ_1, 0, 0 }; |
mcm | 2:1d6817048eb1 | 213 | uint32_t aux = 0; |
mcm | 2:1d6817048eb1 | 214 | |
mcm | 2:1d6817048eb1 | 215 | |
mcm | 2:1d6817048eb1 | 216 | // It gets the raw object 1 temperature |
mcm | 2:1d6817048eb1 | 217 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 2:1d6817048eb1 | 218 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 2:1d6817048eb1 | 219 | |
mcm | 2:1d6817048eb1 | 220 | |
mcm | 2:1d6817048eb1 | 221 | myRawTObj1->RawTObj1 = ( ( cmd[1] << 8 ) | cmd[0] ); |
mcm | 2:1d6817048eb1 | 222 | myRawTObj1->PEC = cmd[2]; |
mcm | 2:1d6817048eb1 | 223 | |
mcm | 2:1d6817048eb1 | 224 | // Check if flag error is triggered ( faulty if so ) |
mcm | 2:1d6817048eb1 | 225 | if ( ( myRawTObj1->RawTObj1 & MLX90614_FLAG_ERROR ) == MLX90614_FLAG_ERROR ) |
mcm | 2:1d6817048eb1 | 226 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 227 | |
mcm | 2:1d6817048eb1 | 228 | |
mcm | 2:1d6817048eb1 | 229 | if ( aux == I2C_SUCCESS ) |
mcm | 2:1d6817048eb1 | 230 | return MLX90614_SUCCESS; |
mcm | 2:1d6817048eb1 | 231 | else |
mcm | 2:1d6817048eb1 | 232 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 233 | } |
mcm | 2:1d6817048eb1 | 234 | |
mcm | 2:1d6817048eb1 | 235 | |
mcm | 2:1d6817048eb1 | 236 | /** |
mcm | 2:1d6817048eb1 | 237 | * @brief MLX90614_ReadTObj1 ( MLX90614_vector_data_t* ) |
mcm | 2:1d6817048eb1 | 238 | * |
mcm | 2:1d6817048eb1 | 239 | * @details It object 1 temperature. |
mcm | 2:1d6817048eb1 | 240 | * |
mcm | 2:1d6817048eb1 | 241 | * @param[in] NaN. |
mcm | 2:1d6817048eb1 | 242 | * |
mcm | 2:1d6817048eb1 | 243 | * @param[out] myTObj1: Object 1 temperature in Celsius. |
mcm | 2:1d6817048eb1 | 244 | * |
mcm | 2:1d6817048eb1 | 245 | * |
mcm | 2:1d6817048eb1 | 246 | * @return Status of MLX90614_ReadTObj1. |
mcm | 2:1d6817048eb1 | 247 | * |
mcm | 2:1d6817048eb1 | 248 | * |
mcm | 2:1d6817048eb1 | 249 | * @author Manuel Caballero |
mcm | 2:1d6817048eb1 | 250 | * @date 26/December/2017 |
mcm | 2:1d6817048eb1 | 251 | * @version 26/December/2017 The ORIGIN |
mcm | 2:1d6817048eb1 | 252 | * @pre NaN. |
mcm | 2:1d6817048eb1 | 253 | * @warning NaN. |
mcm | 2:1d6817048eb1 | 254 | */ |
mcm | 2:1d6817048eb1 | 255 | MLX90614::MLX90614_status_t MLX90614::MLX90614_ReadTObj1 ( MLX90614_vector_data_t* myTObj1 ) |
mcm | 2:1d6817048eb1 | 256 | { |
mcm | 2:1d6817048eb1 | 257 | char cmd[] = { MLX90614_TOBJ_1, 0, 0 }; |
mcm | 2:1d6817048eb1 | 258 | uint32_t aux = 0; |
mcm | 2:1d6817048eb1 | 259 | |
mcm | 2:1d6817048eb1 | 260 | |
mcm | 2:1d6817048eb1 | 261 | // It gets the raw object 1 temperature |
mcm | 2:1d6817048eb1 | 262 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 2:1d6817048eb1 | 263 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 2:1d6817048eb1 | 264 | |
mcm | 2:1d6817048eb1 | 265 | |
mcm | 2:1d6817048eb1 | 266 | myTObj1->TObj1 = ( MLX90614_KELVIN_CONVERSION * ( ( ( cmd[1] << 8 ) | cmd[0] ) ) ) - MLX90614_KELVIN_TO_CELSIUS; |
mcm | 2:1d6817048eb1 | 267 | myTObj1->PEC = cmd[2]; |
mcm | 2:1d6817048eb1 | 268 | |
mcm | 2:1d6817048eb1 | 269 | // Check if flag error is triggered ( faulty if so ) |
mcm | 2:1d6817048eb1 | 270 | if ( ( cmd[1] & ( MLX90614_FLAG_ERROR >> 8 ) ) == ( MLX90614_FLAG_ERROR >> 8 ) ) |
mcm | 2:1d6817048eb1 | 271 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 272 | |
mcm | 2:1d6817048eb1 | 273 | |
mcm | 2:1d6817048eb1 | 274 | if ( aux == I2C_SUCCESS ) |
mcm | 2:1d6817048eb1 | 275 | return MLX90614_SUCCESS; |
mcm | 2:1d6817048eb1 | 276 | else |
mcm | 2:1d6817048eb1 | 277 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 278 | } |
mcm | 2:1d6817048eb1 | 279 | |
mcm | 2:1d6817048eb1 | 280 | |
mcm | 2:1d6817048eb1 | 281 | /** |
mcm | 2:1d6817048eb1 | 282 | * @brief MLX90614_ReadRawTObj2 ( MLX90614_vector_data_t* ) |
mcm | 2:1d6817048eb1 | 283 | * |
mcm | 2:1d6817048eb1 | 284 | * @details It raw object 2 temperature. |
mcm | 2:1d6817048eb1 | 285 | * |
mcm | 2:1d6817048eb1 | 286 | * @param[in] NaN. |
mcm | 2:1d6817048eb1 | 287 | * |
mcm | 2:1d6817048eb1 | 288 | * @param[out] myRawTObj1: Raw object 2 temperature. |
mcm | 2:1d6817048eb1 | 289 | * |
mcm | 2:1d6817048eb1 | 290 | * |
mcm | 2:1d6817048eb1 | 291 | * @return Status of MLX90614_ReadRawTObj2. |
mcm | 2:1d6817048eb1 | 292 | * |
mcm | 2:1d6817048eb1 | 293 | * |
mcm | 2:1d6817048eb1 | 294 | * @author Manuel Caballero |
mcm | 2:1d6817048eb1 | 295 | * @date 26/December/2017 |
mcm | 2:1d6817048eb1 | 296 | * @version 26/December/2017 The ORIGIN |
mcm | 2:1d6817048eb1 | 297 | * @pre NaN. |
mcm | 2:1d6817048eb1 | 298 | * @warning NaN. |
mcm | 2:1d6817048eb1 | 299 | */ |
mcm | 2:1d6817048eb1 | 300 | MLX90614::MLX90614_status_t MLX90614::MLX90614_ReadRawTObj2 ( MLX90614_vector_data_t* myRawTObj2 ) |
mcm | 2:1d6817048eb1 | 301 | { |
mcm | 2:1d6817048eb1 | 302 | char cmd[] = { MLX90614_TOBJ_2, 0, 0 }; |
mcm | 2:1d6817048eb1 | 303 | uint32_t aux = 0; |
mcm | 2:1d6817048eb1 | 304 | |
mcm | 2:1d6817048eb1 | 305 | |
mcm | 2:1d6817048eb1 | 306 | // It gets the raw object 1 temperature |
mcm | 2:1d6817048eb1 | 307 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 2:1d6817048eb1 | 308 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 2:1d6817048eb1 | 309 | |
mcm | 2:1d6817048eb1 | 310 | |
mcm | 2:1d6817048eb1 | 311 | myRawTObj2->RawTObj2 = ( ( cmd[1] << 8 ) | cmd[0] ); |
mcm | 2:1d6817048eb1 | 312 | myRawTObj2->PEC = cmd[2]; |
mcm | 2:1d6817048eb1 | 313 | |
mcm | 2:1d6817048eb1 | 314 | // Check if flag error is triggered ( faulty if so ) |
mcm | 2:1d6817048eb1 | 315 | if ( ( myRawTObj2->RawTObj2 & MLX90614_FLAG_ERROR ) == MLX90614_FLAG_ERROR ) |
mcm | 2:1d6817048eb1 | 316 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 317 | |
mcm | 2:1d6817048eb1 | 318 | |
mcm | 2:1d6817048eb1 | 319 | if ( aux == I2C_SUCCESS ) |
mcm | 2:1d6817048eb1 | 320 | return MLX90614_SUCCESS; |
mcm | 2:1d6817048eb1 | 321 | else |
mcm | 2:1d6817048eb1 | 322 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 323 | } |
mcm | 2:1d6817048eb1 | 324 | |
mcm | 2:1d6817048eb1 | 325 | |
mcm | 2:1d6817048eb1 | 326 | /** |
mcm | 2:1d6817048eb1 | 327 | * @brief MLX90614_ReadTObj2 ( MLX90614_vector_data_t* ) |
mcm | 2:1d6817048eb1 | 328 | * |
mcm | 2:1d6817048eb1 | 329 | * @details It object 2 temperature. |
mcm | 2:1d6817048eb1 | 330 | * |
mcm | 2:1d6817048eb1 | 331 | * @param[in] NaN. |
mcm | 2:1d6817048eb1 | 332 | * |
mcm | 2:1d6817048eb1 | 333 | * @param[out] myTObj2: Object 2 temperature in Celsius. |
mcm | 2:1d6817048eb1 | 334 | * |
mcm | 2:1d6817048eb1 | 335 | * |
mcm | 2:1d6817048eb1 | 336 | * @return Status of MLX90614_ReadTObj2. |
mcm | 2:1d6817048eb1 | 337 | * |
mcm | 2:1d6817048eb1 | 338 | * |
mcm | 2:1d6817048eb1 | 339 | * @author Manuel Caballero |
mcm | 2:1d6817048eb1 | 340 | * @date 26/December/2017 |
mcm | 2:1d6817048eb1 | 341 | * @version 26/December/2017 The ORIGIN |
mcm | 2:1d6817048eb1 | 342 | * @pre NaN. |
mcm | 2:1d6817048eb1 | 343 | * @warning NaN. |
mcm | 2:1d6817048eb1 | 344 | */ |
mcm | 2:1d6817048eb1 | 345 | MLX90614::MLX90614_status_t MLX90614::MLX90614_ReadTObj2 ( MLX90614_vector_data_t* myTObj2 ) |
mcm | 2:1d6817048eb1 | 346 | { |
mcm | 2:1d6817048eb1 | 347 | char cmd[] = { MLX90614_TOBJ_2, 0, 0 }; |
mcm | 2:1d6817048eb1 | 348 | uint32_t aux = 0; |
mcm | 2:1d6817048eb1 | 349 | |
mcm | 2:1d6817048eb1 | 350 | |
mcm | 2:1d6817048eb1 | 351 | // It gets the raw object 2 temperature |
mcm | 2:1d6817048eb1 | 352 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 2:1d6817048eb1 | 353 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 2:1d6817048eb1 | 354 | |
mcm | 2:1d6817048eb1 | 355 | |
mcm | 2:1d6817048eb1 | 356 | myTObj2->TObj2 = ( MLX90614_KELVIN_CONVERSION * ( ( ( cmd[1] << 8 ) | cmd[0] ) ) ) - MLX90614_KELVIN_TO_CELSIUS; |
mcm | 2:1d6817048eb1 | 357 | myTObj2->PEC = cmd[2]; |
mcm | 2:1d6817048eb1 | 358 | |
mcm | 2:1d6817048eb1 | 359 | // Check if flag error is triggered ( faulty if so ) |
mcm | 2:1d6817048eb1 | 360 | if ( ( cmd[1] & ( MLX90614_FLAG_ERROR >> 8 ) ) == ( MLX90614_FLAG_ERROR >> 8 ) ) |
mcm | 2:1d6817048eb1 | 361 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 362 | |
mcm | 2:1d6817048eb1 | 363 | |
mcm | 2:1d6817048eb1 | 364 | if ( aux == I2C_SUCCESS ) |
mcm | 2:1d6817048eb1 | 365 | return MLX90614_SUCCESS; |
mcm | 2:1d6817048eb1 | 366 | else |
mcm | 2:1d6817048eb1 | 367 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 368 | } |
mcm | 2:1d6817048eb1 | 369 | |
mcm | 2:1d6817048eb1 | 370 | |
mcm | 2:1d6817048eb1 | 371 | /** |
mcm | 2:1d6817048eb1 | 372 | * @brief MLX90614_GetEmissivity ( MLX90614_vector_data_t* ) |
mcm | 2:1d6817048eb1 | 373 | * |
mcm | 2:1d6817048eb1 | 374 | * @details It gets the Emissivity correction coefficient. |
mcm | 2:1d6817048eb1 | 375 | * |
mcm | 2:1d6817048eb1 | 376 | * @param[in] NaN |
mcm | 2:1d6817048eb1 | 377 | * |
mcm | 2:1d6817048eb1 | 378 | * @param[out] myEmissivity: Emissivity correction coefficient. |
mcm | 2:1d6817048eb1 | 379 | * |
mcm | 2:1d6817048eb1 | 380 | * |
mcm | 2:1d6817048eb1 | 381 | * @return Status of MLX90614_GetEmissivity. |
mcm | 2:1d6817048eb1 | 382 | * |
mcm | 2:1d6817048eb1 | 383 | * |
mcm | 2:1d6817048eb1 | 384 | * @author Manuel Caballero |
mcm | 2:1d6817048eb1 | 385 | * @date 26/December/2017 |
mcm | 2:1d6817048eb1 | 386 | * @version 26/December/2017 The ORIGIN |
mcm | 2:1d6817048eb1 | 387 | * @pre NaN. |
mcm | 2:1d6817048eb1 | 388 | * @warning NaN. |
mcm | 2:1d6817048eb1 | 389 | */ |
mcm | 2:1d6817048eb1 | 390 | MLX90614::MLX90614_status_t MLX90614::MLX90614_GetEmissivity ( MLX90614_vector_data_t* myEmissivity ) |
mcm | 2:1d6817048eb1 | 391 | { |
mcm | 2:1d6817048eb1 | 392 | char cmd[] = { MLX90614_EMISSIVITY_CORRECTION_COEFFICIENT, 0, 0 }; |
mcm | 2:1d6817048eb1 | 393 | uint32_t aux = 0; |
mcm | 2:1d6817048eb1 | 394 | |
mcm | 2:1d6817048eb1 | 395 | |
mcm | 2:1d6817048eb1 | 396 | // It gets the Emissivity correction coefficient |
mcm | 2:1d6817048eb1 | 397 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 2:1d6817048eb1 | 398 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 2:1d6817048eb1 | 399 | |
mcm | 2:1d6817048eb1 | 400 | |
mcm | 2:1d6817048eb1 | 401 | myEmissivity->Emissivity = ( ( cmd[1] << 8 ) | cmd[0] ); |
mcm | 2:1d6817048eb1 | 402 | myEmissivity->Emissivity /= 65535; |
mcm | 2:1d6817048eb1 | 403 | myEmissivity->PEC = cmd[2]; |
mcm | 2:1d6817048eb1 | 404 | |
mcm | 2:1d6817048eb1 | 405 | |
mcm | 2:1d6817048eb1 | 406 | |
mcm | 2:1d6817048eb1 | 407 | |
mcm | 2:1d6817048eb1 | 408 | if ( aux == I2C_SUCCESS ) |
mcm | 2:1d6817048eb1 | 409 | return MLX90614_SUCCESS; |
mcm | 2:1d6817048eb1 | 410 | else |
mcm | 2:1d6817048eb1 | 411 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 412 | } |
mcm | 2:1d6817048eb1 | 413 | |
mcm | 2:1d6817048eb1 | 414 | |
mcm | 2:1d6817048eb1 | 415 | /** |
mcm | 2:1d6817048eb1 | 416 | * @brief MLX90614_SetEmissivity ( MLX90614_vector_data_t* ) |
mcm | 2:1d6817048eb1 | 417 | * |
mcm | 2:1d6817048eb1 | 418 | * @details It sets the Emissivity correction coefficient. |
mcm | 2:1d6817048eb1 | 419 | * |
mcm | 2:1d6817048eb1 | 420 | * @param[in] NaN. |
mcm | 2:1d6817048eb1 | 421 | * @param[in] myEmissivity: Emissivity correction coefficient. |
mcm | 2:1d6817048eb1 | 422 | * |
mcm | 2:1d6817048eb1 | 423 | * @param[out] NaN |
mcm | 2:1d6817048eb1 | 424 | * |
mcm | 2:1d6817048eb1 | 425 | * |
mcm | 2:1d6817048eb1 | 426 | * @return Status of MLX90614_SetEmissivity. |
mcm | 2:1d6817048eb1 | 427 | * |
mcm | 2:1d6817048eb1 | 428 | * |
mcm | 2:1d6817048eb1 | 429 | * @author Manuel Caballero |
mcm | 2:1d6817048eb1 | 430 | * @date 26/December/2017 |
mcm | 2:1d6817048eb1 | 431 | * @version 26/December/2017 The ORIGIN |
mcm | 2:1d6817048eb1 | 432 | * @pre NaN. |
mcm | 2:1d6817048eb1 | 433 | * @warning NaN. |
mcm | 2:1d6817048eb1 | 434 | */ |
mcm | 2:1d6817048eb1 | 435 | MLX90614::MLX90614_status_t MLX90614::MLX90614_SetEmissivity ( MLX90614_vector_data_t myEmissivity ) |
mcm | 2:1d6817048eb1 | 436 | { |
mcm | 2:1d6817048eb1 | 437 | char cmd[] = { MLX90614_EMISSIVITY_CORRECTION_COEFFICIENT, 0, 0 }; |
mcm | 2:1d6817048eb1 | 438 | uint32_t aux = 0; |
mcm | 2:1d6817048eb1 | 439 | uint32_t ii = 0; |
mcm | 2:1d6817048eb1 | 440 | |
mcm | 2:1d6817048eb1 | 441 | |
mcm | 2:1d6817048eb1 | 442 | // Check Emissivity range |
mcm | 2:1d6817048eb1 | 443 | if ( ( myEmissivity.Emissivity >= 0.1 ) && ( myEmissivity.Emissivity <= 1) ) |
mcm | 2:1d6817048eb1 | 444 | { |
mcm | 2:1d6817048eb1 | 445 | // Erase EEPROM |
mcm | 2:1d6817048eb1 | 446 | cmd[1] = 0; |
mcm | 2:1d6817048eb1 | 447 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 2, false ); |
mcm | 2:1d6817048eb1 | 448 | |
mcm | 2:1d6817048eb1 | 449 | // It takes EEPROM about 5ms to write/read |
mcm | 2:1d6817048eb1 | 450 | do |
mcm | 2:1d6817048eb1 | 451 | { |
mcm | 2:1d6817048eb1 | 452 | cmd[0] = MLX90614_FLAGS; |
mcm | 2:1d6817048eb1 | 453 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 2:1d6817048eb1 | 454 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], 3 ); |
mcm | 2:1d6817048eb1 | 455 | ii++; // Increase the timeout |
mcm | 2:1d6817048eb1 | 456 | } |
mcm | 2:1d6817048eb1 | 457 | while ( ( ( cmd[0] & FLAG_EEBUSY_HIGH ) == FLAG_EEBUSY_HIGH ) && ( ii < MLX90614_TIMEOUT ) ); |
mcm | 2:1d6817048eb1 | 458 | |
mcm | 2:1d6817048eb1 | 459 | |
mcm | 2:1d6817048eb1 | 460 | // If TIMEOUT, exit with failure. |
mcm | 2:1d6817048eb1 | 461 | if ( ii >= MLX90614_TIMEOUT ) |
mcm | 2:1d6817048eb1 | 462 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 463 | else |
mcm | 2:1d6817048eb1 | 464 | { |
mcm | 2:1d6817048eb1 | 465 | // Update the new value |
mcm | 2:1d6817048eb1 | 466 | cmd[0] = MLX90614_EMISSIVITY_CORRECTION_COEFFICIENT; |
mcm | 2:1d6817048eb1 | 467 | cmd[1] = _MYROUND( 65535 * myEmissivity.Emissivity ); |
mcm | 2:1d6817048eb1 | 468 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 2, false ); |
mcm | 2:1d6817048eb1 | 469 | } |
mcm | 2:1d6817048eb1 | 470 | } |
mcm | 2:1d6817048eb1 | 471 | else |
mcm | 2:1d6817048eb1 | 472 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 473 | |
mcm | 2:1d6817048eb1 | 474 | |
mcm | 2:1d6817048eb1 | 475 | |
mcm | 2:1d6817048eb1 | 476 | |
mcm | 2:1d6817048eb1 | 477 | if ( aux == I2C_SUCCESS ) |
mcm | 2:1d6817048eb1 | 478 | return MLX90614_SUCCESS; |
mcm | 2:1d6817048eb1 | 479 | else |
mcm | 2:1d6817048eb1 | 480 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 481 | } |
mcm | 2:1d6817048eb1 | 482 | |
mcm | 2:1d6817048eb1 | 483 | |
mcm | 2:1d6817048eb1 | 484 | /** |
mcm | 2:1d6817048eb1 | 485 | * @brief MLX90614_GetIIR ( MLX90614_vector_data_t* ) |
mcm | 2:1d6817048eb1 | 486 | * |
mcm | 2:1d6817048eb1 | 487 | * @details It gets the IIR. |
mcm | 2:1d6817048eb1 | 488 | * |
mcm | 2:1d6817048eb1 | 489 | * @param[in] NaN. |
mcm | 2:1d6817048eb1 | 490 | * |
mcm | 2:1d6817048eb1 | 491 | * @param[out] myIIR: IIR. |
mcm | 2:1d6817048eb1 | 492 | * |
mcm | 2:1d6817048eb1 | 493 | * |
mcm | 2:1d6817048eb1 | 494 | * @return Status of MLX90614_GetIIR. |
mcm | 2:1d6817048eb1 | 495 | * |
mcm | 2:1d6817048eb1 | 496 | * |
mcm | 2:1d6817048eb1 | 497 | * @author Manuel Caballero |
mcm | 2:1d6817048eb1 | 498 | * @date 26/December/2017 |
mcm | 2:1d6817048eb1 | 499 | * @version 26/December/2017 The ORIGIN |
mcm | 2:1d6817048eb1 | 500 | * @pre NaN. |
mcm | 2:1d6817048eb1 | 501 | * @warning NaN. |
mcm | 2:1d6817048eb1 | 502 | */ |
mcm | 2:1d6817048eb1 | 503 | MLX90614::MLX90614_status_t MLX90614::MLX90614_GetIIR ( MLX90614_vector_data_t* myIIR ) |
mcm | 2:1d6817048eb1 | 504 | { |
mcm | 2:1d6817048eb1 | 505 | char cmd[] = { MLX90614_CONFIG_REGISTER_1, 0, 0 }; |
mcm | 2:1d6817048eb1 | 506 | uint32_t aux = 0; |
mcm | 2:1d6817048eb1 | 507 | |
mcm | 2:1d6817048eb1 | 508 | |
mcm | 2:1d6817048eb1 | 509 | // It gets the IIR |
mcm | 2:1d6817048eb1 | 510 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 2:1d6817048eb1 | 511 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 2:1d6817048eb1 | 512 | |
mcm | 2:1d6817048eb1 | 513 | |
mcm | 2:1d6817048eb1 | 514 | myIIR->IIR = ( MLX90614_configregister1_iir_t )( cmd[0] & CONFIGREG1_IIR_MASK ); |
mcm | 2:1d6817048eb1 | 515 | myIIR->PEC = cmd[2]; |
mcm | 2:1d6817048eb1 | 516 | |
mcm | 2:1d6817048eb1 | 517 | |
mcm | 2:1d6817048eb1 | 518 | |
mcm | 2:1d6817048eb1 | 519 | |
mcm | 2:1d6817048eb1 | 520 | if ( aux == I2C_SUCCESS ) |
mcm | 2:1d6817048eb1 | 521 | return MLX90614_SUCCESS; |
mcm | 2:1d6817048eb1 | 522 | else |
mcm | 2:1d6817048eb1 | 523 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 524 | } |
mcm | 2:1d6817048eb1 | 525 | |
mcm | 2:1d6817048eb1 | 526 | |
mcm | 2:1d6817048eb1 | 527 | /** |
mcm | 2:1d6817048eb1 | 528 | * @brief MLX90614_SetIIR ( MLX90614_configregister1_iir_t ) |
mcm | 2:1d6817048eb1 | 529 | * |
mcm | 2:1d6817048eb1 | 530 | * @details It sets the IIR. |
mcm | 2:1d6817048eb1 | 531 | * |
mcm | 2:1d6817048eb1 | 532 | * @param[in] NaN. |
mcm | 2:1d6817048eb1 | 533 | * @param[in] myIIR: IIR. |
mcm | 2:1d6817048eb1 | 534 | * |
mcm | 2:1d6817048eb1 | 535 | * @param[out] NaN. |
mcm | 2:1d6817048eb1 | 536 | * |
mcm | 2:1d6817048eb1 | 537 | * |
mcm | 2:1d6817048eb1 | 538 | * @return Status of MLX90614_SetIIR. |
mcm | 2:1d6817048eb1 | 539 | * |
mcm | 2:1d6817048eb1 | 540 | * |
mcm | 2:1d6817048eb1 | 541 | * @author Manuel Caballero |
mcm | 2:1d6817048eb1 | 542 | * @date 26/December/2017 |
mcm | 2:1d6817048eb1 | 543 | * @version 26/December/2017 The ORIGIN |
mcm | 2:1d6817048eb1 | 544 | * @pre NaN. |
mcm | 2:1d6817048eb1 | 545 | * @warning NaN. |
mcm | 2:1d6817048eb1 | 546 | */ |
mcm | 2:1d6817048eb1 | 547 | MLX90614::MLX90614_status_t MLX90614::MLX90614_SetIIR ( MLX90614_configregister1_iir_t myIIR ) |
mcm | 2:1d6817048eb1 | 548 | { |
mcm | 2:1d6817048eb1 | 549 | char cmd[] = { MLX90614_CONFIG_REGISTER_1, 0, 0 }; |
mcm | 2:1d6817048eb1 | 550 | uint32_t aux = 0; |
mcm | 2:1d6817048eb1 | 551 | uint32_t ii = 0; |
mcm | 2:1d6817048eb1 | 552 | |
mcm | 2:1d6817048eb1 | 553 | |
mcm | 2:1d6817048eb1 | 554 | // It gets the IIR |
mcm | 2:1d6817048eb1 | 555 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 2:1d6817048eb1 | 556 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 2:1d6817048eb1 | 557 | |
mcm | 2:1d6817048eb1 | 558 | // Erase EEPROM |
mcm | 2:1d6817048eb1 | 559 | cmd[2] = cmd[1]; // MSB |
mcm | 2:1d6817048eb1 | 560 | cmd[1] = ( cmd[0] & ~CONFIGREG1_IIR_MASK ); // LSB |
mcm | 2:1d6817048eb1 | 561 | cmd[0] = MLX90614_CONFIG_REGISTER_1; // Command |
mcm | 2:1d6817048eb1 | 562 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 3, false ); |
mcm | 2:1d6817048eb1 | 563 | |
mcm | 2:1d6817048eb1 | 564 | // It takes EEPROM about 5ms to write/read |
mcm | 2:1d6817048eb1 | 565 | do |
mcm | 2:1d6817048eb1 | 566 | { |
mcm | 2:1d6817048eb1 | 567 | cmd[0] = MLX90614_FLAGS; |
mcm | 2:1d6817048eb1 | 568 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 2:1d6817048eb1 | 569 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], 3 ); |
mcm | 2:1d6817048eb1 | 570 | ii++; // Increase the timeout |
mcm | 2:1d6817048eb1 | 571 | } |
mcm | 2:1d6817048eb1 | 572 | while ( ( ( cmd[0] & FLAG_EEBUSY_HIGH ) == FLAG_EEBUSY_HIGH ) && ( ii < MLX90614_TIMEOUT ) ); |
mcm | 2:1d6817048eb1 | 573 | |
mcm | 2:1d6817048eb1 | 574 | |
mcm | 2:1d6817048eb1 | 575 | // If TIMEOUT, exit with failure. |
mcm | 2:1d6817048eb1 | 576 | if ( ii >= MLX90614_TIMEOUT ) |
mcm | 2:1d6817048eb1 | 577 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 578 | else |
mcm | 2:1d6817048eb1 | 579 | { |
mcm | 2:1d6817048eb1 | 580 | // It gets the IIR |
mcm | 2:1d6817048eb1 | 581 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 2:1d6817048eb1 | 582 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 2:1d6817048eb1 | 583 | |
mcm | 2:1d6817048eb1 | 584 | // Update the new value |
mcm | 2:1d6817048eb1 | 585 | cmd[2] = cmd[1]; // MSB |
mcm | 2:1d6817048eb1 | 586 | cmd[1] = ( ( cmd[0] & ~CONFIGREG1_IIR_MASK ) | myIIR ); // LSB |
mcm | 2:1d6817048eb1 | 587 | cmd[0] = MLX90614_CONFIG_REGISTER_1; // Command |
mcm | 2:1d6817048eb1 | 588 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 2, false ); |
mcm | 2:1d6817048eb1 | 589 | } |
mcm | 2:1d6817048eb1 | 590 | |
mcm | 2:1d6817048eb1 | 591 | |
mcm | 2:1d6817048eb1 | 592 | |
mcm | 2:1d6817048eb1 | 593 | |
mcm | 2:1d6817048eb1 | 594 | if ( aux == I2C_SUCCESS ) |
mcm | 2:1d6817048eb1 | 595 | return MLX90614_SUCCESS; |
mcm | 2:1d6817048eb1 | 596 | else |
mcm | 2:1d6817048eb1 | 597 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 598 | } |
mcm | 2:1d6817048eb1 | 599 | |
mcm | 2:1d6817048eb1 | 600 | |
mcm | 2:1d6817048eb1 | 601 | /** |
mcm | 4:c5344a5f3266 | 602 | * @brief MLX90614_GetTemperatureSource ( MLX90614_vector_data_t* ) |
mcm | 4:c5344a5f3266 | 603 | * |
mcm | 4:c5344a5f3266 | 604 | * @details It gets the temperature source. |
mcm | 4:c5344a5f3266 | 605 | * |
mcm | 4:c5344a5f3266 | 606 | * @param[in] NaN |
mcm | 4:c5344a5f3266 | 607 | * |
mcm | 4:c5344a5f3266 | 608 | * @param[out] myTempSource: Temperature source. |
mcm | 4:c5344a5f3266 | 609 | * |
mcm | 4:c5344a5f3266 | 610 | * |
mcm | 4:c5344a5f3266 | 611 | * @return Status of MLX90614_GetTemperatureSource. |
mcm | 4:c5344a5f3266 | 612 | * |
mcm | 4:c5344a5f3266 | 613 | * |
mcm | 4:c5344a5f3266 | 614 | * @author Manuel Caballero |
mcm | 4:c5344a5f3266 | 615 | * @date 26/December/2017 |
mcm | 4:c5344a5f3266 | 616 | * @version 26/December/2017 The ORIGIN |
mcm | 4:c5344a5f3266 | 617 | * @pre NaN. |
mcm | 4:c5344a5f3266 | 618 | * @warning NaN. |
mcm | 4:c5344a5f3266 | 619 | */ |
mcm | 4:c5344a5f3266 | 620 | MLX90614::MLX90614_status_t MLX90614::MLX90614_GetTemperatureSource ( MLX90614_vector_data_t* myTempSource ) |
mcm | 4:c5344a5f3266 | 621 | { |
mcm | 4:c5344a5f3266 | 622 | char cmd[] = { MLX90614_CONFIG_REGISTER_1, 0, 0 }; |
mcm | 4:c5344a5f3266 | 623 | uint32_t aux = 0; |
mcm | 4:c5344a5f3266 | 624 | |
mcm | 4:c5344a5f3266 | 625 | |
mcm | 4:c5344a5f3266 | 626 | // It gets the temperature source |
mcm | 4:c5344a5f3266 | 627 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 4:c5344a5f3266 | 628 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 4:c5344a5f3266 | 629 | |
mcm | 4:c5344a5f3266 | 630 | |
mcm | 4:c5344a5f3266 | 631 | myTempSource->TempSource = ( MLX90614_configregister1_temp_t )( cmd[0] & CONFIGREG1_TEMP_MASK ); |
mcm | 4:c5344a5f3266 | 632 | myTempSource->PEC = cmd[2]; |
mcm | 4:c5344a5f3266 | 633 | |
mcm | 4:c5344a5f3266 | 634 | |
mcm | 4:c5344a5f3266 | 635 | |
mcm | 4:c5344a5f3266 | 636 | |
mcm | 4:c5344a5f3266 | 637 | if ( aux == I2C_SUCCESS ) |
mcm | 4:c5344a5f3266 | 638 | return MLX90614_SUCCESS; |
mcm | 4:c5344a5f3266 | 639 | else |
mcm | 4:c5344a5f3266 | 640 | return MLX90614_FAILURE; |
mcm | 4:c5344a5f3266 | 641 | } |
mcm | 4:c5344a5f3266 | 642 | |
mcm | 4:c5344a5f3266 | 643 | |
mcm | 4:c5344a5f3266 | 644 | /** |
mcm | 4:c5344a5f3266 | 645 | * @brief MLX90614_SetTemperatureSource ( I2C_parameters_t , MLX90614_configregister1_temp_t ) |
mcm | 4:c5344a5f3266 | 646 | * |
mcm | 4:c5344a5f3266 | 647 | * @details It sets the temperature source. |
mcm | 4:c5344a5f3266 | 648 | * |
mcm | 4:c5344a5f3266 | 649 | * @param[in] myTempSource: Temperature source. |
mcm | 4:c5344a5f3266 | 650 | * |
mcm | 4:c5344a5f3266 | 651 | * @param[out] NaN. |
mcm | 4:c5344a5f3266 | 652 | * |
mcm | 4:c5344a5f3266 | 653 | * |
mcm | 4:c5344a5f3266 | 654 | * @return Status of MLX90614_SetTemperatureSource. |
mcm | 4:c5344a5f3266 | 655 | * |
mcm | 4:c5344a5f3266 | 656 | * |
mcm | 4:c5344a5f3266 | 657 | * @author Manuel Caballero |
mcm | 4:c5344a5f3266 | 658 | * @date 26/December/2017 |
mcm | 4:c5344a5f3266 | 659 | * @version 26/December/2017 The ORIGIN |
mcm | 4:c5344a5f3266 | 660 | * @pre NaN. |
mcm | 4:c5344a5f3266 | 661 | * @warning NaN. |
mcm | 4:c5344a5f3266 | 662 | */ |
mcm | 4:c5344a5f3266 | 663 | MLX90614::MLX90614_status_t MLX90614::MLX90614_SetTemperatureSource ( MLX90614_configregister1_temp_t myTempSource ) |
mcm | 4:c5344a5f3266 | 664 | { |
mcm | 4:c5344a5f3266 | 665 | char cmd[] = { MLX90614_CONFIG_REGISTER_1, 0, 0 }; |
mcm | 4:c5344a5f3266 | 666 | uint32_t aux = 0; |
mcm | 4:c5344a5f3266 | 667 | uint32_t ii = 0; |
mcm | 4:c5344a5f3266 | 668 | |
mcm | 4:c5344a5f3266 | 669 | |
mcm | 4:c5344a5f3266 | 670 | // It gets the IIR |
mcm | 4:c5344a5f3266 | 671 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 4:c5344a5f3266 | 672 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 4:c5344a5f3266 | 673 | |
mcm | 4:c5344a5f3266 | 674 | // Erase EEPROM |
mcm | 4:c5344a5f3266 | 675 | cmd[2] = cmd[1]; // MSB |
mcm | 4:c5344a5f3266 | 676 | cmd[1] = ( cmd[0] & ~CONFIGREG1_TEMP_MASK ); // LSB |
mcm | 4:c5344a5f3266 | 677 | cmd[0] = MLX90614_CONFIG_REGISTER_1; // Command |
mcm | 4:c5344a5f3266 | 678 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 3, false ); |
mcm | 4:c5344a5f3266 | 679 | |
mcm | 4:c5344a5f3266 | 680 | // It takes EEPROM about 5ms to write/read |
mcm | 4:c5344a5f3266 | 681 | do |
mcm | 4:c5344a5f3266 | 682 | { |
mcm | 4:c5344a5f3266 | 683 | cmd[0] = MLX90614_FLAGS; |
mcm | 4:c5344a5f3266 | 684 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 4:c5344a5f3266 | 685 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], 3 ); |
mcm | 4:c5344a5f3266 | 686 | ii++; // Increase the timeout |
mcm | 4:c5344a5f3266 | 687 | } |
mcm | 4:c5344a5f3266 | 688 | while ( ( ( cmd[0] & FLAG_EEBUSY_HIGH ) == FLAG_EEBUSY_HIGH ) && ( ii < MLX90614_TIMEOUT ) ); |
mcm | 4:c5344a5f3266 | 689 | |
mcm | 4:c5344a5f3266 | 690 | |
mcm | 4:c5344a5f3266 | 691 | // If TIMEOUT, exit with failure. |
mcm | 4:c5344a5f3266 | 692 | if ( ii >= MLX90614_TIMEOUT ) |
mcm | 4:c5344a5f3266 | 693 | return MLX90614_FAILURE; |
mcm | 4:c5344a5f3266 | 694 | else |
mcm | 4:c5344a5f3266 | 695 | { |
mcm | 4:c5344a5f3266 | 696 | // It gets the IIR |
mcm | 4:c5344a5f3266 | 697 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 4:c5344a5f3266 | 698 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 4:c5344a5f3266 | 699 | |
mcm | 4:c5344a5f3266 | 700 | // Update the new value |
mcm | 4:c5344a5f3266 | 701 | cmd[2] = cmd[1]; // MSB |
mcm | 4:c5344a5f3266 | 702 | cmd[1] = ( ( cmd[0] & ~CONFIGREG1_TEMP_MASK ) | myTempSource ); // LSB |
mcm | 4:c5344a5f3266 | 703 | cmd[0] = MLX90614_CONFIG_REGISTER_1; // Command |
mcm | 4:c5344a5f3266 | 704 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 2, false ); |
mcm | 4:c5344a5f3266 | 705 | } |
mcm | 4:c5344a5f3266 | 706 | |
mcm | 4:c5344a5f3266 | 707 | |
mcm | 4:c5344a5f3266 | 708 | |
mcm | 4:c5344a5f3266 | 709 | |
mcm | 4:c5344a5f3266 | 710 | if ( aux == I2C_SUCCESS ) |
mcm | 4:c5344a5f3266 | 711 | return MLX90614_SUCCESS; |
mcm | 4:c5344a5f3266 | 712 | else |
mcm | 4:c5344a5f3266 | 713 | return MLX90614_FAILURE; |
mcm | 4:c5344a5f3266 | 714 | } |
mcm | 4:c5344a5f3266 | 715 | |
mcm | 4:c5344a5f3266 | 716 | |
mcm | 4:c5344a5f3266 | 717 | /** |
mcm | 2:1d6817048eb1 | 718 | * @brief MLX90614_GetFLAGS ( MLX90614_vector_data_t* ) |
mcm | 2:1d6817048eb1 | 719 | * |
mcm | 2:1d6817048eb1 | 720 | * @details It gets the flags. |
mcm | 2:1d6817048eb1 | 721 | * |
mcm | 2:1d6817048eb1 | 722 | * @param[in] NaN. |
mcm | 2:1d6817048eb1 | 723 | * |
mcm | 2:1d6817048eb1 | 724 | * @param[out] myFlags: Flags. |
mcm | 2:1d6817048eb1 | 725 | * |
mcm | 2:1d6817048eb1 | 726 | * |
mcm | 2:1d6817048eb1 | 727 | * @return Status of MLX90614_GetFLAGS. |
mcm | 2:1d6817048eb1 | 728 | * |
mcm | 2:1d6817048eb1 | 729 | * |
mcm | 2:1d6817048eb1 | 730 | * @author Manuel Caballero |
mcm | 2:1d6817048eb1 | 731 | * @date 26/December/2017 |
mcm | 2:1d6817048eb1 | 732 | * @version 26/December/2017 The ORIGIN |
mcm | 2:1d6817048eb1 | 733 | * @pre NaN. |
mcm | 2:1d6817048eb1 | 734 | * @warning NaN. |
mcm | 2:1d6817048eb1 | 735 | */ |
mcm | 2:1d6817048eb1 | 736 | MLX90614::MLX90614_status_t MLX90614::MLX90614_GetFLAGS ( MLX90614_vector_data_t* myFlags ) |
mcm | 2:1d6817048eb1 | 737 | { |
mcm | 2:1d6817048eb1 | 738 | char cmd[] = { MLX90614_FLAGS, 0, 0 }; |
mcm | 2:1d6817048eb1 | 739 | uint32_t aux = 0; |
mcm | 2:1d6817048eb1 | 740 | |
mcm | 2:1d6817048eb1 | 741 | |
mcm | 2:1d6817048eb1 | 742 | // It gets the flags |
mcm | 2:1d6817048eb1 | 743 | aux = _i2c.write ( _MLX90614_Addr, &cmd[0], 1, true ); |
mcm | 2:1d6817048eb1 | 744 | aux = _i2c.read ( _MLX90614_Addr, &cmd[0], sizeof( cmd )/sizeof( cmd[0] ) ); |
mcm | 2:1d6817048eb1 | 745 | |
mcm | 2:1d6817048eb1 | 746 | |
mcm | 2:1d6817048eb1 | 747 | myFlags->Flags = ( MLX90614_flags_t )cmd[0]; |
mcm | 2:1d6817048eb1 | 748 | myFlags->PEC = cmd[2]; |
mcm | 2:1d6817048eb1 | 749 | |
mcm | 2:1d6817048eb1 | 750 | |
mcm | 2:1d6817048eb1 | 751 | |
mcm | 2:1d6817048eb1 | 752 | |
mcm | 2:1d6817048eb1 | 753 | if ( aux == I2C_SUCCESS ) |
mcm | 2:1d6817048eb1 | 754 | return MLX90614_SUCCESS; |
mcm | 2:1d6817048eb1 | 755 | else |
mcm | 2:1d6817048eb1 | 756 | return MLX90614_FAILURE; |
mcm | 2:1d6817048eb1 | 757 | } |