[SX126x] Changed pin mapping, added reset, changed LoRa sync word to 1B
This commit is contained in:
parent
beb160f705
commit
55aff74a81
13 changed files with 68 additions and 38 deletions
|
@ -18,8 +18,9 @@
|
|||
// SX1262 has the following connections:
|
||||
// NSS pin: 10
|
||||
// DIO1 pin: 2
|
||||
// NRST pin: 3
|
||||
// BUSY pin: 9
|
||||
SX1262 lora = new Module(10, 2, 9);
|
||||
SX1262 lora = new Module(10, 2, 3, 9);
|
||||
|
||||
// or using RadioShield
|
||||
// https://github.com/jgromes/RadioShield
|
||||
|
|
|
@ -19,8 +19,9 @@
|
|||
// SX1262 has the following connections:
|
||||
// NSS pin: 10
|
||||
// DIO1 pin: 2
|
||||
// NRST pin: 3
|
||||
// BUSY pin: 9
|
||||
SX1262 fsk = new Module(10, 2, 9);
|
||||
SX1262 fsk = new Module(10, 2, 3, 9);
|
||||
|
||||
// or using RadioShield
|
||||
// https://github.com/jgromes/RadioShield
|
||||
|
|
|
@ -23,9 +23,9 @@
|
|||
// SX1262 has the following connections:
|
||||
// NSS pin: 10
|
||||
// DIO1 pin: 2
|
||||
// DIO2 pin: 3
|
||||
// NRST pin: 3
|
||||
// BUSY pin: 9
|
||||
SX1262 lora = new Module(10, 2, 9);
|
||||
SX1262 lora = new Module(10, 2, 3, 9);
|
||||
|
||||
// or using RadioShield
|
||||
// https://github.com/jgromes/RadioShield
|
||||
|
|
|
@ -24,8 +24,9 @@
|
|||
// SX1262 has the following connections:
|
||||
// NSS pin: 10
|
||||
// DIO1 pin: 2
|
||||
// NRST pin: 3
|
||||
// BUSY pin: 9
|
||||
SX1262 lora = new Module(10, 2, 9);
|
||||
SX1262 lora = new Module(10, 2, 3, 9);
|
||||
|
||||
// or using RadioShield
|
||||
// https://github.com/jgromes/RadioShield
|
||||
|
|
|
@ -27,14 +27,16 @@
|
|||
// SX1262 has the following connections:
|
||||
// NSS pin: 10
|
||||
// DIO1 pin: 2
|
||||
// NRST pin: 3
|
||||
// BUSY pin: 9
|
||||
SX1262 loraSX1262 = new Module(10, 2, 9);
|
||||
SX1262 loraSX1262 = new Module(10, 2, 3, 9);
|
||||
|
||||
// SX12628 has different connections:
|
||||
// NSS pin: 8
|
||||
// DIO1 pin: 4
|
||||
// NRST pin: 5
|
||||
// BUSY pin: 6
|
||||
SX1268 loraSX1268 = new Module(8, 4, 6);
|
||||
SX1268 loraSX1268 = new Module(8, 4, 5, 6);
|
||||
|
||||
// or using RadioShield
|
||||
// https://github.com/jgromes/RadioShield
|
||||
|
|
|
@ -19,8 +19,9 @@
|
|||
// SX1262 has the following connections:
|
||||
// NSS pin: 10
|
||||
// DIO1 pin: 2
|
||||
// NRST pin: 3
|
||||
// BUSY pin: 9
|
||||
SX1262 lora = new Module(10, 2, 9);
|
||||
SX1262 lora = new Module(10, 2, 3, 9);
|
||||
|
||||
// or using RadioShield
|
||||
// https://github.com/jgromes/RadioShield
|
||||
|
@ -35,7 +36,7 @@ void setup() {
|
|||
// bandwidth: 125.0 kHz
|
||||
// spreading factor: 9
|
||||
// coding rate: 7
|
||||
// sync word: 0x1424 (private network)
|
||||
// sync word: 0x12 (private network)
|
||||
// output power: 14 dBm
|
||||
// current limit: 60 mA
|
||||
// preamble length: 8 symbols
|
||||
|
|
|
@ -20,8 +20,9 @@
|
|||
// SX1262 has the following connections:
|
||||
// NSS pin: 10
|
||||
// DIO1 pin: 2
|
||||
// NRST pin: 3
|
||||
// BUSY pin: 9
|
||||
SX1262 lora = new Module(10, 2, 9);
|
||||
SX1262 lora = new Module(10, 2, 3, 9);
|
||||
|
||||
// save transmission state between loops
|
||||
int transmissionState = ERR_NONE;
|
||||
|
|
|
@ -4,7 +4,7 @@ SX1262::SX1262(Module* mod) : SX126x(mod) {
|
|||
|
||||
}
|
||||
|
||||
int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint16_t syncWord, int8_t power, float currentLimit, uint16_t preambleLength, float tcxoVoltage) {
|
||||
int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, float currentLimit, uint16_t preambleLength, float tcxoVoltage) {
|
||||
// execute common part
|
||||
int16_t state = SX126x::begin(bw, sf, cr, syncWord, currentLimit, preambleLength, tcxoVoltage);
|
||||
if(state != ERR_NONE) {
|
||||
|
|
|
@ -32,7 +32,7 @@ class SX1262: public SX126x {
|
|||
|
||||
\param cr LoRa coding rate denominator. Defaults to 7 (coding rate 4/7).
|
||||
|
||||
\param syncWord 2-byte LoRa sync word. Defaults to SX126X_SYNC_WORD_PRIVATE (0x1424).
|
||||
\param syncWord 2-byte LoRa sync word. Defaults to SX126X_SYNC_WORD_PRIVATE (0x12).
|
||||
|
||||
\param power Output power in dBm. Defaults to 14 dBm.
|
||||
|
||||
|
@ -44,7 +44,7 @@ class SX1262: public SX126x {
|
|||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint16_t syncWord = SX126X_SYNC_WORD_PRIVATE, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 8, float tcxoVoltage = 1.6);
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX126X_SYNC_WORD_PRIVATE, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 8, float tcxoVoltage = 1.6);
|
||||
|
||||
/*!
|
||||
\brief Initialization method for FSK modem.
|
||||
|
|
|
@ -4,7 +4,7 @@ SX1268::SX1268(Module* mod) : SX126x(mod) {
|
|||
|
||||
}
|
||||
|
||||
int16_t SX1268::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint16_t syncWord, int8_t power, float currentLimit, uint16_t preambleLength, float tcxoVoltage) {
|
||||
int16_t SX1268::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, float currentLimit, uint16_t preambleLength, float tcxoVoltage) {
|
||||
// execute common part
|
||||
int16_t state = SX126x::begin(bw, sf, cr, syncWord, currentLimit, preambleLength, tcxoVoltage);
|
||||
if(state != ERR_NONE) {
|
||||
|
|
|
@ -35,7 +35,7 @@ class SX1268: public SX126x {
|
|||
|
||||
\param cr LoRa coding rate denominator. Defaults to 7 (coding rate 4/7).
|
||||
|
||||
\param syncWord 2-byte LoRa sync word. Defaults to SX126X_SYNC_WORD_PRIVATE (0x1424).
|
||||
\param syncWord 2-byte LoRa sync word. Defaults to SX126X_SYNC_WORD_PRIVATE (0x12).
|
||||
|
||||
\param power Output power in dBm. Defaults to 14 dBm.
|
||||
|
||||
|
@ -47,7 +47,7 @@ class SX1268: public SX126x {
|
|||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint16_t syncWord = SX126X_SYNC_WORD_PRIVATE, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 8, float tcxoVoltage = 1.6);
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX126X_SYNC_WORD_PRIVATE, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 8, float tcxoVoltage = 1.6);
|
||||
|
||||
/*!
|
||||
\brief Initialization method for FSK modem.
|
||||
|
|
|
@ -4,9 +4,14 @@ SX126x::SX126x(Module* mod) : PhysicalLayer(SX126X_CRYSTAL_FREQ, SX126X_DIV_EXPO
|
|||
_mod = mod;
|
||||
}
|
||||
|
||||
int16_t SX126x::begin(float bw, uint8_t sf, uint8_t cr, uint16_t syncWord, float currentLimit, uint16_t preambleLength, float tcxoVoltage) {
|
||||
int16_t SX126x::begin(float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, float currentLimit, uint16_t preambleLength, float tcxoVoltage) {
|
||||
// set module properties
|
||||
_mod->init(RADIOLIB_USE_SPI, RADIOLIB_INT_BOTH);
|
||||
_mod->init(RADIOLIB_USE_SPI);
|
||||
Module::pinMode(_mod->getIrq(), INPUT);
|
||||
Module::pinMode(_mod->getGpio(), INPUT);
|
||||
|
||||
// reset the module
|
||||
reset();
|
||||
|
||||
// BW in kHz and SF are required in order to calculate LDRO for setModulationParams
|
||||
_bwKhz = bw;
|
||||
|
@ -79,7 +84,11 @@ int16_t SX126x::begin(float bw, uint8_t sf, uint8_t cr, uint16_t syncWord, float
|
|||
|
||||
int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, float currentLimit, uint16_t preambleLength, float dataShaping, float tcxoVoltage) {
|
||||
// set module properties
|
||||
_mod->init(RADIOLIB_USE_SPI, RADIOLIB_INT_BOTH);
|
||||
_mod->init(RADIOLIB_USE_SPI);
|
||||
Module::pinMode(_mod->getIrq(), INPUT);
|
||||
|
||||
// reset the module
|
||||
reset();
|
||||
|
||||
// initialize configuration variables (will be overwritten during public settings configuration)
|
||||
_br = 21333; // 48.0 kbps
|
||||
|
@ -159,6 +168,15 @@ int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, float currentLimit
|
|||
return(state);
|
||||
}
|
||||
|
||||
void SX126x::reset() {
|
||||
Module::pinMode(_mod->getRst(), OUTPUT);
|
||||
Module::digitalWrite(_mod->getRst(), LOW);
|
||||
delay(100);
|
||||
Module::digitalWrite(_mod->getRst(), HIGH);
|
||||
Module::pinMode(_mod->getRst(), INPUT);
|
||||
delay(100);
|
||||
}
|
||||
|
||||
int16_t SX126x::transmit(uint8_t* data, size_t len, uint8_t addr) {
|
||||
// set mode to standby
|
||||
int16_t state = standby();
|
||||
|
@ -199,7 +217,7 @@ int16_t SX126x::transmit(uint8_t* data, size_t len, uint8_t addr) {
|
|||
|
||||
// wait for packet transmission or timeout
|
||||
uint32_t start = micros();
|
||||
while(!digitalRead(_mod->getInt0())) {
|
||||
while(!digitalRead(_mod->getIrq())) {
|
||||
if(micros() - start > timeout) {
|
||||
clearIrqStatus();
|
||||
return(ERR_TX_TIMEOUT);
|
||||
|
@ -264,7 +282,7 @@ int16_t SX126x::receive(uint8_t* data, size_t len) {
|
|||
|
||||
// wait for packet reception or timeout
|
||||
uint32_t start = micros();
|
||||
while(!digitalRead(_mod->getInt0())) {
|
||||
while(!digitalRead(_mod->getIrq())) {
|
||||
if(micros() - start > timeout) {
|
||||
fixImplicitTimeout();
|
||||
clearIrqStatus();
|
||||
|
@ -333,7 +351,7 @@ int16_t SX126x::scanChannel() {
|
|||
}
|
||||
|
||||
// wait for channel activity detected or timeout
|
||||
while(!digitalRead(_mod->getInt0()));
|
||||
while(!digitalRead(_mod->getIrq()));
|
||||
|
||||
// check CAD result
|
||||
uint16_t cadResult = getIrqStatus();
|
||||
|
@ -370,7 +388,7 @@ int16_t SX126x::standby(uint8_t mode) {
|
|||
}
|
||||
|
||||
void SX126x::setDio1Action(void (*func)(void)) {
|
||||
attachInterrupt(digitalPinToInterrupt(_mod->getInt0()), func, RISING);
|
||||
attachInterrupt(digitalPinToInterrupt(_mod->getIrq()), func, RISING);
|
||||
}
|
||||
|
||||
int16_t SX126x::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
|
||||
|
@ -438,7 +456,7 @@ int16_t SX126x::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
|
|||
}
|
||||
|
||||
// wait for BUSY to go low (= PA ramp up done)
|
||||
while(digitalRead(_mod->getInt1()));
|
||||
while(digitalRead(_mod->getGpio()));
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
@ -660,14 +678,14 @@ int16_t SX126x::setCodingRate(uint8_t cr) {
|
|||
return(setModulationParams(_sf, _bw, _cr));
|
||||
}
|
||||
|
||||
int16_t SX126x::setSyncWord(uint16_t syncWord) {
|
||||
int16_t SX126x::setSyncWord(uint8_t syncWord) {
|
||||
// check active modem
|
||||
if(getPacketType() != SX126X_PACKET_TYPE_LORA) {
|
||||
return(ERR_WRONG_MODEM);
|
||||
}
|
||||
|
||||
// update register
|
||||
uint8_t data[2] = {(uint8_t)((syncWord >> 8) & 0xFF), (uint8_t)(syncWord & 0xFF)};
|
||||
uint8_t data[2] = {(uint8_t)((syncWord & 0xF0) | 0x04), (uint8_t)(((syncWord & 0x0F) << 4) | 0x04)};
|
||||
return(writeRegister(SX126X_REG_LORA_SYNC_WORD_MSB, data, 2));
|
||||
}
|
||||
|
||||
|
@ -1501,7 +1519,7 @@ int16_t SX126x::config(uint8_t modem) {
|
|||
|
||||
// wait for calibration completion
|
||||
delay(5);
|
||||
while(digitalRead(_mod->getInt1()));
|
||||
while(digitalRead(_mod->getGpio()));
|
||||
|
||||
return(ERR_NONE);
|
||||
}
|
||||
|
@ -1537,7 +1555,7 @@ int16_t SX126x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* d
|
|||
// ensure BUSY is low (state meachine ready)
|
||||
RADIOLIB_VERBOSE_PRINTLN(F("Wait for BUSY ... "));
|
||||
uint32_t start = millis();
|
||||
while(digitalRead(_mod->getInt1())) {
|
||||
while(digitalRead(_mod->getGpio())) {
|
||||
if(millis() - start >= timeout) {
|
||||
return(ERR_SPI_CMD_TIMEOUT);
|
||||
}
|
||||
|
@ -1604,11 +1622,11 @@ int16_t SX126x::SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* d
|
|||
if(waitForBusy) {
|
||||
delayMicroseconds(1);
|
||||
start = millis();
|
||||
while(digitalRead(_mod->getInt1())) {
|
||||
if(millis() - start >= timeout) {
|
||||
status = SX126X_STATUS_CMD_TIMEOUT;
|
||||
break;
|
||||
}
|
||||
while(digitalRead(_mod->getGpio())) {
|
||||
if(millis() - start >= timeout) {
|
||||
status = SX126X_STATUS_CMD_TIMEOUT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -325,8 +325,8 @@
|
|||
|
||||
// SX126X SPI register variables
|
||||
//SX126X_REG_LORA_SYNC_WORD_MSB + LSB
|
||||
#define SX126X_SYNC_WORD_PUBLIC 0x3444
|
||||
#define SX126X_SYNC_WORD_PRIVATE 0x1424
|
||||
#define SX126X_SYNC_WORD_PUBLIC 0x34 // actually 0x3444 NOTE: The low nibbles in each byte (0x_4_4) are masked out since apparently, they're reserved.
|
||||
#define SX126X_SYNC_WORD_PRIVATE 0x12 // actually 0x1424 You couldn't make this up if you tried.
|
||||
|
||||
|
||||
/*!
|
||||
|
@ -361,7 +361,7 @@ class SX126x: public PhysicalLayer {
|
|||
|
||||
\param cr LoRa coding rate denominator. Allowed values range from 5 to 8.
|
||||
|
||||
\param syncWord 2-byte LoRa sync word.
|
||||
\param syncWord 1-byte LoRa sync word.
|
||||
|
||||
\param currentLimit Current protection limit in mA.
|
||||
|
||||
|
@ -371,7 +371,7 @@ class SX126x: public PhysicalLayer {
|
|||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float bw, uint8_t sf, uint8_t cr, uint16_t syncWord, float currentLimit, uint16_t preambleLength, float tcxoVoltage);
|
||||
int16_t begin(float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, float currentLimit, uint16_t preambleLength, float tcxoVoltage);
|
||||
|
||||
/*!
|
||||
\brief Initialization method for FSK modem.
|
||||
|
@ -394,6 +394,11 @@ class SX126x: public PhysicalLayer {
|
|||
*/
|
||||
int16_t beginFSK(float br, float freqDev, float rxBw, float currentLimit, uint16_t preambleLength, float dataShaping, float tcxoVoltage);
|
||||
|
||||
/*!
|
||||
\brief Reset method. Will reset the chip to the default state using RST pin.
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/*!
|
||||
\brief Blocking binary transmit method.
|
||||
Overloads for string-based transmissions are implemented in PhysicalLayer.
|
||||
|
@ -571,7 +576,7 @@ class SX126x: public PhysicalLayer {
|
|||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setSyncWord(uint16_t syncWord);
|
||||
int16_t setSyncWord(uint8_t syncWord);
|
||||
|
||||
/*!
|
||||
\brief Sets current protection limit. Can be set in 0.25 mA steps.
|
||||
|
|
Loading…
Add table
Reference in a new issue