bool FLC100::initialise(uint8_t pp, uint8_t adcAddressList[numAxes], uint8_t adcChannelList[numAxes], uint8_t adcResolutionList[numAxes], uint8_t adcGainList[numAxes]) { powerPin = pp; pinMode(powerPin, OUTPUT); pinMode(FLC100_DUMP_CHARGE_PIN, OUTPUT); digitalWrite(FLC100_DUMP_CHARGE_PIN, HIGH); uint8_t pud_50ms = eeprom_read_byte((uint8_t*)FLC100_POWER_UP_DELAY_50MS); if (pud_50ms != 0xFF) powerUpDelay_ms = 50 * pud_50ms; // Turn on 5V supply so that the ADC can be probed. Ensure some // delay if set to zero (always on mode) digitalWrite(powerPin, HIGH); delay.start((powerUpDelay_ms ? powerUpDelay_ms : defaultPowerUpDelay_ms), AsyncDelay::MILLIS); // Reset all MCP342x devices MCP342x::generalCallReset(); bool r = true; // Autoprobe to check ADCs are actually present for (int i = 0; i < numAxes; ++i) { adc[i] = MCP342x(adcAddressList[i]); adcConfig[i] = MCP342x::Config(adcChannelList[i], false, adcResolutionList[i], adcGainList[i]); if (adc[i].autoprobe(&adcAddressList[i], 1)) adcPresent[i] = true; else { adcPresent[i] = false; r = false; } } tempConfig = MCP342x::Config(FLC100_TEMPERATURE_CHANNEL, false, 16, 1); return r; }
#endif ISR(WDT_vect){ Sleepy::watchdogEvent();} // set watchdog for Sleepy float getTemperature(); int32_t getSensorValue(); /*==============|| EEPROM ||==============*/ uint16_t EEPROM_ADDR = 0; //Start of data storage float vRef; float temperature; /*==============|| ADC ||==============*/ // 0x68 is the default address for all MCP342x devices uint8_t address = 0x68; MCP342x adc = MCP342x(address); MCP342x::Config config(MCP342x::channel1, MCP342x::oneShot, MCP342x::resolution16, MCP342x::gain1); MCP342x::Config status;// Configuration/status read back from the ADC void setup() { #ifdef SERIAL_EN Serial.begin(SERIAL_BAUD); #endif pinMode(LED, OUTPUT); // Set LED Mode digitalWrite(LED, HIGH); // --| Initialize Devices |-- MCP342x::generalCallReset(); delay(1); // MC342x needs 300us to settle