mirror of
https://github.com/sandeepmistry/arduino-LoRa.git
synced 2025-04-19 13:02:14 +03:00
Add function to invert IQ signal register (#179)
Add function to change register (REG_INVERTIQ) to support communication node and gateway The register does not exist in datasheet but use on but used in Semtech code. Reference : https://github.com/intel-iot-devkit/upm/blob/master/src/sx1276/sx1276.cxx * Add LoRa Simple Gateway/Node Exemple Example how to use InvertIQ function to create a simple Gateway/Node logic.
This commit is contained in:
parent
403738660b
commit
07bfead143
10
API.md
10
API.md
@ -329,6 +329,16 @@ LoRa.enableCrc();
|
|||||||
LoRa.disableCrc();
|
LoRa.disableCrc();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Invert IQ Signals
|
||||||
|
|
||||||
|
Enable or disable Invert the LoRa I and Q signals, by default a invertIQ is not used.
|
||||||
|
|
||||||
|
```arduino
|
||||||
|
LoRa.enableInvertIQ();
|
||||||
|
|
||||||
|
LoRa.disableInvertIQ();
|
||||||
|
```
|
||||||
|
|
||||||
## Other functions
|
## Other functions
|
||||||
|
|
||||||
### Random
|
### Random
|
||||||
|
113
examples/LoRaSimpleGateway/LoRaSimpleGateway.ino
Normal file
113
examples/LoRaSimpleGateway/LoRaSimpleGateway.ino
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
LoRa Simple Gateway/Node Exemple
|
||||||
|
|
||||||
|
This code uses InvertIQ function to create a simple Gateway/Node logic.
|
||||||
|
|
||||||
|
Gateway - Sends messages with enableInvertIQ()
|
||||||
|
- Receives messages with disableInvertIQ()
|
||||||
|
|
||||||
|
Node - Sends messages with disableInvertIQ()
|
||||||
|
- Receives messages with enableInvertIQ()
|
||||||
|
|
||||||
|
With this arrangement a Gateway never receive messages from another Gateway
|
||||||
|
and a Node never receive message from another Node.
|
||||||
|
Only Gateway to Node and vice versa.
|
||||||
|
|
||||||
|
This code receives messages and sends a message every second.
|
||||||
|
|
||||||
|
InvertIQ function basically invert the LoRa I and Q signals.
|
||||||
|
|
||||||
|
See the Semtech datasheet, http://www.semtech.com/images/datasheet/sx1276.pdf
|
||||||
|
for more on InvertIQ register 0x33.
|
||||||
|
|
||||||
|
created 05 August 2018
|
||||||
|
by Luiz H. Cassettari
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <SPI.h> // include libraries
|
||||||
|
#include <LoRa.h>
|
||||||
|
|
||||||
|
const long frequency = 915E6; // LoRa Frequency
|
||||||
|
|
||||||
|
const int csPin = 10; // LoRa radio chip select
|
||||||
|
const int resetPin = 9; // LoRa radio reset
|
||||||
|
const int irqPin = 2; // change for your board; must be a hardware interrupt pin
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(9600); // initialize serial
|
||||||
|
while (!Serial);
|
||||||
|
|
||||||
|
LoRa.setPins(csPin, resetPin, irqPin);
|
||||||
|
|
||||||
|
if (!LoRa.begin(frequency)) {
|
||||||
|
Serial.println("LoRa init failed. Check your connections.");
|
||||||
|
while (true); // if failed, do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("LoRa init succeeded.");
|
||||||
|
Serial.println();
|
||||||
|
Serial.println("LoRa Simple Gateway");
|
||||||
|
Serial.println("Only receive messages from nodes");
|
||||||
|
Serial.println("Tx: invertIQ enable");
|
||||||
|
Serial.println("Rx: invertIQ disable");
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
LoRa.onReceive(onReceive);
|
||||||
|
LoRa_rxMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
if (runEvery(5000)) { // repeat every 5000 millis
|
||||||
|
|
||||||
|
String message = "HeLoRa World! ";
|
||||||
|
message += "I'm a Gateway! ";
|
||||||
|
message += millis();
|
||||||
|
|
||||||
|
LoRa_sendMessage(message); // send a message
|
||||||
|
|
||||||
|
Serial.println("Send Message!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoRa_rxMode(){
|
||||||
|
LoRa.disableInvertIQ(); // normal mode
|
||||||
|
LoRa.receive(); // set receive mode
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoRa_txMode(){
|
||||||
|
LoRa.idle(); // set standby mode
|
||||||
|
LoRa.enableInvertIQ(); // active invert I and Q signals
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoRa_sendMessage(String message) {
|
||||||
|
LoRa_txMode(); // set tx mode
|
||||||
|
LoRa.beginPacket(); // start packet
|
||||||
|
LoRa.print(message); // add payload
|
||||||
|
LoRa.endPacket(); // finish packet and send it
|
||||||
|
LoRa_rxMode(); // set rx mode
|
||||||
|
}
|
||||||
|
|
||||||
|
void onReceive(int packetSize) {
|
||||||
|
String message = "";
|
||||||
|
|
||||||
|
while (LoRa.available()) {
|
||||||
|
message += (char)LoRa.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print("Gateway Receive: ");
|
||||||
|
Serial.println(message);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean runEvery(unsigned long interval)
|
||||||
|
{
|
||||||
|
static unsigned long previousMillis = 0;
|
||||||
|
unsigned long currentMillis = millis();
|
||||||
|
if (currentMillis - previousMillis >= interval)
|
||||||
|
{
|
||||||
|
previousMillis = currentMillis;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
113
examples/LoRaSimpleNode/LoRaSimpleNode.ino
Normal file
113
examples/LoRaSimpleNode/LoRaSimpleNode.ino
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
LoRa Simple Gateway/Node Exemple
|
||||||
|
|
||||||
|
This code uses InvertIQ function to create a simple Gateway/Node logic.
|
||||||
|
|
||||||
|
Gateway - Sends messages with enableInvertIQ()
|
||||||
|
- Receives messages with disableInvertIQ()
|
||||||
|
|
||||||
|
Node - Sends messages with disableInvertIQ()
|
||||||
|
- Receives messages with enableInvertIQ()
|
||||||
|
|
||||||
|
With this arrangement a Gateway never receive messages from another Gateway
|
||||||
|
and a Node never receive message from another Node.
|
||||||
|
Only Gateway to Node and vice versa.
|
||||||
|
|
||||||
|
This code receives messages and sends a message every second.
|
||||||
|
|
||||||
|
InvertIQ function basically invert the LoRa I and Q signals.
|
||||||
|
|
||||||
|
See the Semtech datasheet, http://www.semtech.com/images/datasheet/sx1276.pdf
|
||||||
|
for more on InvertIQ register 0x33.
|
||||||
|
|
||||||
|
created 05 August 2018
|
||||||
|
by Luiz H. Cassettari
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <SPI.h> // include libraries
|
||||||
|
#include <LoRa.h>
|
||||||
|
|
||||||
|
const long frequency = 915E6; // LoRa Frequency
|
||||||
|
|
||||||
|
const int csPin = 10; // LoRa radio chip select
|
||||||
|
const int resetPin = 9; // LoRa radio reset
|
||||||
|
const int irqPin = 2; // change for your board; must be a hardware interrupt pin
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(9600); // initialize serial
|
||||||
|
while (!Serial);
|
||||||
|
|
||||||
|
LoRa.setPins(csPin, resetPin, irqPin);
|
||||||
|
|
||||||
|
if (!LoRa.begin(frequency)) {
|
||||||
|
Serial.println("LoRa init failed. Check your connections.");
|
||||||
|
while (true); // if failed, do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("LoRa init succeeded.");
|
||||||
|
Serial.println();
|
||||||
|
Serial.println("LoRa Simple Node");
|
||||||
|
Serial.println("Only receive messages from gateways");
|
||||||
|
Serial.println("Tx: invertIQ disable");
|
||||||
|
Serial.println("Rx: invertIQ enable");
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
LoRa.onReceive(onReceive);
|
||||||
|
LoRa_rxMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
if (runEvery(1000)) { // repeat every 1000 millis
|
||||||
|
|
||||||
|
String message = "HeLoRa World! ";
|
||||||
|
message += "I'm a Node! ";
|
||||||
|
message += millis();
|
||||||
|
|
||||||
|
LoRa_sendMessage(message); // send a message
|
||||||
|
|
||||||
|
Serial.println("Send Message!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoRa_rxMode(){
|
||||||
|
LoRa.enableInvertIQ(); // active invert I and Q signals
|
||||||
|
LoRa.receive(); // set receive mode
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoRa_txMode(){
|
||||||
|
LoRa.idle(); // set standby mode
|
||||||
|
LoRa.disableInvertIQ(); // normal mode
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoRa_sendMessage(String message) {
|
||||||
|
LoRa_txMode(); // set tx mode
|
||||||
|
LoRa.beginPacket(); // start packet
|
||||||
|
LoRa.print(message); // add payload
|
||||||
|
LoRa.endPacket(); // finish packet and send it
|
||||||
|
LoRa_rxMode(); // set rx mode
|
||||||
|
}
|
||||||
|
|
||||||
|
void onReceive(int packetSize) {
|
||||||
|
String message = "";
|
||||||
|
|
||||||
|
while (LoRa.available()) {
|
||||||
|
message += (char)LoRa.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.print("Node Receive: ");
|
||||||
|
Serial.println(message);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean runEvery(unsigned long interval)
|
||||||
|
{
|
||||||
|
static unsigned long previousMillis = 0;
|
||||||
|
unsigned long currentMillis = millis();
|
||||||
|
if (currentMillis - previousMillis >= interval)
|
||||||
|
{
|
||||||
|
previousMillis = currentMillis;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
@ -44,6 +44,8 @@ setPreambleLength KEYWORD2
|
|||||||
setSyncWord KEYWORD2
|
setSyncWord KEYWORD2
|
||||||
enableCrc KEYWORD2
|
enableCrc KEYWORD2
|
||||||
disableCrc KEYWORD2
|
disableCrc KEYWORD2
|
||||||
|
enableInvertIQ KEYWORD2
|
||||||
|
disableInvertIQ KEYWORD2
|
||||||
|
|
||||||
random KEYWORD2
|
random KEYWORD2
|
||||||
setPins KEYWORD2
|
setPins KEYWORD2
|
||||||
|
14
src/LoRa.cpp
14
src/LoRa.cpp
@ -31,8 +31,10 @@
|
|||||||
#define REG_FREQ_ERROR_LSB 0x2a
|
#define REG_FREQ_ERROR_LSB 0x2a
|
||||||
#define REG_RSSI_WIDEBAND 0x2c
|
#define REG_RSSI_WIDEBAND 0x2c
|
||||||
#define REG_DETECTION_OPTIMIZE 0x31
|
#define REG_DETECTION_OPTIMIZE 0x31
|
||||||
|
#define REG_INVERTIQ 0x33
|
||||||
#define REG_DETECTION_THRESHOLD 0x37
|
#define REG_DETECTION_THRESHOLD 0x37
|
||||||
#define REG_SYNC_WORD 0x39
|
#define REG_SYNC_WORD 0x39
|
||||||
|
#define REG_INVERTIQ2 0x3b
|
||||||
#define REG_DIO_MAPPING_1 0x40
|
#define REG_DIO_MAPPING_1 0x40
|
||||||
#define REG_VERSION 0x42
|
#define REG_VERSION 0x42
|
||||||
#define REG_PA_DAC 0x4d
|
#define REG_PA_DAC 0x4d
|
||||||
@ -531,6 +533,18 @@ void LoRaClass::disableCrc()
|
|||||||
writeRegister(REG_MODEM_CONFIG_2, readRegister(REG_MODEM_CONFIG_2) & 0xfb);
|
writeRegister(REG_MODEM_CONFIG_2, readRegister(REG_MODEM_CONFIG_2) & 0xfb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LoRaClass::enableInvertIQ()
|
||||||
|
{
|
||||||
|
writeRegister(REG_INVERTIQ, 0x66);
|
||||||
|
writeRegister(REG_INVERTIQ2, 0x19);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LoRaClass::disableInvertIQ()
|
||||||
|
{
|
||||||
|
writeRegister(REG_INVERTIQ, 0x27);
|
||||||
|
writeRegister(REG_INVERTIQ2, 0x1d);
|
||||||
|
}
|
||||||
|
|
||||||
void LoRaClass::setOCP(uint8_t mA)
|
void LoRaClass::setOCP(uint8_t mA)
|
||||||
{
|
{
|
||||||
uint8_t ocpTrim = 27;
|
uint8_t ocpTrim = 27;
|
||||||
|
@ -66,6 +66,9 @@ public:
|
|||||||
void setSyncWord(int sw);
|
void setSyncWord(int sw);
|
||||||
void enableCrc();
|
void enableCrc();
|
||||||
void disableCrc();
|
void disableCrc();
|
||||||
|
void enableInvertIQ();
|
||||||
|
void disableInvertIQ();
|
||||||
|
|
||||||
void setOCP(uint8_t mA); // Over Current Protection control
|
void setOCP(uint8_t mA); // Over Current Protection control
|
||||||
|
|
||||||
// deprecated
|
// deprecated
|
||||||
|
Loading…
x
Reference in New Issue
Block a user