From 36afff855dcd41f0e6860c6ffb8b51fa24c50e13 Mon Sep 17 00:00:00 2001 From: jgromes Date: Fri, 20 Nov 2020 17:53:03 +0100 Subject: [PATCH] [Si443x] Added method to read version register --- src/modules/Si443x/Si443x.cpp | 10 +++++++--- src/modules/Si443x/Si443x.h | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/modules/Si443x/Si443x.cpp b/src/modules/Si443x/Si443x.cpp index 0e6d695a..4a424d69 100644 --- a/src/modules/Si443x/Si443x.cpp +++ b/src/modules/Si443x/Si443x.cpp @@ -572,6 +572,10 @@ uint8_t Si443x::random() { return(randByte); } +int16_t Si443x::getChipVersion() { + return(_mod->SPIgetRegValue(SI443X_REG_DEVICE_VERSION)); +} + int16_t Si443x::setFrequencyRaw(float newFreq) { // set mode to standby int16_t state = standby(); @@ -605,7 +609,7 @@ bool Si443x::findChip() { reset(); // check version register - uint8_t version = _mod->SPIreadRegister(SI443X_REG_DEVICE_VERSION); + int16_t version = getChipVersion(); if(version == SI443X_DEVICE_VERSION) { flagFound = true; } else { @@ -614,8 +618,8 @@ bool Si443x::findChip() { RADIOLIB_DEBUG_PRINT(i + 1); RADIOLIB_DEBUG_PRINT(F(" of 10 tries) SI443X_REG_DEVICE_VERSION == ")); - char buffHex[5]; - sprintf(buffHex, "0x%02X", version); + char buffHex[12]; + sprintf(buffHex, "0x%04X", version); RADIOLIB_DEBUG_PRINT(buffHex); RADIOLIB_DEBUG_PRINT(F(", expected 0x00")); RADIOLIB_DEBUG_PRINTLN(SI443X_DEVICE_VERSION, HEX); diff --git a/src/modules/Si443x/Si443x.h b/src/modules/Si443x/Si443x.h index 9064d4ca..f187d291 100644 --- a/src/modules/Si443x/Si443x.h +++ b/src/modules/Si443x/Si443x.h @@ -792,6 +792,13 @@ class Si443x: public PhysicalLayer { */ uint8_t random(); + /*! + \brief Read version SPI register. Should return SI443X_DEVICE_VERSION (0x06) if Si443x is connected and working. + + \returns Version register contents or \ref status_codes + */ + int16_t getChipVersion(); + #ifndef RADIOLIB_GODMODE protected: #endif