Merge pull request #500 from loopj/rf69-ook-rxbw

[RF69] Set RX bandwidth correctly for OOK mode
This commit is contained in:
Jan Gromeš 2022-03-29 22:00:27 +02:00 committed by GitHub
commit 84dc43d1e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View file

@ -390,10 +390,14 @@ int16_t RF69::setOOK(bool enableOOK) {
} else { } else {
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_FSK, 4, 3, 5); state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_FSK, 4, 3, 5);
} }
if(state == RADIOLIB_ERR_NONE) { if(state == RADIOLIB_ERR_NONE) {
_ook = enableOOK; _ook = enableOOK;
} }
// call setRxBandwidth again, since register values differ based on OOK mode being enabled
state |= setRxBandwidth(_rxBw);
return(state); return(state);
} }
@ -468,7 +472,7 @@ int16_t RF69::setRxBandwidth(float rxBw) {
// calculate exponent and mantissa values for receiver bandwidth // calculate exponent and mantissa values for receiver bandwidth
for(int8_t e = 7; e >= 0; e--) { for(int8_t e = 7; e >= 0; e--) {
for(int8_t m = 2; m >= 0; m--) { for(int8_t m = 2; m >= 0; m--) {
float point = (RADIOLIB_RF69_CRYSTAL_FREQ * 1000000.0)/(((4 * m) + 16) * ((uint32_t)1 << (e + 2))); float point = (RADIOLIB_RF69_CRYSTAL_FREQ * 1000000.0)/(((4 * m) + 16) * ((uint32_t)1 << (e + (_ook ? 3 : 2))));
if(fabs(rxBw - (point / 1000.0)) <= 0.1) { if(fabs(rxBw - (point / 1000.0)) <= 0.1) {
// set Rx bandwidth // set Rx bandwidth
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_RX_BW, (m << 3) | e, 4, 0); state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_RX_BW, (m << 3) | e, 4, 0);

View file

@ -744,6 +744,7 @@ class RF69: public PhysicalLayer {
/*! /*!
\brief Enables/disables OOK modulation instead of FSK. \brief Enables/disables OOK modulation instead of FSK.
Note: This function calls setRxBandwidth again, since register values differ based on OOK mode being enabled/disabled
\param enableOOK Enable (true) or disable (false) OOK. \param enableOOK Enable (true) or disable (false) OOK.