Skip to content

Commit 399d721

Browse files
committed
v1.0.6 - Update setFilterCoefficient
1 parent d7c57b2 commit 399d721

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SparkFun MCP9600 Arduino Library [![Build Status](https://travis-ci.org/sparkfun/SparkFun_MCP9600_Arduino_Library.svg?branch=master)](https://travis-ci.org/sparkfun/SparkFun_MCP9600_Arduino_Library)
1+
SparkFun MCP9600 Arduino Library
22
========================================
33

44
<table class="table table-hover table-striped table-bordered">

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun MCP9600 Thermocouple Library
2-
version=1.0.5
2+
version=1.0.6
33
author=SparkFun Electronics <techsupport@sparkfun.com>
44
maintainer=Fischer Moseley <fischer.moseley@sparkfun.com>
55
sentence=Driver for Microchip's MCP9600 Thermocouple Amplifier.

src/SparkFun_MCP9600.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ bool MCP9600::checkDeviceID()
8383
bool 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)
216216
Thermocouple_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

222222
uint8_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

Comments
 (0)