From 3a55ad92e178c121f381f0ae22c54ced554ee4d0 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 2 Apr 2022 19:20:28 +0200 Subject: [PATCH] [CC1101] Fixed RSSI/LQI always returning incorrect values (#504) --- src/modules/CC1101/CC1101.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index 98a2dadc..eadd6a2b 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -375,12 +375,6 @@ int16_t CC1101::readData(uint8_t* data, size_t len) { RADIOLIB_DEBUG_PRINTLN(F("No data for more than 5mS. Stop here.")); break; } else { - /* - * Does this work for all rates? If 1 ms is longer than the 1ms delay - * then the entire FIFO will be transmitted during that delay. - * - * TODO: drop this delay(1) or come up with a better solution: - */ delay(1); bytesInFIFO = SPIgetRegValue(RADIOLIB_CC1101_REG_RXBYTES, 6, 0); continue; @@ -400,17 +394,21 @@ int16_t CC1101::readData(uint8_t* data, size_t len) { // check if status bytes are enabled (default: RADIOLIB_CC1101_APPEND_STATUS_ON) bool isAppendStatus = SPIgetRegValue(RADIOLIB_CC1101_REG_PKTCTRL1, 2, 2) == RADIOLIB_CC1101_APPEND_STATUS_ON; + // for some reason, we need this delay here to get the correct status bytes + delay(3); + // If status byte is enabled at least 2 bytes (2 status bytes + any following packet) will remain in FIFO. - if (bytesInFIFO >= 2 && isAppendStatus) { + if (isAppendStatus) { // read RSSI byte _rawRSSI = SPIgetRegValue(RADIOLIB_CC1101_REG_FIFO); - // read LQI and CRC byte - uint8_t val = SPIgetRegValue(RADIOLIB_CC1101_REG_FIFO); - _rawLQI = val & 0x7F; + // read LQI and CRC byte + uint8_t val = SPIgetRegValue(RADIOLIB_CC1101_REG_FIFO); + _rawLQI = val & 0x7F; // check CRC if (_crcOn && (val & RADIOLIB_CC1101_CRC_OK) == RADIOLIB_CC1101_CRC_ERROR) { + _packetLengthQueried = false; return (RADIOLIB_ERR_CRC_MISMATCH); } }