[SX127x] Changed pin mapping and implemented reset

pull/103/head
jgromes 2019-12-27 13:19:54 +01:00
rodzic 47776c5acb
commit beb160f705
9 zmienionych plików z 51 dodań i 20 usunięć

Wyświetl plik

@ -19,8 +19,9 @@
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 lora = new Module(10, 2, 3);
SX1278 lora = new Module(10, 2, 9, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield

Wyświetl plik

@ -19,8 +19,9 @@
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 fsk = new Module(10, 2, 3);
SX1278 fsk = new Module(10, 2, 9, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield

Wyświetl plik

@ -23,8 +23,9 @@
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 lora = new Module(10, 2, 3);
SX1278 lora = new Module(10, 2, 9, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield

Wyświetl plik

@ -24,8 +24,9 @@
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 lora = new Module(10, 2, 3);
SX1278 lora = new Module(10, 2, 9, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield

Wyświetl plik

@ -23,14 +23,16 @@
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 loraSX1278 = new Module(10, 2, 3);
SX1278 loraSX1278 = new Module(10, 2, 9, 3);
// SX1272 has different connections:
// NSS pin: 9
// DIO0 pin: 4
// DIO1 pin: 5
SX1272 loraSX1272 = new Module(9, 4, 5);
// RESET pin: 5
// DIO1 pin: 6
SX1272 loraSX1272 = new Module(9, 4, 5, 6);
// or using RadioShield
// https://github.com/jgromes/RadioShield

Wyświetl plik

@ -19,8 +19,9 @@
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 lora = new Module(10, 2, 3);
SX1278 lora = new Module(10, 2, 9, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield

Wyświetl plik

@ -20,8 +20,9 @@
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 lora = new Module(10, 2, 3);
SX1278 lora = new Module(10, 2, 9, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield

Wyświetl plik

@ -7,7 +7,12 @@ SX127x::SX127x(Module* mod) : PhysicalLayer(SX127X_CRYSTAL_FREQ, SX127X_DIV_EXPO
int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimit, uint16_t preambleLength) {
// 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();
// try to find the SX127x chip
if(!SX127x::findChip(chipVersion)) {
@ -54,7 +59,11 @@ int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimi
int16_t SX127x::beginFSK(uint8_t chipVersion, float br, float freqDev, float rxBw, uint8_t currentLimit, uint16_t preambleLength, bool enableOOK) {
// 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();
// try to find the SX127x chip
if(!SX127x::findChip(chipVersion)) {
@ -145,6 +154,15 @@ int16_t SX127x::beginFSK(uint8_t chipVersion, float br, float freqDev, float rxB
return(state);
}
void SX127x::reset() {
Module::pinMode(_mod->getRst(), OUTPUT);
Module::digitalWrite(_mod->getRst(), LOW);
delayMicroseconds(100);
Module::digitalWrite(_mod->getRst(), HIGH);
Module::pinMode(_mod->getRst(), INPUT);
delay(5);
}
int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) {
// set mode to standby
int16_t state = setMode(SX127X_STANDBY);
@ -172,7 +190,7 @@ int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) {
// wait for packet transmission or timeout
start = micros();
while(!digitalRead(_mod->getInt0())) {
while(!digitalRead(_mod->getIrq())) {
if(micros() - start > timeout) {
clearIRQFlags();
return(ERR_TX_TIMEOUT);
@ -191,7 +209,7 @@ int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) {
// wait for transmission end or timeout
start = micros();
while(!digitalRead(_mod->getInt0())) {
while(!digitalRead(_mod->getIrq())) {
if(micros() - start > timeout) {
clearIRQFlags();
standby();
@ -226,8 +244,8 @@ int16_t SX127x::receive(uint8_t* data, size_t len) {
}
// wait for packet reception or timeout (100 LoRa symbols)
while(!digitalRead(_mod->getInt0())) {
if(digitalRead(_mod->getInt1())) {
while(!digitalRead(_mod->getIrq())) {
if(digitalRead(_mod->getGpio())) {
clearIRQFlags();
return(ERR_RX_TIMEOUT);
}
@ -245,7 +263,7 @@ int16_t SX127x::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) {
clearIRQFlags();
return(ERR_RX_TIMEOUT);
@ -281,8 +299,8 @@ int16_t SX127x::scanChannel() {
}
// wait for channel activity detected or timeout
while(!digitalRead(_mod->getInt0())) {
if(digitalRead(_mod->getInt1())) {
while(!digitalRead(_mod->getIrq())) {
if(digitalRead(_mod->getGpio())) {
clearIRQFlags();
return(PREAMBLE_DETECTED);
}
@ -411,11 +429,11 @@ int16_t SX127x::startReceive(uint8_t len, uint8_t mode) {
}
void SX127x::setDio0Action(void (*func)(void)) {
attachInterrupt(digitalPinToInterrupt(_mod->getInt0()), func, RISING);
attachInterrupt(digitalPinToInterrupt(_mod->getIrq()), func, RISING);
}
void SX127x::setDio1Action(void (*func)(void)) {
attachInterrupt(digitalPinToInterrupt(_mod->getInt1()), func, RISING);
attachInterrupt(digitalPinToInterrupt(_mod->getGpio()), func, RISING);
}
int16_t SX127x::startTransmit(uint8_t* data, size_t len, uint8_t addr) {

Wyświetl plik

@ -563,6 +563,11 @@ class SX127x: public PhysicalLayer {
*/
int16_t begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimit, uint16_t preambleLength);
/*!
\brief Reset method. Will reset the chip to the default state using RST pin.
*/
void reset();
/*!
\brief Initialization method for FSK modem. Will be called with appropriate parameters when calling FSK initialization method from derived class.