@@ -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