RF69 - Added function to set bit rate

This commit is contained in:
Jan Gromeš 2018-07-04 15:16:00 +02:00
parent cd2ae1883c
commit 0c3145dcbe
4 changed files with 37 additions and 10 deletions

View file

@ -59,6 +59,7 @@ setCodingRate KEYWORD2
setFrequency KEYWORD2
setSyncWord KEYWORD2
setOutputPower KEYWORD2
setBitRate KEYWORD2
# ESP8266
join KEYWORD2
@ -99,6 +100,7 @@ ERR_INVALID_FREQUENCY LITERAL1
ERR_INVALID_OUTPUT_POWER LITERAL1
PREAMBLE_DETECTED LITERAL1
CHANNEL_FREE LITERAL1
ERR_INVALID_BIT_RATE LITERAL1
ERR_AT_FAILED LITERAL1
ERR_URL_MALFORMED LITERAL1

View file

@ -67,6 +67,7 @@
#define ERR_INVALID_OUTPUT_POWER 0x0C
#define PREAMBLE_DETECTED 0x0D
#define CHANNEL_FREE 0x0E
#define ERR_INVALID_BIT_RATE 0x0F
// ESP8266 status codes
#define ERR_AT_FAILED 0x01

View file

@ -4,7 +4,7 @@ RF69::RF69(Module* module) {
_mod = module;
}
uint8_t RF69::begin(float freq) {
uint8_t RF69::begin(float freq, uint32_t br) {
// set module properties
_mod->init(USE_SPI, INT_0);
@ -39,7 +39,7 @@ uint8_t RF69::begin(float freq) {
DEBUG_PRINTLN_STR("Found RF69! (match by RF69_REG_VERSION == 0x24)");
}
return(config(freq));
return(config(freq, br));
}
uint8_t RF69::transmit(Packet& pack) {
@ -129,15 +129,36 @@ uint8_t RF69::standby() {
return(setMode(RF69_STANDBY));
}
uint8_t RF69::config(float freq) {
uint8_t RF69::setFrequency(float freq) {
uint8_t state = RF69::config(freq, _br);
if(state == ERR_NONE) {
RF69::_freq = freq;
}
return(state);
}
uint8_t RF69::setBitRate(uint32_t br) {
uint8_t state = RF69::config(_freq, br);
if(state == ERR_NONE) {
RF69::_br = br;
}
return(state);
}
uint8_t RF69::config(float freq, uint32_t br) {
uint8_t status = ERR_NONE;
// check supplied settings
if(!((freq > 290.0) && (freq < 340.0) ||
(freq > 431.0) && (freq < 510.0) ||
(freq > 862.0) && (freq < 1020.0))) {
return(ERR_INVALID_FREQUENCY);
}
if((br < 1200) || (br > 300000)) {
return(ERR_INVALID_BIT_RATE);
}
//set mode to STANDBY
status = setMode(RF69_STANDBY);
if(status != ERR_NONE) {
@ -163,9 +184,10 @@ uint8_t RF69::config(float freq) {
return(status);
}
//set bit rate (4.8 kbps by default)
status = _mod->SPIsetRegValue(RF69_REG_BITRATE_MSB, RF69_BITRATE_MSB, 7, 0);
status = _mod->SPIsetRegValue(RF69_REG_BITRATE_LSB, RF69_BITRATE_LSB, 7, 0);
//set bit rate
uint16_t bitRate = 32000000 / br;
status = _mod->SPIsetRegValue(RF69_REG_BITRATE_MSB, (bitRate & 0xFF00) >> 8, 7, 0);
status = _mod->SPIsetRegValue(RF69_REG_BITRATE_LSB, bitRate & 0x00FF, 7, 0);
if(status != ERR_NONE) {
return(status);
}

View file

@ -322,11 +322,11 @@
//RF69_REG_RX_TIMEOUT_1
#define RF69_TIMEOUT_RX_START_OFF 0x00 // 7 0 RSSI interrupt timeout disabled (default)
#define RF69_TIMEOUT_RX_START 0x70 // 7 0 timeout will occur if RSSI interrupt is not received
#define RF69_TIMEOUT_RX_START 0xFF // 7 0 timeout will occur if RSSI interrupt is not received
//RF69_REG_RX_TIMEOUT_2
#define RF69_TIMEOUT_RSSI_THRESH_OFF 0x00 // 7 0 PayloadReady interrupt timeout disabled (default)
#define RF69_TIMEOUT_RSSI_THRESH 0x70 // 7 0 timeout will occur if PayloadReady interrupt is not received
#define RF69_TIMEOUT_RSSI_THRESH 0xFF // 7 0 timeout will occur if PayloadReady interrupt is not received
//RF69_REG_PREAMBLE_MSB + REG_PREAMBLE_MSB
#define RF69_PREAMBLE_MSB 0x00 // 7 0 2-byte preamble size value
@ -425,7 +425,7 @@ class RF69 {
public:
RF69(Module* module);
uint8_t begin(float freq = 915.0);
uint8_t begin(float freq = 434.0, uint32_t br = 48000);
uint8_t transmit(Packet& pack);
uint8_t receive(Packet& pack);
@ -433,13 +433,15 @@ class RF69 {
uint8_t standby();
uint8_t setFrequency(float freq);
uint8_t setBitRate(uint32_t br);
private:
Module* _mod;
float _freq;
uint32_t _br;
uint8_t config(float freq);
uint8_t config(float freq, uint32_t br);
uint8_t setMode(uint8_t mode);
void clearIRQFlags();
};