From dc78e9b137b8593dbaefee36d6dc4d1af872fa98 Mon Sep 17 00:00:00 2001 From: "Morgan 'ARR\\!' Allen" Date: Wed, 17 Nov 2021 19:28:46 -0800 Subject: [PATCH] remove assert(REG_VERSION) in favor of returning error so application recovery is possible --- include/esp32-lora.h | 2 +- main/esp32-lora.c | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/esp32-lora.h b/include/esp32-lora.h index 81ee6de..9fc0b8f 100644 --- a/include/esp32-lora.h +++ b/include/esp32-lora.h @@ -77,7 +77,7 @@ #define EV_DIO0 (1 << 0) -#define ERR_LOR_ID_MISMATCH (00) +#define ERR_LOR_VERSION_MISMATCH (01) enum freq { F433, F866, F915 diff --git a/main/esp32-lora.c b/main/esp32-lora.c index 353dd2e..a52d7c6 100644 --- a/main/esp32-lora.c +++ b/main/esp32-lora.c @@ -463,7 +463,13 @@ uint8_t lora32_init(lora32_cfg_t *lora) { uint8_t version = lora32_read_reg(lora, REG_VERSION); ESP_LOGD(TAG, "lora32_get_id() == 0x%2X", version); - assert(version == 0x12); + + // if ID does not match, something is likely wrong on the SPI bus + if(version != 0x12) { + ESP_LOGD(TAG, "REG_VERSION returned incorrectly. Expected 0x12 got 0x%02X", version); + + return ERR_LOR_VERSION_MISMATCH; + } // TODO: confirm this is happening. Before/after power measurements? lora32_sleep(lora);