Skip to content

Commit 039b138

Browse files
Add support for Arduino MKR WAN 1300 boards (#105)
* Add support for Arduino MKR WAN 1300 board * Add new LoRa.setSPI(...) API to use radio with a different SPI interface * Disable LoRa.onReceive(...) and LoRa.receive() on Arduino MKR WAN 1300 * Add errors on sketches not compatible with the Arduino MKR WAN 1300
1 parent a2636d1 commit 039b138

File tree

7 files changed

+82
-14
lines changed

7 files changed

+82
-14
lines changed

Diff for: .travis.yml

+7-2
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,13 @@ 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
3136
- buildExampleSketch LoRaSetSpread
3237
- buildExampleSketch LoRaSetSyncWord

Diff for: API.md

+13
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()`.
@@ -122,6 +133,8 @@ Returns the packet size in bytes or `0` if no packet was received.
122133

123134
### Continuous receive mode
124135

136+
**WARNING**: Not supported on the Arduino MKR WAN 1300 board!
137+
125138
#### Register callback
126139

127140
Register a callback function for when a packet is received.

Diff for: README.md

+3
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
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

Diff for: examples/LoRaDuplexCallback/LoRaDuplexCallback.ino

+4
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

Diff for: examples/LoRaReceiverCallback/LoRaReceiverCallback.ino

+4
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);

Diff for: src/LoRa.cpp

+32-7
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
#define MAX_PKT_LENGTH 255
5555

5656
LoRaClass::LoRaClass() :
57-
_spiSettings(8E6, MSBFIRST, SPI_MODE0),
57+
_spiSettings(LORA_DEFAULT_SPI_FREQUENCY, MSBFIRST, SPI_MODE0),
58+
_spi(&LORA_DEFAULT_SPI),
5859
_ss(LORA_DEFAULT_SS_PIN), _reset(LORA_DEFAULT_RESET_PIN), _dio0(LORA_DEFAULT_DIO0_PIN),
5960
_frequency(0),
6061
_packetIndex(0),
@@ -67,6 +68,23 @@ LoRaClass::LoRaClass() :
6768

6869
int LoRaClass::begin(long frequency)
6970
{
71+
#ifdef ARDUINO_SAMD_MKRWAN1300
72+
pinMode(LORA_IRQ_DUMB, OUTPUT);
73+
digitalWrite(LORA_IRQ_DUMB, LOW);
74+
75+
// Hardware reset
76+
pinMode(LORA_BOOT0, OUTPUT);
77+
digitalWrite(LORA_BOOT0, LOW);
78+
79+
pinMode(LORA_RESET, OUTPUT);
80+
digitalWrite(LORA_RESET, HIGH);
81+
delay(200);
82+
digitalWrite(LORA_RESET, LOW);
83+
delay(200);
84+
digitalWrite(LORA_RESET, HIGH);
85+
delay(50);
86+
#endif
87+
7088
// setup pins
7189
pinMode(_ss, OUTPUT);
7290
// set SS high
@@ -83,7 +101,7 @@ int LoRaClass::begin(long frequency)
83101
}
84102

85103
// start SPI
86-
SPI.begin();
104+
_spi->begin();
87105

88106
// check version
89107
uint8_t version = readRegister(REG_VERSION);
@@ -122,7 +140,7 @@ void LoRaClass::end()
122140
sleep();
123141

124142
// stop SPI
125-
SPI.end();
143+
_spi->end();
126144
}
127145

128146
int LoRaClass::beginPacket(int implicitHeader)
@@ -296,6 +314,7 @@ void LoRaClass::flush()
296314
{
297315
}
298316

317+
#ifndef ARDUINO_SAMD_MKRWAN1300
299318
void LoRaClass::onReceive(void(*callback)(int))
300319
{
301320
_onReceive = callback;
@@ -328,6 +347,7 @@ void LoRaClass::receive(int size)
328347

329348
writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_RX_CONTINUOUS);
330349
}
350+
#endif
331351

332352
void LoRaClass::idle()
333353
{
@@ -504,6 +524,11 @@ void LoRaClass::setPins(int ss, int reset, int dio0)
504524
_dio0 = dio0;
505525
}
506526

527+
void LoRaClass::setSPI(SPIClass& spi)
528+
{
529+
_spi = &spi;
530+
}
531+
507532
void LoRaClass::setSPIFrequency(uint32_t frequency)
508533
{
509534
_spiSettings = SPISettings(frequency, MSBFIRST, SPI_MODE0);
@@ -575,10 +600,10 @@ uint8_t LoRaClass::singleTransfer(uint8_t address, uint8_t value)
575600

576601
digitalWrite(_ss, LOW);
577602

578-
SPI.beginTransaction(_spiSettings);
579-
SPI.transfer(address);
580-
response = SPI.transfer(value);
581-
SPI.endTransaction();
603+
_spi->beginTransaction(_spiSettings);
604+
_spi->transfer(address);
605+
response = _spi->transfer(value);
606+
_spi->endTransaction();
582607

583608
digitalWrite(_ss, HIGH);
584609

Diff for: src/LoRa.h

+19-5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,22 @@
77
#include <Arduino.h>
88
#include <SPI.h>
99

10-
#define LORA_DEFAULT_SS_PIN 10
11-
#define LORA_DEFAULT_RESET_PIN 9
12-
#define LORA_DEFAULT_DIO0_PIN 2
10+
#ifdef ARDUINO_SAMD_MKRWAN1300
11+
#define LORA_DEFAULT_SPI SPI1
12+
#define LORA_DEFAULT_SPI_FREQUENCY 250000
13+
#define LORA_DEFAULT_SS_PIN LORA_IRQ_DUMB
14+
#define LORA_DEFAULT_RESET_PIN -1
15+
#define LORA_DEFAULT_DIO0_PIN -1
16+
#else
17+
#define LORA_DEFAULT_SPI SPI
18+
#define LORA_DEFAULT_SPI_FREQUENCY 8E6
19+
#define LORA_DEFAULT_SS_PIN 10
20+
#define LORA_DEFAULT_RESET_PIN 9
21+
#define LORA_DEFAULT_DIO0_PIN 2
22+
#endif
1323

14-
#define PA_OUTPUT_RFO_PIN 0
15-
#define PA_OUTPUT_PA_BOOST_PIN 1
24+
#define PA_OUTPUT_RFO_PIN 0
25+
#define PA_OUTPUT_PA_BOOST_PIN 1
1626

1727
class LoRaClass : public Stream {
1828
public:
@@ -39,9 +49,11 @@ class LoRaClass : public Stream {
3949
virtual int peek();
4050
virtual void flush();
4151

52+
#ifndef ARDUINO_SAMD_MKRWAN1300
4253
void onReceive(void(*callback)(int));
4354

4455
void receive(int size = 0);
56+
#endif
4557
void idle();
4658
void sleep();
4759

@@ -62,6 +74,7 @@ class LoRaClass : public Stream {
6274
byte random();
6375

6476
void setPins(int ss = LORA_DEFAULT_SS_PIN, int reset = LORA_DEFAULT_RESET_PIN, int dio0 = LORA_DEFAULT_DIO0_PIN);
77+
void setSPI(SPIClass& spi);
6578
void setSPIFrequency(uint32_t frequency);
6679

6780
void dumpRegisters(Stream& out);
@@ -85,6 +98,7 @@ class LoRaClass : public Stream {
8598

8699
private:
87100
SPISettings _spiSettings;
101+
SPIClass* _spi;
88102
int _ss;
89103
int _reset;
90104
int _dio0;

0 commit comments

Comments
 (0)