[CC1101] Fixed RSSI/LQI always returning incorrect values (#504)
This commit is contained in:
parent
84dc43d1e1
commit
3a55ad92e1
1 changed files with 8 additions and 10 deletions
|
@ -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."));
|
RADIOLIB_DEBUG_PRINTLN(F("No data for more than 5mS. Stop here."));
|
||||||
break;
|
break;
|
||||||
} else {
|
} 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);
|
delay(1);
|
||||||
bytesInFIFO = SPIgetRegValue(RADIOLIB_CC1101_REG_RXBYTES, 6, 0);
|
bytesInFIFO = SPIgetRegValue(RADIOLIB_CC1101_REG_RXBYTES, 6, 0);
|
||||||
continue;
|
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)
|
// 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;
|
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 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
|
// read RSSI byte
|
||||||
_rawRSSI = SPIgetRegValue(RADIOLIB_CC1101_REG_FIFO);
|
_rawRSSI = SPIgetRegValue(RADIOLIB_CC1101_REG_FIFO);
|
||||||
|
|
||||||
// read LQI and CRC byte
|
// read LQI and CRC byte
|
||||||
uint8_t val = SPIgetRegValue(RADIOLIB_CC1101_REG_FIFO);
|
uint8_t val = SPIgetRegValue(RADIOLIB_CC1101_REG_FIFO);
|
||||||
_rawLQI = val & 0x7F;
|
_rawLQI = val & 0x7F;
|
||||||
|
|
||||||
// check CRC
|
// check CRC
|
||||||
if (_crcOn && (val & RADIOLIB_CC1101_CRC_OK) == RADIOLIB_CC1101_CRC_ERROR) {
|
if (_crcOn && (val & RADIOLIB_CC1101_CRC_OK) == RADIOLIB_CC1101_CRC_ERROR) {
|
||||||
|
_packetLengthQueried = false;
|
||||||
return (RADIOLIB_ERR_CRC_MISMATCH);
|
return (RADIOLIB_ERR_CRC_MISMATCH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue