Skip to content

Commit 4faf64c

Browse files
committed
Restructuring detectQwiicDevices so that the MCP9600 is detected correctly
1 parent 8aef181 commit 4faf64c

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

Firmware/OpenLog_Artemis/autoDetect.ino

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,7 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
10401040
break;
10411041
case 0x60:
10421042
{
1043+
//Always do the MCP9600 first. It's fussy...
10431044
//Confidence: High - Checks 8bit ID
10441045
MCP9600 sensor;
10451046
if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port
@@ -1053,6 +1054,7 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
10531054
break;
10541055
case 0x61:
10551056
{
1057+
//Always do the MCP9600 first. It's fussy...
10561058
//Confidence: High - Checks 8bit ID
10571059
MCP9600 sensor;
10581060
if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port
@@ -1067,6 +1069,7 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
10671069
break;
10681070
case 0x62:
10691071
{
1072+
//Always do the MCP9600 first. It's fussy...
10701073
//Confidence: High - Checks 8bit ID
10711074
MCP9600 sensor;
10721075
if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port
@@ -1075,6 +1078,7 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
10751078
break;
10761079
case 0x63:
10771080
{
1081+
//Always do the MCP9600 first. It's fussy...
10781082
//Confidence: High - Checks 8bit ID
10791083
MCP9600 sensor;
10801084
if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port
@@ -1083,6 +1087,7 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
10831087
break;
10841088
case 0x64:
10851089
{
1090+
//Always do the MCP9600 first. It's fussy...
10861091
//Confidence: High - Checks 8bit ID
10871092
MCP9600 sensor;
10881093
if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port
@@ -1091,6 +1096,7 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
10911096
break;
10921097
case 0x65:
10931098
{
1099+
//Always do the MCP9600 first. It's fussy...
10941100
//Confidence: High - Checks 8bit ID
10951101
MCP9600 sensor;
10961102
if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port
@@ -1099,6 +1105,7 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
10991105
break;
11001106
case 0x66:
11011107
{
1108+
//Always do the MCP9600 first. It's fussy...
11021109
//Confidence: High - Checks 8bit ID
11031110
MCP9600 sensor;
11041111
if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port
@@ -1107,6 +1114,7 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
11071114
break;
11081115
case 0x67:
11091116
{
1117+
//Always do the MCP9600 first. It's fussy...
11101118
//Confidence: High - Checks 8bit ID
11111119
MCP9600 sensor;
11121120
if (sensor.begin(i2cAddress, qwiic) == true) //Address, Wire port

Firmware/OpenLog_Artemis/menuAttachedDevices.ino

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,15 @@ bool detectQwiicDevices()
4242

4343
waitForQwiicBusPowerDelay(); // Wait while the qwiic devices power up
4444

45-
//Do a prelim scan to see if anything is out there
46-
for (uint8_t address = 1 ; address < 127 ; address++)
47-
{
48-
qwiic.beginTransmission(address);
49-
if (qwiic.endTransmission() == 0)
50-
{
51-
somethingDetected = true;
52-
if (settings.printDebugMessages == true)
53-
Serial.printf("detectQwiicDevices: something detected at address 0x%02X\r\n", address);
54-
break;
55-
}
56-
}
57-
if (somethingDetected == false) return (false);
45+
// Note: The MCP9600 (Qwiic Thermocouple) is a fussy device. If we use beginTransmission + endTransmission more than once
46+
// the second and subsequent times will fail. The MCP9600 only ACKs the first time. The MCP9600 also appears to be able to
47+
// lock up the I2C bus if you don't discover it and then begin it in one go...
48+
// The following code has been restructured to try and keep the MCP9600 happy.
5849

59-
Serial.println(F("Identifying Qwiic Devices..."));
50+
Serial.println(F("Identifying Qwiic Muxes..."));
6051

6152
//First scan for Muxes. Valid addresses are 0x70 to 0x77 (112 to 119).
6253
//If any are found, they will be begin()'d causing their ports to turn off
63-
printDebug("detectQwiicDevices: scanning for multiplexers\r\n");
6454
uint8_t muxCount = 0;
6555
for (uint8_t address = 0x70 ; address < 0x78 ; address++)
6656
{
@@ -72,6 +62,9 @@ bool detectQwiicDevices()
7262
// digitalWrite(PIN_LOGIC_DEBUG, LOW);
7363
// digitalWrite(PIN_LOGIC_DEBUG, HIGH);
7464
//}
65+
somethingDetected = true;
66+
if (settings.printDebugMessages == true)
67+
Serial.printf("detectQwiicDevices: something detected at address 0x%02X\r\n", address);
7568
deviceType_e foundType = testMuxDevice(address, 0, 0); //No mux or port numbers for this test
7669
if (foundType == DEVICE_MULTIPLEXER)
7770
{
@@ -82,6 +75,7 @@ bool detectQwiicDevices()
8275
}
8376
}
8477
}
78+
8579
if (muxCount > 0)
8680
{
8781
if (settings.printDebugMessages == true)
@@ -92,17 +86,20 @@ bool detectQwiicDevices()
9286
else
9387
Serial.println(F(" multiplexers"));
9488
}
95-
beginQwiicDevices(); //Because we are about to use a multiplexer, begin() the muxes.
89+
beginQwiicDevices(); //begin() the muxes to disable their ports
9690
}
9791

98-
//Before going into sub branches, complete the scan of the main branch for all devices
99-
printDebug("detectQwiicDevices: scanning main bus\r\n");
92+
//Before going into mux sub branches, scan the main branch for all remaining devices
93+
Serial.println(F("Identifying Qwiic Devices..."));
10094
bool foundMS8607 = false; // The MS8607 appears as two devices (MS8607 and MS5637). We need to skip the MS5637 if we have found a MS8607.
10195
for (uint8_t address = 1 ; address < 127 ; address++)
10296
{
10397
qwiic.beginTransmission(address);
10498
if (qwiic.endTransmission() == 0)
10599
{
100+
somethingDetected = true;
101+
if (settings.printDebugMessages == true)
102+
Serial.printf("detectQwiicDevices: something detected at address 0x%02X\r\n", address);
106103
deviceType_e foundType = testDevice(address, 0, 0); //No mux or port numbers for this test
107104
if (foundType != DEVICE_UNKNOWN_DEVICE)
108105
{
@@ -112,7 +109,7 @@ bool detectQwiicDevices()
112109
}
113110
else
114111
{
115-
if (addDevice(foundType, address, 0, 0) == true) //Records this device. //Returns false if device was already recorded.
112+
if (addDevice(foundType, address, 0, 0) == true) //Records this device. //Returns false if mux/device was already recorded.
116113
{
117114
if (settings.printDebugMessages == true)
118115
Serial.printf("detectQwiicDevices: added %s at address 0x%02X\r\n", getDeviceName(foundType), address);
@@ -126,6 +123,8 @@ bool detectQwiicDevices()
126123
}
127124
}
128125

126+
if (somethingDetected == false) return (false);
127+
129128
//If we have muxes, begin scanning their sub nets
130129
if (muxCount > 0)
131130
{
@@ -164,6 +163,9 @@ bool detectQwiicDevices()
164163
qwiic.beginTransmission(address);
165164
if (qwiic.endTransmission() == 0)
166165
{
166+
// We don't need to do anything special for the MCP9600 here, because we can guarantee that beginTransmission + endTransmission
167+
// have only been used once for each MCP9600 address
168+
167169
somethingDetected = true;
168170

169171
deviceType_e foundType = testDevice(address, muxNode->address, portNumber);

0 commit comments

Comments
 (0)