From 7177242d8084b8722b27e24737e99d40fbfa0580 Mon Sep 17 00:00:00 2001 From: Robert Klajko Date: Sun, 18 Jul 2021 21:43:30 +0200 Subject: [PATCH] Missing lora_initialized() function implemnted. [RK, 2021.07.18] --- components/lora/lora.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/components/lora/lora.c b/components/lora/lora.c index 952b0ea..988d002 100644 --- a/components/lora/lora.c +++ b/components/lora/lora.c @@ -499,3 +499,38 @@ lora_dump_registers(void) printf("\n"); } +/** + * @brief Check if SX127x LoRa radio module initialized properly + * @return + * - 0: Init failed + * - 1: Init was succesful + * @note RK, 2021.07.18 + */ +int lora_initialized(void) +{ + /* + * Check version, see datasheet + * https://cdn-shop.adafruit.com/product-files/3179/sx1276_77_78_79.pdf, page 92, 105 + */ + uint8_t version; + uint8_t i = 0; + while (i < TIMEOUT_RESET) + { + version = lora_read_reg(REG_VERSION); + if (version == 0x12) + break; + vTaskDelay(2); + i++; + } + if (i >= TIMEOUT_RESET) + { + return 0; + } + + /* + * Switch to idle mode. + */ + lora_idle(); + + return 1; +}