Skip to content

Commit 1cf44e5

Browse files
committed
Merge branch 'master' into fix-ISR-not-in-IRAM
2 parents 77a7643 + dee0fdb commit 1cf44e5

File tree

12 files changed

+481
-40
lines changed

12 files changed

+481
-40
lines changed

.travis.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ env:
99
- BOARD="arduino:samd:arduino_zero_edbg"
1010
- BOARD="arduino:samd:mkr1000"
1111
- BOARD="arduino:samd:mkrzero"
12+
- BOARD="arduino:samd:mkrwan1300"
1213
before_install:
1314
- wget http://downloads.arduino.cc/arduino-$IDE_VERSION-linux64.tar.xz
1415
- tar xf arduino-$IDE_VERSION-linux64.tar.xz
@@ -24,9 +25,14 @@ install:
2425
script:
2526
- buildExampleSketch LoRaDumpRegisters
2627
- buildExampleSketch LoRaDuplex
27-
- buildExampleSketch LoRaDuplexCallback
28+
- if [[ "$BOARD" != "arduino:samd:mkrwan1300" ]]; then
29+
buildExampleSketch LoRaDuplexCallback;
30+
fi
2831
- buildExampleSketch LoRaReceiver
29-
- buildExampleSketch LoRaReceiverCallback
32+
- if [[ "$BOARD" != "arduino:samd:mkrwan1300" ]]; then
33+
buildExampleSketch LoRaReceiverCallback;
34+
fi
3035
- buildExampleSketch LoRaSender
36+
- buildExampleSketch LoRaSenderNonBlocking
3137
- buildExampleSketch LoRaSetSpread
3238
- buildExampleSketch LoRaSetSyncWord

API.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ To save further pins one could connect the reset pin of the MCU with reset pin o
3838

3939
* `reset` - set to `-1` to omit this pin
4040

41+
### Set SPI interface
42+
43+
Override the default SPI interface used by the library. **Must** be called before `LoRa.begin()`.
44+
45+
```arduino
46+
LoRa.setSPI(spi);
47+
```
48+
* `spi` - new SPI interface to use, defaults to `SPI`
49+
50+
This call is optional and only needs to be used if you need to change the default SPI interface used, in the case your Arduino (or compatible) board has more than one SPI interface present.
51+
4152
### Set SPI Frequency
4253

4354
Override the default SPI frequency of 10 MHz used by the library. **Must** be called before `LoRa.begin()`.
@@ -71,7 +82,7 @@ LoRa.beginPacket(implicitHeader);
7182

7283
* `implicitHeader` - (optional) `true` enables implicit header mode, `false` enables explicit header mode (default)
7384

74-
Returns `1` on success, `0` on failure.
85+
Returns `1` if radio is ready to transmit, `0` if busy or on failure.
7586

7687
### Writing
7788

@@ -98,8 +109,11 @@ Returns the number of bytes written.
98109
End the sequence of sending a packet.
99110

100111
```arduino
101-
LoRa.endPacket()
112+
LoRa.endPacket();
113+
114+
LoRa.endPacket(async);
102115
```
116+
* `async` - (optional) `true` enables non-blocking mode, `false` waits for transmission to be completed (default)
103117

104118
Returns `1` on success, `0` on failure.
105119

@@ -122,6 +136,8 @@ Returns the packet size in bytes or `0` if no packet was received.
122136

123137
### Continuous receive mode
124138

139+
**WARNING**: Not supported on the Arduino MKR WAN 1300 board!
140+
125141
#### Register callback
126142

127143
Register a callback function for when a packet is received.
@@ -236,7 +252,7 @@ LoRa.setTxPower(txPower, outputPin);
236252
* `txPower` - TX power in dB, defaults to `17`
237253
* `outputPin` - (optional) PA output pin, supported values are `PA_OUTPUT_RFO_PIN` and `PA_OUTPUT_PA_BOOST_PIN`, defaults to `PA_OUTPUT_PA_BOOST_PIN`.
238254

239-
Supported values are between `2` and `17` for `PA_OUTPUT_PA_BOOST_PIN`, `0` and `14` for `PA_OUTPUT_RFO_PIN`.
255+
Supported values are `2` to `20` for `PA_OUTPUT_PA_BOOST_PIN`, and `0` to `14` for `PA_OUTPUT_RFO_PIN`.
240256

241257
Most modules have the PA output pin connected to PA BOOST,
242258

@@ -304,7 +320,7 @@ Change the sync word of the radio.
304320
LoRa.setSyncWord(syncWord);
305321
```
306322

307-
* `syncWord` - byte value to use as the sync word, defaults to `0x34`
323+
* `syncWord` - byte value to use as the sync word, defaults to `0x12`
308324

309325
### CRC
310326

@@ -316,6 +332,16 @@ LoRa.enableCrc();
316332
LoRa.disableCrc();
317333
```
318334

335+
### Invert IQ Signals
336+
337+
Enable or disable Invert the LoRa I and Q signals, by default a invertIQ is not used.
338+
339+
```arduino
340+
LoRa.enableInvertIQ();
341+
342+
LoRa.disableInvertIQ();
343+
```
344+
319345
## Other functions
320346

321347
### Random

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ An [Arduino](https://arduino.cc/) library for sending and receiving data using [
1010
* [Dragino Lora Shield](http://www.dragino.com/products/module/item/102-lora-shield.html)
1111
* [HopeRF](http://www.hoperf.com/rf_transceiver/lora/) [RFM95W](http://www.hoperf.com/rf_transceiver/lora/RFM95W.html), [RFM96W](http://www.hoperf.com/rf_transceiver/lora/RFM96W.html), and [RFM98W](http://www.hoperf.com/rf_transceiver/lora/RFM98W.html)
1212
* [Modtronix](http://modtronix.com/) [inAir4](http://modtronix.com/inair4.html), [inAir9](http://modtronix.com/inair9.html), and [inAir9B](http://modtronix.com/inair9b.html)
13+
* [Arduino MKR WAN 1300](https://store.arduino.cc/usa/mkr-wan-1300)
14+
* **NOTE:** Requires firmware v1.1.6 or later on the on-board Murata module. Please use the [MKRWANFWUpdate_standalone example](https://github.com/arduino-libraries/MKRWAN/blob/master/examples/MKRWANFWUpdate_standalone/MKRWANFWUpdate_standalone.ino) from latest [MKRWAN library](https://github.com/arduino-libraries/MKRWAN) release to update the firmware.
15+
* **WARNING**: [LoRa.onReceive(...)](https://github.com/sandeepmistry/arduino-LoRa/blob/master/API.md#register-callback) and [LoRa.recieve()](https://github.com/sandeepmistry/arduino-LoRa/blob/master/API.md#receive-mode) is not compatible with this board!
1316

1417
### Semtech SX1276/77/78/79 wiring
1518

examples/LoRaDuplexCallback/LoRaDuplexCallback.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#include <SPI.h> // include libraries
1616
#include <LoRa.h>
1717

18+
#ifdef ARDUINO_SAMD_MKRWAN1300
19+
#error "This example is not compatible with the Arduino MKR WAN 1300 board!"
20+
#endif
21+
1822
const int csPin = 7; // LoRa radio chip select
1923
const int resetPin = 6; // LoRa radio reset
2024
const int irqPin = 1; // change for your board; must be a hardware interrupt pin

examples/LoRaReceiverCallback/LoRaReceiverCallback.ino

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include <SPI.h>
22
#include <LoRa.h>
33

4+
#ifdef ARDUINO_SAMD_MKRWAN1300
5+
#error "This example is not compatible with the Arduino MKR WAN 1300 board!"
6+
#endif
7+
48
void setup() {
59
Serial.begin(9600);
610
while (!Serial);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <SPI.h>
2+
#include <LoRa.h>
3+
4+
int counter = 0;
5+
6+
void setup() {
7+
Serial.begin(9600);
8+
while (!Serial);
9+
10+
Serial.println("LoRa Sender non-blocking");
11+
12+
if (!LoRa.begin(915E6)) {
13+
Serial.println("Starting LoRa failed!");
14+
while (1);
15+
}
16+
}
17+
18+
void loop() {
19+
// wait until the radio is ready to send a packet
20+
while (LoRa.beginPacket() == 0) {
21+
Serial.print("waiting for radio ... ");
22+
delay(100);
23+
}
24+
25+
Serial.print("Sending packet non-blocking: ");
26+
Serial.println(counter);
27+
28+
// send in async / non-blocking mode
29+
LoRa.beginPacket();
30+
LoRa.print("hello ");
31+
LoRa.print(counter);
32+
LoRa.endPacket(true); // true = async / non-blocking mode
33+
34+
counter++;
35+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
LoRa Simple Gateway/Node Exemple
3+
4+
This code uses InvertIQ function to create a simple Gateway/Node logic.
5+
6+
Gateway - Sends messages with enableInvertIQ()
7+
- Receives messages with disableInvertIQ()
8+
9+
Node - Sends messages with disableInvertIQ()
10+
- Receives messages with enableInvertIQ()
11+
12+
With this arrangement a Gateway never receive messages from another Gateway
13+
and a Node never receive message from another Node.
14+
Only Gateway to Node and vice versa.
15+
16+
This code receives messages and sends a message every second.
17+
18+
InvertIQ function basically invert the LoRa I and Q signals.
19+
20+
See the Semtech datasheet, http://www.semtech.com/images/datasheet/sx1276.pdf
21+
for more on InvertIQ register 0x33.
22+
23+
created 05 August 2018
24+
by Luiz H. Cassettari
25+
*/
26+
27+
#include <SPI.h> // include libraries
28+
#include <LoRa.h>
29+
30+
const long frequency = 915E6; // LoRa Frequency
31+
32+
const int csPin = 10; // LoRa radio chip select
33+
const int resetPin = 9; // LoRa radio reset
34+
const int irqPin = 2; // change for your board; must be a hardware interrupt pin
35+
36+
void setup() {
37+
Serial.begin(9600); // initialize serial
38+
while (!Serial);
39+
40+
LoRa.setPins(csPin, resetPin, irqPin);
41+
42+
if (!LoRa.begin(frequency)) {
43+
Serial.println("LoRa init failed. Check your connections.");
44+
while (true); // if failed, do nothing
45+
}
46+
47+
Serial.println("LoRa init succeeded.");
48+
Serial.println();
49+
Serial.println("LoRa Simple Gateway");
50+
Serial.println("Only receive messages from nodes");
51+
Serial.println("Tx: invertIQ enable");
52+
Serial.println("Rx: invertIQ disable");
53+
Serial.println();
54+
55+
LoRa.onReceive(onReceive);
56+
LoRa_rxMode();
57+
}
58+
59+
void loop() {
60+
if (runEvery(5000)) { // repeat every 5000 millis
61+
62+
String message = "HeLoRa World! ";
63+
message += "I'm a Gateway! ";
64+
message += millis();
65+
66+
LoRa_sendMessage(message); // send a message
67+
68+
Serial.println("Send Message!");
69+
}
70+
}
71+
72+
void LoRa_rxMode(){
73+
LoRa.disableInvertIQ(); // normal mode
74+
LoRa.receive(); // set receive mode
75+
}
76+
77+
void LoRa_txMode(){
78+
LoRa.idle(); // set standby mode
79+
LoRa.enableInvertIQ(); // active invert I and Q signals
80+
}
81+
82+
void LoRa_sendMessage(String message) {
83+
LoRa_txMode(); // set tx mode
84+
LoRa.beginPacket(); // start packet
85+
LoRa.print(message); // add payload
86+
LoRa.endPacket(); // finish packet and send it
87+
LoRa_rxMode(); // set rx mode
88+
}
89+
90+
void onReceive(int packetSize) {
91+
String message = "";
92+
93+
while (LoRa.available()) {
94+
message += (char)LoRa.read();
95+
}
96+
97+
Serial.print("Gateway Receive: ");
98+
Serial.println(message);
99+
100+
}
101+
102+
boolean runEvery(unsigned long interval)
103+
{
104+
static unsigned long previousMillis = 0;
105+
unsigned long currentMillis = millis();
106+
if (currentMillis - previousMillis >= interval)
107+
{
108+
previousMillis = currentMillis;
109+
return true;
110+
}
111+
return false;
112+
}
113+

0 commit comments

Comments
 (0)