kopia lustrzana https://github.com/jgromes/RadioLib
RF69 - Added method to set sync word
rodzic
17f8e3efdd
commit
9ea57154be
|
@ -20,6 +20,7 @@ void setup() {
|
|||
// Rx bandwidth: 125.0 kHz
|
||||
// frequency deviation: 50.0 kHz
|
||||
// output power: 13 dBm
|
||||
// sync word: 0x2D 0x01
|
||||
byte state = rf.begin();
|
||||
if(state == ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
|
|
|
@ -20,6 +20,7 @@ void setup() {
|
|||
// Rx bandwidth: 125.0 kHz
|
||||
// frequency deviation: 50.0 kHz
|
||||
// output power: 13 dBm
|
||||
// sync word: 0x2D 0x01
|
||||
byte state = rf.begin();
|
||||
if(state == ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
|
|
|
@ -100,10 +100,12 @@ ERR_INVALID_FREQUENCY LITERAL1
|
|||
ERR_INVALID_OUTPUT_POWER LITERAL1
|
||||
PREAMBLE_DETECTED LITERAL1
|
||||
CHANNEL_FREE LITERAL1
|
||||
|
||||
ERR_INVALID_BIT_RATE LITERAL1
|
||||
ERR_INVALID_FREQUENCY_DEVIATION LITERAL1
|
||||
ERR_INVALID_BIT_RATE_BW_RATIO LITERAL1
|
||||
ERR_INVALID_RX_BANDWIDTH LITERAL1
|
||||
ERR_INVALID_SYNC_WORD LITERAL1
|
||||
|
||||
ERR_AT_FAILED LITERAL1
|
||||
ERR_URL_MALFORMED LITERAL1
|
||||
|
|
|
@ -67,10 +67,13 @@
|
|||
#define ERR_INVALID_OUTPUT_POWER 0x0C
|
||||
#define PREAMBLE_DETECTED 0x0D
|
||||
#define CHANNEL_FREE 0x0E
|
||||
|
||||
// RF69-specific status codes
|
||||
#define ERR_INVALID_BIT_RATE 0x0F
|
||||
#define ERR_INVALID_FREQUENCY_DEVIATION 0x10
|
||||
#define ERR_INVALID_BIT_RATE_BW_RATIO 0x11
|
||||
#define ERR_INVALID_RX_BANDWIDTH 0x12
|
||||
#define ERR_INVALID_SYNC_WORD 0x13
|
||||
|
||||
// ESP8266 status codes
|
||||
#define ERR_AT_FAILED 0x01
|
||||
|
|
|
@ -72,6 +72,13 @@ uint8_t RF69::begin(float freq, float br, float rxBw, float freqDev, int8_t powe
|
|||
return(state);
|
||||
}
|
||||
|
||||
// default sync word values 0x2D01 is the same as the default in LowPowerLab RFM69 library
|
||||
uint8_t syncWord[] = {0x2D, 0x01};
|
||||
state = setSyncWord(syncWord, 2);
|
||||
if(state != ERR_NONE) {
|
||||
return(state);
|
||||
}
|
||||
|
||||
return(ERR_NONE);
|
||||
}
|
||||
|
||||
|
@ -368,6 +375,41 @@ uint8_t RF69::setOutputPower(int8_t power) {
|
|||
return(state);
|
||||
}
|
||||
|
||||
uint8_t RF69::setSyncWord(uint8_t* syncWord, size_t len, uint8_t maxErrBits) {
|
||||
// check constraints
|
||||
if((maxErrBits > 7) || (len > 8)) {
|
||||
return(ERR_INVALID_SYNC_WORD);
|
||||
}
|
||||
|
||||
// sync word must not contain value 0x00
|
||||
for(uint8_t i = 0; i < len; i++) {
|
||||
if(syncWord[i] == 0x00) {
|
||||
return(ERR_INVALID_SYNC_WORD);
|
||||
}
|
||||
}
|
||||
|
||||
// enable sync word recognition
|
||||
uint8_t state = _mod->SPIsetRegValue(RF69_REG_SYNC_CONFIG, RF69_SYNC_ON | RF69_FIFO_FILL_CONDITION_SYNC | (len - 1) << 3 | maxErrBits, 7, 0);
|
||||
if(state != ERR_NONE) {
|
||||
return(state);
|
||||
}
|
||||
|
||||
// set sync word
|
||||
_mod->SPIwriteRegisterBurst(RF69_REG_SYNC_VALUE_1, syncWord, len);
|
||||
return(ERR_NONE);
|
||||
}
|
||||
|
||||
uint8_t RF69::setNodeAddress(uint8_t nodeAddr) {
|
||||
// enable address filtering (node only)
|
||||
uint8_t state = _mod->SPIsetRegValue(RF69_REG_PACKET_CONFIG_1, RF69_ADDRESS_FILTERING_NODE, 2, 1);
|
||||
if(state != ERR_NONE) {
|
||||
return(state);
|
||||
}
|
||||
|
||||
// set node address
|
||||
return(_mod->SPIsetRegValue(RF69_REG_NODE_ADRS, nodeAddr));
|
||||
}
|
||||
|
||||
uint8_t RF69::config() {
|
||||
uint8_t state = ERR_NONE;
|
||||
|
||||
|
|
|
@ -428,12 +428,13 @@ class RF69 {
|
|||
uint8_t sleep();
|
||||
uint8_t standby();
|
||||
|
||||
// setting methods
|
||||
// configuration methods
|
||||
uint8_t setFrequency(float freq);
|
||||
uint8_t setBitRate(float br);
|
||||
uint8_t setRxBandwidth(float rxBw);
|
||||
uint8_t setFrequencyDeviation(float freqDev);
|
||||
uint8_t setOutputPower(int8_t power);
|
||||
uint8_t setSyncWord(uint8_t* syncWord, size_t len, uint8_t maxErrBits = 0);
|
||||
|
||||
protected:
|
||||
Module* _mod;
|
||||
|
|
Ładowanie…
Reference in New Issue