@@ -83,8 +83,8 @@ bool MCP9600::checkDeviceID()
8383bool MCP9600::resetToDefaults ()
8484{
8585 bool success = writeSingleRegister (SENSOR_STATUS, 0x00 );
86- success |= writeSingleRegister (THERMO_SENSOR_CONFIG, 0x00 );
87- success |= writeSingleRegister (DEVICE_CONFIG, 0x00 );
86+ success |= writeSingleRegister (THERMO_SENSOR_CONFIG, 0x00 ); // Type-K, Filter off
87+ success |= writeSingleRegister (DEVICE_CONFIG, 0x00 ); // 0.0625C, 18-bit, 1 sample, normal operation
8888 success |= writeSingleRegister (ALERT1_CONFIG, 0x00 );
8989 success |= writeSingleRegister (ALERT2_CONFIG, 0x00 );
9090 success |= writeSingleRegister (ALERT3_CONFIG, 0x00 );
@@ -216,7 +216,7 @@ uint8_t MCP9600::setThermocoupleType(Thermocouple_Type type)
216216Thermocouple_Type MCP9600::getThermocoupleType ()
217217{
218218 uint8_t config = readSingleRegister (THERMO_SENSOR_CONFIG);
219- return static_cast <Thermocouple_Type>(config >> 4 ); // clear the non- thermocouple-type bits in the config registe
219+ return static_cast <Thermocouple_Type>(( config >> 4 ) & 0x07 ) ; // shift the thermocouple-type bits into the 3 LSB
220220}
221221
222222uint8_t MCP9600::setFilterCoefficient (uint8_t coefficient)
@@ -226,14 +226,10 @@ uint8_t MCP9600::setFilterCoefficient(uint8_t coefficient)
226226
227227 uint8_t config = readSingleRegister (THERMO_SENSOR_CONFIG);
228228 bitWrite (coefficient, 3 , bitRead (config, 3 ));
229- bitWrite (coefficient, 4 , bitRead (config, 3 ));
230- bitWrite (coefficient, 5 , bitRead (config, 3 ));
231- bitWrite (coefficient, 6 , bitRead (config, 3 ));
232- bitWrite (coefficient, 7 , bitRead (config, 3 ));
233-
234- // config = config >> 3;
235- // config = config << 3;
236- // config |= coefficient; //set the necessary bits in the config register
229+ bitWrite (coefficient, 4 , bitRead (config, 4 ));
230+ bitWrite (coefficient, 5 , bitRead (config, 5 ));
231+ bitWrite (coefficient, 6 , bitRead (config, 6 ));
232+ bitWrite (coefficient, 7 , bitRead (config, 7 ));
237233
238234 return writeSingleRegister (THERMO_SENSOR_CONFIG, coefficient);
239235}
@@ -298,7 +294,7 @@ bool MCP9600::setShutdownMode(Shutdown_Mode mode)
298294{
299295 uint8_t config = readSingleRegister (DEVICE_CONFIG);
300296 config = (config >> 2 ) << 2 ; // clear last two bits of the device config register
301- config |= mode;
297+ config |= mode & 0x03 ;
302298
303299 bool failed = writeSingleRegister (DEVICE_CONFIG, config); // write new config register to MCP9600
304300 failed |= (readSingleRegister (DEVICE_CONFIG) != config); // double check that it was written properly
0 commit comments