From a3d0955a928d53d59191e4a6d200f2d5f3c90a9c Mon Sep 17 00:00:00 2001 From: AlessandroAU Date: Tue, 16 Jun 2020 03:43:07 +1000 Subject: [PATCH] adds SX1276_DetectChip() SX1276_DetectChip() will detect if the sx1276 is installed and talking properly via looking for a version 0x12 match in reg 0x42. --- Multiprotocol/SX1276_SPI.ino | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/Multiprotocol/SX1276_SPI.ino b/Multiprotocol/SX1276_SPI.ino index c576d40..64b05d9 100644 --- a/Multiprotocol/SX1276_SPI.ino +++ b/Multiprotocol/SX1276_SPI.ino @@ -42,6 +42,41 @@ uint8_t SX1276_Reset() return 0; } +bool SX1276_DetectChip() //to be called after reset, verfies the chip has been detected +{ + #define MaxAttempts 5 + uint8_t i = 0; + bool chipFound = false; + while ((i < MaxAttempts) && !chipFound) + { + uint8_t ChipVersion = SX1276_ReadReg(0x42); + if (ChipVersion == 0x12) + { + debugln("SX1276 reg version=%d", ChipVersion); + chipFound = true; + } + else + { + debug("SX1276 not found! attempts: "); + debug(i + 1); + debug(" of "); + debug(MaxAttempts); + debugln(" SX1276 reg version=%d", ChipVersion); + i++; + } + } + if (!chipFound) + { + debugln("SX1276 not detected!!!"); + return false; + } + else + { + debugln("Found SX1276 Device!"); + return true; + } +} + void SX1276_SetTxRxMode(uint8_t mode) { #ifdef SX1276_TXEN_pin @@ -198,4 +233,4 @@ void SX1276_WritePayloadToFifo(uint8_t* payload, uint8_t length) SX1276_WriteRegisterMulti(SX1276_00_FIFO, payload, length); } -#endif \ No newline at end of file +#endif