@@ -924,8 +924,9 @@ bool RF24::_init_radio()
924924 setRetries (5 , 15 );
925925
926926 // Then set the data rate to the slowest (and most reliable) speed supported by all
927- // hardware.
928- setDataRate (RF24_1MBPS);
927+ // hardware. Since this value occupies the same register as the PA level value, set
928+ // the PA level to MAX
929+ setRadiation (RF24_PA_MAX, RF24_1MBPS); // LNA enabled by default
929930
930931 // detect if is a plus variant & use old toggle features command accordingly
931932 uint8_t before_toggle = read_register (FEATURE);
@@ -1670,16 +1671,9 @@ bool RF24::testRPD(void)
16701671
16711672void RF24::setPALevel (uint8_t level, bool lnaEnable)
16721673{
1673-
1674- uint8_t setup = read_register (RF_SETUP) & 0xF8 ;
1675-
1676- if (level > 3 ) { // If invalid level, go to max PA
1677- level = static_cast <uint8_t >((RF24_PA_MAX << 1 ) + lnaEnable); // +1 to support the SI24R1 chip extra bit
1678- } else {
1679- level = static_cast <uint8_t >((level << 1 ) + lnaEnable); // Else set level as requested
1680- }
1681-
1682- write_register (RF_SETUP, setup |= level); // Write it to the chip
1674+ uint8_t setup = read_register (RF_SETUP) & static_cast <uint8_t >(0xF8 );
1675+ setup |= _pa_level_reg_value (level, lnaEnable);
1676+ write_register (RF_SETUP, setup);
16831677}
16841678
16851679/* ***************************************************************************/
@@ -1707,33 +1701,8 @@ bool RF24::setDataRate(rf24_datarate_e speed)
17071701
17081702 // HIGH and LOW '00' is 1Mbs - our default
17091703 setup = static_cast <uint8_t >(setup & ~(_BV (RF_DR_LOW) | _BV (RF_DR_HIGH)));
1704+ setup |= _data_rate_reg_value (speed);
17101705
1711- #if !defined(F_CPU) || F_CPU > 20000000
1712- txDelay = 280 ;
1713- #else // 16Mhz Arduino
1714- txDelay=85 ;
1715- #endif
1716- if (speed == RF24_250KBPS) {
1717- // Must set the RF_DR_LOW to 1; RF_DR_HIGH (used to be RF_DR) is already 0
1718- // Making it '10'.
1719- setup |= _BV (RF_DR_LOW);
1720- #if !defined(F_CPU) || F_CPU > 20000000
1721- txDelay = 505 ;
1722- #else // 16Mhz Arduino
1723- txDelay = 155 ;
1724- #endif
1725- } else {
1726- // Set 2Mbs, RF_DR (RF_DR_HIGH) is set 1
1727- // Making it '01'
1728- if (speed == RF24_2MBPS) {
1729- setup |= _BV (RF_DR_HIGH);
1730- #if !defined(F_CPU) || F_CPU > 20000000
1731- txDelay = 240 ;
1732- #else // 16Mhz Arduino
1733- txDelay = 65 ;
1734- #endif
1735- }
1736- }
17371706 write_register (RF_SETUP, setup);
17381707
17391708 // Verify our result
@@ -1851,6 +1820,7 @@ void RF24::startConstCarrier(rf24_pa_dbm_e level, uint8_t channel)
18511820}
18521821
18531822/* ***************************************************************************/
1823+
18541824void RF24::stopConstCarrier ()
18551825{
18561826 /*
@@ -1863,3 +1833,63 @@ void RF24::stopConstCarrier()
18631833 write_register (RF_SETUP, static_cast <uint8_t >(read_register (RF_SETUP) & ~_BV (CONT_WAVE) & ~_BV (PLL_LOCK)));
18641834 ce (LOW);
18651835}
1836+
1837+ /* ***************************************************************************/
1838+
1839+ void RF24::toggleAllPipes (bool isEnabled)
1840+ {
1841+ write_register (EN_RXADDR, static_cast <uint8_t >(isEnabled ? 0x3F : 0 ));
1842+ }
1843+
1844+ /* ***************************************************************************/
1845+
1846+ uint8_t RF24::_data_rate_reg_value (rf24_datarate_e speed)
1847+ {
1848+ #if !defined(F_CPU) || F_CPU > 20000000
1849+ txDelay = 280 ;
1850+ #else // 16Mhz Arduino
1851+ txDelay=85 ;
1852+ #endif
1853+ if (speed == RF24_250KBPS) {
1854+ #if !defined(F_CPU) || F_CPU > 20000000
1855+ txDelay = 505 ;
1856+ #else // 16Mhz Arduino
1857+ txDelay = 155 ;
1858+ #endif
1859+ // Must set the RF_DR_LOW to 1; RF_DR_HIGH (used to be RF_DR) is already 0
1860+ // Making it '10'.
1861+ return static_cast <uint8_t >(_BV (RF_DR_LOW));
1862+ }
1863+ else if (speed == RF24_2MBPS) {
1864+ #if !defined(F_CPU) || F_CPU > 20000000
1865+ txDelay = 240 ;
1866+ #else // 16Mhz Arduino
1867+ txDelay = 65 ;
1868+ #endif
1869+ // Set 2Mbs, RF_DR (RF_DR_HIGH) is set 1
1870+ // Making it '01'
1871+ return static_cast <uint8_t >(_BV (RF_DR_HIGH));
1872+ }
1873+ // HIGH and LOW '00' is 1Mbs - our default
1874+ return static_cast <uint8_t >(0 );
1875+
1876+ }
1877+
1878+ /* ***************************************************************************/
1879+
1880+ uint8_t RF24::_pa_level_reg_value (uint8_t level, bool lnaEnable)
1881+ {
1882+ // If invalid level, go to max PA
1883+ // Else set level as requested
1884+ // + lnaEnable (1 or 0) to support the SI24R1 chip extra bit
1885+ return static_cast <uint8_t >(((level > RF24_PA_MAX ? static_cast <uint8_t >(RF24_PA_MAX) : level) << 1 ) + lnaEnable);
1886+ }
1887+
1888+ /* ***************************************************************************/
1889+
1890+ void RF24::setRadiation (uint8_t level, rf24_datarate_e speed, bool lnaEnable)
1891+ {
1892+ uint8_t setup = _data_rate_reg_value (speed);
1893+ setup |= _pa_level_reg_value (level, lnaEnable);
1894+ write_register (RF_SETUP, setup);
1895+ }
0 commit comments