@@ -839,10 +839,10 @@ void configureDevice(node * temp)
839839 TMP102 *sensor = (TMP102 *)temp->classPtr ;
840840 struct_TMP102 *sensorSetting = (struct_TMP102 *)temp->configPtr ;
841841
842- // JWS TODO replace with initalization code for TMP102 if needed?
843- // sensor->setConversionAverageMode(sensorSetting->conversionAverageMode);
844- // sensor->setConversionCycleBit(sensorSetting->conversionCycle);
845- // sensor->setContinuousConversionMode();
842+ // JWS - I did not initalize the TMP102 sensor, as they appear to
843+ // work just fine with no special initalization code.
844+
845+
846846 }
847847 break ;
848848 case DEVICE_TEMPERATURE_TMP117:
@@ -1518,21 +1518,54 @@ deviceType_e testDevice(uint8_t i2cAddress, uint8_t muxAddress, uint8_t portNumb
15181518 if (sensor.begin (i2cAddress, qwiic) == true ) // Address, Wire port
15191519 return (DEVICE_TEMPERATURE_TMP117);
15201520
1521- // Confidence: Low - only does a simple isConnected. Not a problem with TMP117, but it
1522- // will probably detect a ADS1015 as a TMP102. We need to figure out a way to discriminate between
1523- // those two devices (when a TMP102 is misdetected as a ADS1015, all 4 values are always equal, maybe this will help?)
1524- // For development purposes, listing before the ADS1015 so that I can develop/test and make my TMP102's work.
1521+
1522+
1523+
1524+
1525+ // Confidence: Medium - does a simple isConnected check, and then tests that two bits are read/write to disambiguate
1526+ // from the TMP102 sensor, where those two bits are read only 11.
1527+ ADS1015 sensor1;
1528+ if (sensor1.begin (i2cAddress, qwiic) == true ) // Address, Wire port
1529+ {
1530+ // Peek at the current config register (same 01 pointer addr as the TMP102)
1531+ uint16_t config = sensor1.readRegister (ADS1015_POINTER_CONFIG);
1532+
1533+ // Write zeros to the MUX[2:1] bits of the ADS1015 (read/write bits) which
1534+ // happen to be in the same place as the R1/R0 bits of the TMP102 (and
1535+ // are read only 11 on the TMP102
1536+ uint16_t newConfig = config & 0x9FFF ; // 0x9FFF is 1001 1111 1111 1111 so it zeros out those two bits
1537+
1538+ // SerialPrintf2("ADS1015 detect, newconfig is:: %x \r\n", newConfig);
1539+
1540+
1541+ sensor1.writeRegister (ADS1015_POINTER_CONFIG, newConfig);
1542+
1543+ // Read back to see if our changes were recorded (ADS1015) or not (TMP102)
1544+ newConfig = sensor1.readRegister (ADS1015_POINTER_CONFIG);
1545+
1546+
1547+ // SerialPrintf2("ADS105 detect, after write/read cycle, config is: %x \r\n", newConfig);
1548+
1549+
1550+ // Write the original config back to restore the correct state.
1551+ sensor1.writeRegister (ADS1015_POINTER_CONFIG, config);
1552+
1553+ // Check to see if the bits we wrote zero stayed at 00 (ADS1015) or returned as
1554+ // 1's because it's actually a TMP102 or some other chip with read only bits
1555+ // in that spot...
1556+ if ( (newConfig & 0x6000 ) == 0 ) // 0x6000 is 0110 0000 0000 0000 so it zeros out all bits except the two we are interested in.
1557+ {
1558+ // Our cannary bits correctly stayed set at zero! Write successful, assume it is a ADS1015
1559+ return (DEVICE_ADS1015);
1560+
1561+ }
1562+ // Otherwise, fall through to the TMP102 test below, which just assumes anything on the correct address is in fact a TMP102 sensor...
1563+ } // end if there is a device on this address.
1564+
1565+ // Confidence: Low - only does a simple isConnected.
15251566 TMP102 sensor2;
15261567 if (sensor2.begin (i2cAddress, qwiic) == true ) // Address, Wire port
15271568 return (DEVICE_TEMPERATURE_TMP102);
1528-
1529- // JWS WARNING - shadowed by above TMP102 test, need to find out a way to discriminate between the two chips via their behavior, OR
1530- // allow user to select which it is via menu.
1531- //
1532- // Confidence: Low - only does a simple isConnected
1533- ADS1015 sensor1;
1534- if (sensor1.begin (i2cAddress, qwiic) == true ) // Address, Wire port
1535- return (DEVICE_ADS1015);
15361569 }
15371570 break ;
15381571 case 0x55 :
0 commit comments