@@ -91,7 +91,7 @@ bool MCP9600::setAmbientResolution(Ambient_Resolution res){
9191 bitWrite (config, 7 , res); // set the bit that controls the ambient (cold) junction resolution
9292
9393 bool failed = writeSingleRegister (DEVICE_CONFIG, config); // write new config register to MCP9600
94- failed & = (readSingleRegister (DEVICE_CONFIG) != config); // double check that it was set properly
94+ failed | = (readSingleRegister (DEVICE_CONFIG) != config); // double check that it was set properly
9595 return failed; // return 1 if the write failed or the register wasn't properly set, 0 otherwise
9696}
9797
@@ -108,7 +108,7 @@ bool MCP9600::setThermocoupleResolution(Thermocouple_Resolution res){
108108 bitWrite (config, 5 , lowResolutionBit); // set 5th bit of config register to 0th bit of the resolution
109109
110110 bool failed = writeSingleRegister (DEVICE_CONFIG, config); // write new config register to MCP9600
111- failed & = (readSingleRegister (DEVICE_CONFIG) != config); // double check that it was written properly
111+ failed | = (readSingleRegister (DEVICE_CONFIG) != config); // double check that it was written properly
112112 return failed; // return 1 if the write failed or the register wasn't properly set, 0 otherwise
113113}
114114
@@ -143,17 +143,27 @@ uint8_t MCP9600::setFilterCoeffecients(uint8_t coeffecient){
143143 if (coeffecient > 7 ) return 3 ; // return immediately if the value is too big
144144
145145 uint8_t config = readSingleRegister (THERMO_SENSOR_CONFIG);
146- config = config >> 3 ;
147- config = config << 3 ;
148- config |= coeffecient; // set the necessary bits in the config register
146+ bitWrite (coeffecient, 3 , bitRead (config, 3 ));
147+ bitWrite (coeffecient, 4 , bitRead (config, 3 ));
148+ bitWrite (coeffecient, 5 , bitRead (config, 3 ));
149+ bitWrite (coeffecient, 6 , bitRead (config, 3 ));
150+ bitWrite (coeffecient, 7 , bitRead (config, 3 ));
149151
150- writeSingleRegister (THERMO_SENSOR_CONFIG, config);
151- return ;
152+ // config = config >> 3;
153+ // config = config << 3;
154+ // config |= coeffecient; //set the necessary bits in the config register
155+
156+ return writeSingleRegister (THERMO_SENSOR_CONFIG, coeffecient);
152157}
153158
154159uint8_t MCP9600::getFilterCoeffecients (){
155160 uint8_t config = readSingleRegister (THERMO_SENSOR_CONFIG);
156- return ((config << 5 ) >> 5 ); // clear the non-filter-coeffecients data in the config register
161+ uint8_t coeff = 0 ;
162+ bitWrite (coeff, 0 , bitRead (config, 0 ));
163+ bitWrite (coeff, 1 , bitRead (config, 1 ));
164+ bitWrite (coeff, 2 , bitRead (config, 2 ));
165+
166+ return coeff; // clear the non-filter-coeffecients data in the config register
157167}
158168
159169bool MCP9600::setBurstSamples (Burst_Sample samples){
@@ -166,7 +176,7 @@ bool MCP9600::setBurstSamples(Burst_Sample samples){
166176 bitWrite (config, 2 , lowResolutionBit); // write 0th bit of samples to 2nd of config
167177
168178 bool failed = writeSingleRegister (DEVICE_CONFIG, config); // write new config register to MCP9600
169- failed & = (readSingleRegister (DEVICE_CONFIG) != config); // double check that it was written properly
179+ failed | = (readSingleRegister (DEVICE_CONFIG) != config); // double check that it was written properly
170180 return failed; // return 1 if the write failed or the register wasn't properly set, 0 otherwise
171181}
172182
@@ -190,7 +200,11 @@ bool MCP9600::burstAvailable(){
190200bool MCP9600::startBurst (){
191201 uint8_t status = readSingleRegister (SENSOR_STATUS);
192202 bitWrite (status, 7 , 0 ); // clear the 7th bit of the status register, and send over I2C
193- return writeSingleRegister (SENSOR_STATUS, status); // return whether the write was successful
203+
204+ bool failed = writeSingleRegister (SENSOR_STATUS, status); // return whether the write was successful
205+ failed |= setShutdownMode (BURST);
206+
207+ return failed;
194208}
195209
196210bool MCP9600::setShutdownMode (Shutdown_Mode mode){
@@ -199,13 +213,16 @@ bool MCP9600::setShutdownMode(Shutdown_Mode mode){
199213 config |= mode;
200214
201215 bool failed = writeSingleRegister (DEVICE_CONFIG, config); // write new config register to MCP9600
202- failed & = (readSingleRegister (DEVICE_CONFIG) != config); // double check that it was written properly
216+ failed | = (readSingleRegister (DEVICE_CONFIG) != config); // double check that it was written properly
203217 return failed; // return 1 if the write failed or the register wasn't properly set, 0 otherwise
204218}
205219
206220Shutdown_Mode MCP9600::getShutdownMode (){
207221 uint8_t config = readSingleRegister (DEVICE_CONFIG);
208- return ((config << 6 ) >> 6 ); // clear all bits except the last two and return
222+ uint8_t mode = 0 ;
223+ bitWrite (mode, 0 , bitRead (config, 0 ));
224+ bitWrite (mode, 1 , bitRead (config, 1 ));
225+ return mode; // clear all bits except the last two and return
209226}
210227
211228/* ------------------------- Internal I2C Abstraction ---------------- */
0 commit comments