-
1RadioHead library: custom modem configurations
A brief application note if you are using the RadioHead library.
To the moment, the RadioHead library offers only a set of four predefined modem configurations. These can be found in RH_RF95.cpp:{ 0x72, 0x74, 0x00}, // Bw125Cr45Sf128 (the chip default) { 0x92, 0x74, 0x00}, // Bw500Cr45Sf128 { 0x48, 0x94, 0x00}, // Bw31_25Cr48Sf512 { 0x78, 0xc4, 0x00}, // Bw125Cr48Sf4096
The first of these three bytes is written to configuration register 0x1d, the second to 0x1e and the third into 0x26. Relevant settings include:
RegModemConfig 1 / 0x1D
- signal bandwidth (7.8kHz to 500kHz)
- codingRate 4/4 to 4/8
- implicit Header on/off
RegModemConfig 2 / 0x1E
- spreading factor (64chips/symbol to 4096 chips/symbol)
- CRC on/off
RegModemConfig 3 / 0x26
- 'Low Data Rate Optimization' aka MobileNode
- automatic AGC on/off
Utilizing one of the predefined settings, you would want to initialize your modem like this:
... #define ModemConfig RH_RF95::Bw31_25Cr48Sf512 ... rf95.setModemConfig(ModemConfig); ...
And instead of using one of the predefined settings, you can configure your LoRa mode according your needs:
... RH_RF95::ModemConfig myconfig= { 0x28, 0x94, 0x04}; // Bw15_6Cr48Sf512 // will give you // 15.6kHz bandwidth, 4/8 coding rate, spreading factor 9 (512), low data rate optimization off, AGC on ... rf95.setModemRegisters(&myconfig);
Now, if this seems too cryptic to you, this can be rewritten into a more human readable form. Fortunatelly, the available options are predefined accordingly in RH_RF95.h:
... // RH_RF95_REG_1D_MODEM_CONFIG1 0x1d #define RH_RF95_BW 0xf0 #define RH_RF95_BW_7_8KHZ 0x00 #define RH_RF95_BW_10_4KHZ 0x10 #define RH_RF95_BW_15_6KHZ 0x20 #define RH_RF95_BW_20_8KHZ 0x30 #define RH_RF95_BW_31_25KHZ 0x40 #define RH_RF95_BW_41_7KHZ 0x50 #define RH_RF95_BW_62_5KHZ 0x60 #define RH_RF95_BW_125KHZ 0x70 #define RH_RF95_BW_250KHZ 0x80 #define RH_RF95_BW_500KHZ 0x90 #define RH_RF95_CODING_RATE 0x0e #define RH_RF95_CODING_RATE_4_5 0x02 #define RH_RF95_CODING_RATE_4_6 0x04 #define RH_RF95_CODING_RATE_4_7 0x06 #define RH_RF95_CODING_RATE_4_8 0x08 #define RH_RF95_IMPLICIT_HEADER_MODE_ON 0x01 // RH_RF95_REG_1E_MODEM_CONFIG2 0x1e #define RH_RF95_SPREADING_FACTOR 0xf0 #define RH_RF95_SPREADING_FACTOR_64CPS 0x60 #define RH_RF95_SPREADING_FACTOR_128CPS 0x70 #define RH_RF95_SPREADING_FACTOR_256CPS 0x80 #define RH_RF95_SPREADING_FACTOR_512CPS 0x90 #define RH_RF95_SPREADING_FACTOR_1024CPS 0xa0 #define RH_RF95_SPREADING_FACTOR_2048CPS 0xb0 #define RH_RF95_SPREADING_FACTOR_4096CPS 0xc0 #define RH_RF95_TX_CONTINUOUS_MOE 0x08 #define RH_RF95_PAYLOAD_CRC_ON 0x04 #define RH_RF95_SYM_TIMEOUT_MSB 0x03 ...
So your custom modem configuration can be rewritten into this:
// so instead of RH_RF95::ModemConfig myconfig= { 0x28, 0x94, 0x04}; // you can use RH_RF95::ModemConfig myconfig = { RH_RF95_BW_15_6KHZ | RH_RF95_CODING_RATE_4_8, RH_RF95_SPREADING_FACTOR_512CPS, 0x04}; // where the last parameter (0x04) turns the AGC on
All relevant registers are described also within the SX127x datasheet, available e.g. at
Happy coding!
dk
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.