From 1e1c34bac81c043558a804bac9beb1489bb9599d Mon Sep 17 00:00:00 2001 From: "Morgan 'ARR\\!' Allen" Date: Fri, 21 Feb 2020 08:55:01 -0800 Subject: [PATCH] check IRQ flags that this is actually a receive --- main/esp32-lora.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/main/esp32-lora.c b/main/esp32-lora.c index 6a8d4e9..277b674 100644 --- a/main/esp32-lora.c +++ b/main/esp32-lora.c @@ -268,22 +268,24 @@ static void IRAM_ATTR lora32_dio0_task(void *arg) { ESP_LOGD(TAG, "handling DIO0"); // read IRQ flags - ESP_LOGD(TAG, "reading irqs"); uint8_t irqs = lora32_read_reg(lora, REG_IRQ_FLAGS); + ESP_LOGI(TAG, "reading irqs: %02X", irqs); // clear IRQ flags ESP_LOGD(TAG, "clearing irqs"); lora32_write_reg(lora, REG_IRQ_FLAGS, irqs); - uint8_t len = lora32_read_reg(lora, (lora->implicitHeader ? REG_PAYLOAD_LENGTH : REG_RX_NB_BYTES)); - ESP_LOGD(TAG, "lora32_receive_task packet length: %d", len); + if((irqs & IRQ_RX_DONE_MASK) == IRQ_RX_DONE_MASK) { + uint8_t len = lora32_read_reg(lora, (lora->implicitHeader ? REG_PAYLOAD_LENGTH : REG_RX_NB_BYTES)); + ESP_LOGD(TAG, "lora32_dio0_task packet length: %d", len); - // TODO: set FIFO address to RX address - uint8_t fifo_addr = lora32_read_reg(lora, REG_FIFO_RX_CURRENT_ADDR); - ESP_LOGD(TAG, "lora32_receive_task current FIFO address: %d", fifo_addr); + // TODO: set FIFO address to RX address + uint8_t fifo_addr = lora32_read_reg(lora, REG_FIFO_RX_CURRENT_ADDR); + ESP_LOGD(TAG, "lora32_dio0_task current FIFO address: %d", fifo_addr); - lora32_write_reg(lora, REG_FIFO_ADDR_PTR, fifo_addr); + lora32_write_reg(lora, REG_FIFO_ADDR_PTR, fifo_addr); - lora->receive(len); + lora->receive(len); + } } }