// Returns true iff RFM22 (or RFM23) appears to be correctly connected. bool RFM22CheckConnected() { const bool neededEnable = powerUpSPIIfDisabled(); bool isOK = false; const uint8_t rType = _RFM22ReadReg8Bit(0); // May read as 0 if not connected at all. if(RFM22_SUPPORTED_DEVICE_TYPE == rType) { const uint8_t rVersion = _RFM22ReadReg8Bit(1); if(RFM22_SUPPORTED_DEVICE_VERSION == rVersion) { isOK = true; } #if 1 && defined(DEBUG) else { DEBUG_SERIAL_PRINT_FLASHSTRING("RFM22 bad version: "); DEBUG_SERIAL_PRINTFMT(rVersion, HEX); DEBUG_SERIAL_PRINTLN(); } #endif } #if 1 && defined(DEBUG) else { DEBUG_SERIAL_PRINT_FLASHSTRING("RFM22 bad type: "); DEBUG_SERIAL_PRINTFMT(rType, HEX); DEBUG_SERIAL_PRINTLN(); } #endif if(neededEnable) { powerDownSPI(); } return(isOK); }
// Configure the radio from a list of register/value pairs in readonly PROGMEM/Flash, terminating with an 0xff register value. // NOTE: argument is not a pointer into SRAM, it is into PROGMEM! // Could optimise case where multiple values are for successive RFM22 registers by using burst write. void RFM22RegisterBlockSetup(const uint8_t registerValues[][2]) { const bool neededEnable = powerUpSPIIfDisabled(); for( ; ; ) { const uint8_t reg = pgm_read_byte(&(registerValues[0][0])); const uint8_t val = pgm_read_byte(&(registerValues[0][1])); if(0xff == reg) { break; } #if 0 && defined(DEBUG) DEBUG_SERIAL_PRINT_FLASHSTRING("RFM22 reg 0x"); DEBUG_SERIAL_PRINTFMT(reg, HEX); DEBUG_SERIAL_PRINT_FLASHSTRING(" = 0x"); DEBUG_SERIAL_PRINTFMT(val, HEX); DEBUG_SERIAL_PRINTLN(); #endif _RFM22WriteReg8Bit(reg, val); ++registerValues; } if(neededEnable) { powerDownSPI(); } }
// Initialise the device (if any) before first use. // Returns true iff successful. // Uses specified order DS18B20 found on bus. // May need to be reinitialised if precision changed. bool TemperatureC16_DS18B20::init() { // DEBUG_SERIAL_PRINTLN_FLASHSTRING("DS18B20 init..."); bool found = false; // Ensure no bad search state. minOW.reset_search(); for( ; ; ) { if(!minOW.search(address)) { minOW.reset_search(); // Be kind to any other OW search user. break; } #if 0 && defined(DEBUG) // Found a device. DEBUG_SERIAL_PRINT_FLASHSTRING("addr:"); for(int i = 0; i < 8; ++i) { DEBUG_SERIAL_PRINT(' '); DEBUG_SERIAL_PRINTFMT(address[i], HEX); } DEBUG_SERIAL_PRINTLN(); #endif if(0x28 != address[0]) { #if 0 && defined(DEBUG) DEBUG_SERIAL_PRINTLN_FLASHSTRING("Not a DS18B20, skipping..."); #endif continue; } #if 0 && defined(DEBUG) DEBUG_SERIAL_PRINTLN_FLASHSTRING("Setting precision..."); #endif minOW.reset(); // Write scratchpad/config minOW.select(address); minOW.write(0x4e); minOW.write(0); // Th: not used. minOW.write(0); // Tl: not used. // MinOW.write(DS1820_PRECISION | 0x1f); // Config register; lsbs all 1. minOW.write(((precision - 9) << 6) | 0x1f); // Config register; lsbs all 1. // Found one and configured it! found = true; } // Search has been run (whether DS18B20 was found or not). initialised = true; if(!found) { // DEBUG_SERIAL_PRINTLN_FLASHSTRING("DS18B20 not found"); address[0] = 0; // Indicate that no DS18B20 was found. } return(found); }