mirror of
https://github.com/sandeepmistry/arduino-LoRa.git
synced 2025-04-19 13:02:14 +03:00
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
This commit is contained in:
parent
a2636d10a9
commit
039b138d80
@ -9,6 +9,7 @@ env:
|
|||||||
- BOARD="arduino:samd:arduino_zero_edbg"
|
- BOARD="arduino:samd:arduino_zero_edbg"
|
||||||
- BOARD="arduino:samd:mkr1000"
|
- BOARD="arduino:samd:mkr1000"
|
||||||
- BOARD="arduino:samd:mkrzero"
|
- BOARD="arduino:samd:mkrzero"
|
||||||
|
- BOARD="arduino:samd:mkrwan1300"
|
||||||
before_install:
|
before_install:
|
||||||
- wget http://downloads.arduino.cc/arduino-$IDE_VERSION-linux64.tar.xz
|
- wget http://downloads.arduino.cc/arduino-$IDE_VERSION-linux64.tar.xz
|
||||||
- tar xf arduino-$IDE_VERSION-linux64.tar.xz
|
- tar xf arduino-$IDE_VERSION-linux64.tar.xz
|
||||||
@ -24,9 +25,13 @@ install:
|
|||||||
script:
|
script:
|
||||||
- buildExampleSketch LoRaDumpRegisters
|
- buildExampleSketch LoRaDumpRegisters
|
||||||
- buildExampleSketch LoRaDuplex
|
- buildExampleSketch LoRaDuplex
|
||||||
- buildExampleSketch LoRaDuplexCallback
|
- if [[ "$BOARD" != "arduino:samd:mkrwan1300" ]]; then
|
||||||
|
buildExampleSketch LoRaDuplexCallback;
|
||||||
|
fi
|
||||||
- buildExampleSketch LoRaReceiver
|
- buildExampleSketch LoRaReceiver
|
||||||
- buildExampleSketch LoRaReceiverCallback
|
- if [[ "$BOARD" != "arduino:samd:mkrwan1300" ]]; then
|
||||||
|
buildExampleSketch LoRaReceiverCallback;
|
||||||
|
fi
|
||||||
- buildExampleSketch LoRaSender
|
- buildExampleSketch LoRaSender
|
||||||
- buildExampleSketch LoRaSetSpread
|
- buildExampleSketch LoRaSetSpread
|
||||||
- buildExampleSketch LoRaSetSyncWord
|
- buildExampleSketch LoRaSetSyncWord
|
||||||
|
13
API.md
13
API.md
@ -38,6 +38,17 @@ To save further pins one could connect the reset pin of the MCU with reset pin o
|
|||||||
|
|
||||||
* `reset` - set to `-1` to omit this pin
|
* `reset` - set to `-1` to omit this pin
|
||||||
|
|
||||||
|
### Set SPI interface
|
||||||
|
|
||||||
|
Override the default SPI interface used by the library. **Must** be called before `LoRa.begin()`.
|
||||||
|
|
||||||
|
```arduino
|
||||||
|
LoRa.setSPI(spi);
|
||||||
|
```
|
||||||
|
* `spi` - new SPI interface to use, defaults to `SPI`
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
### Set SPI Frequency
|
### Set SPI Frequency
|
||||||
|
|
||||||
Override the default SPI frequency of 10 MHz used by the library. **Must** be called before `LoRa.begin()`.
|
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.
|
|||||||
|
|
||||||
### Continuous receive mode
|
### Continuous receive mode
|
||||||
|
|
||||||
|
**WARNING**: Not supported on the Arduino MKR WAN 1300 board!
|
||||||
|
|
||||||
#### Register callback
|
#### Register callback
|
||||||
|
|
||||||
Register a callback function for when a packet is received.
|
Register a callback function for when a packet is received.
|
||||||
|
@ -10,6 +10,9 @@ An [Arduino](https://arduino.cc/) library for sending and receiving data using [
|
|||||||
* [Dragino Lora Shield](http://www.dragino.com/products/module/item/102-lora-shield.html)
|
* [Dragino Lora Shield](http://www.dragino.com/products/module/item/102-lora-shield.html)
|
||||||
* [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)
|
* [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)
|
||||||
* [Modtronix](http://modtronix.com/) [inAir4](http://modtronix.com/inair4.html), [inAir9](http://modtronix.com/inair9.html), and [inAir9B](http://modtronix.com/inair9b.html)
|
* [Modtronix](http://modtronix.com/) [inAir4](http://modtronix.com/inair4.html), [inAir9](http://modtronix.com/inair9.html), and [inAir9B](http://modtronix.com/inair9b.html)
|
||||||
|
* [Arduino MKR WAN 1300](https://store.arduino.cc/usa/mkr-wan-1300)
|
||||||
|
* **NOTE:** Requires firmware v1.1.6 or later on the on-board Murata module
|
||||||
|
* **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!
|
||||||
|
|
||||||
### Semtech SX1276/77/78/79 wiring
|
### Semtech SX1276/77/78/79 wiring
|
||||||
|
|
||||||
|
@ -15,6 +15,10 @@
|
|||||||
#include <SPI.h> // include libraries
|
#include <SPI.h> // include libraries
|
||||||
#include <LoRa.h>
|
#include <LoRa.h>
|
||||||
|
|
||||||
|
#ifdef ARDUINO_SAMD_MKRWAN1300
|
||||||
|
#error "This example is not compatible with the Arduino MKR WAN 1300 board!"
|
||||||
|
#endif
|
||||||
|
|
||||||
const int csPin = 7; // LoRa radio chip select
|
const int csPin = 7; // LoRa radio chip select
|
||||||
const int resetPin = 6; // LoRa radio reset
|
const int resetPin = 6; // LoRa radio reset
|
||||||
const int irqPin = 1; // change for your board; must be a hardware interrupt pin
|
const int irqPin = 1; // change for your board; must be a hardware interrupt pin
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <LoRa.h>
|
#include <LoRa.h>
|
||||||
|
|
||||||
|
#ifdef ARDUINO_SAMD_MKRWAN1300
|
||||||
|
#error "This example is not compatible with the Arduino MKR WAN 1300 board!"
|
||||||
|
#endif
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
while (!Serial);
|
while (!Serial);
|
||||||
|
39
src/LoRa.cpp
39
src/LoRa.cpp
@ -54,7 +54,8 @@
|
|||||||
#define MAX_PKT_LENGTH 255
|
#define MAX_PKT_LENGTH 255
|
||||||
|
|
||||||
LoRaClass::LoRaClass() :
|
LoRaClass::LoRaClass() :
|
||||||
_spiSettings(8E6, MSBFIRST, SPI_MODE0),
|
_spiSettings(LORA_DEFAULT_SPI_FREQUENCY, MSBFIRST, SPI_MODE0),
|
||||||
|
_spi(&LORA_DEFAULT_SPI),
|
||||||
_ss(LORA_DEFAULT_SS_PIN), _reset(LORA_DEFAULT_RESET_PIN), _dio0(LORA_DEFAULT_DIO0_PIN),
|
_ss(LORA_DEFAULT_SS_PIN), _reset(LORA_DEFAULT_RESET_PIN), _dio0(LORA_DEFAULT_DIO0_PIN),
|
||||||
_frequency(0),
|
_frequency(0),
|
||||||
_packetIndex(0),
|
_packetIndex(0),
|
||||||
@ -67,6 +68,23 @@ LoRaClass::LoRaClass() :
|
|||||||
|
|
||||||
int LoRaClass::begin(long frequency)
|
int LoRaClass::begin(long frequency)
|
||||||
{
|
{
|
||||||
|
#ifdef ARDUINO_SAMD_MKRWAN1300
|
||||||
|
pinMode(LORA_IRQ_DUMB, OUTPUT);
|
||||||
|
digitalWrite(LORA_IRQ_DUMB, LOW);
|
||||||
|
|
||||||
|
// Hardware reset
|
||||||
|
pinMode(LORA_BOOT0, OUTPUT);
|
||||||
|
digitalWrite(LORA_BOOT0, LOW);
|
||||||
|
|
||||||
|
pinMode(LORA_RESET, OUTPUT);
|
||||||
|
digitalWrite(LORA_RESET, HIGH);
|
||||||
|
delay(200);
|
||||||
|
digitalWrite(LORA_RESET, LOW);
|
||||||
|
delay(200);
|
||||||
|
digitalWrite(LORA_RESET, HIGH);
|
||||||
|
delay(50);
|
||||||
|
#endif
|
||||||
|
|
||||||
// setup pins
|
// setup pins
|
||||||
pinMode(_ss, OUTPUT);
|
pinMode(_ss, OUTPUT);
|
||||||
// set SS high
|
// set SS high
|
||||||
@ -83,7 +101,7 @@ int LoRaClass::begin(long frequency)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// start SPI
|
// start SPI
|
||||||
SPI.begin();
|
_spi->begin();
|
||||||
|
|
||||||
// check version
|
// check version
|
||||||
uint8_t version = readRegister(REG_VERSION);
|
uint8_t version = readRegister(REG_VERSION);
|
||||||
@ -122,7 +140,7 @@ void LoRaClass::end()
|
|||||||
sleep();
|
sleep();
|
||||||
|
|
||||||
// stop SPI
|
// stop SPI
|
||||||
SPI.end();
|
_spi->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
int LoRaClass::beginPacket(int implicitHeader)
|
int LoRaClass::beginPacket(int implicitHeader)
|
||||||
@ -296,6 +314,7 @@ void LoRaClass::flush()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef ARDUINO_SAMD_MKRWAN1300
|
||||||
void LoRaClass::onReceive(void(*callback)(int))
|
void LoRaClass::onReceive(void(*callback)(int))
|
||||||
{
|
{
|
||||||
_onReceive = callback;
|
_onReceive = callback;
|
||||||
@ -328,6 +347,7 @@ void LoRaClass::receive(int size)
|
|||||||
|
|
||||||
writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_RX_CONTINUOUS);
|
writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_RX_CONTINUOUS);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void LoRaClass::idle()
|
void LoRaClass::idle()
|
||||||
{
|
{
|
||||||
@ -504,6 +524,11 @@ void LoRaClass::setPins(int ss, int reset, int dio0)
|
|||||||
_dio0 = dio0;
|
_dio0 = dio0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LoRaClass::setSPI(SPIClass& spi)
|
||||||
|
{
|
||||||
|
_spi = &spi;
|
||||||
|
}
|
||||||
|
|
||||||
void LoRaClass::setSPIFrequency(uint32_t frequency)
|
void LoRaClass::setSPIFrequency(uint32_t frequency)
|
||||||
{
|
{
|
||||||
_spiSettings = SPISettings(frequency, MSBFIRST, SPI_MODE0);
|
_spiSettings = SPISettings(frequency, MSBFIRST, SPI_MODE0);
|
||||||
@ -575,10 +600,10 @@ uint8_t LoRaClass::singleTransfer(uint8_t address, uint8_t value)
|
|||||||
|
|
||||||
digitalWrite(_ss, LOW);
|
digitalWrite(_ss, LOW);
|
||||||
|
|
||||||
SPI.beginTransaction(_spiSettings);
|
_spi->beginTransaction(_spiSettings);
|
||||||
SPI.transfer(address);
|
_spi->transfer(address);
|
||||||
response = SPI.transfer(value);
|
response = _spi->transfer(value);
|
||||||
SPI.endTransaction();
|
_spi->endTransaction();
|
||||||
|
|
||||||
digitalWrite(_ss, HIGH);
|
digitalWrite(_ss, HIGH);
|
||||||
|
|
||||||
|
24
src/LoRa.h
24
src/LoRa.h
@ -7,12 +7,22 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
|
||||||
#define LORA_DEFAULT_SS_PIN 10
|
#ifdef ARDUINO_SAMD_MKRWAN1300
|
||||||
#define LORA_DEFAULT_RESET_PIN 9
|
#define LORA_DEFAULT_SPI SPI1
|
||||||
#define LORA_DEFAULT_DIO0_PIN 2
|
#define LORA_DEFAULT_SPI_FREQUENCY 250000
|
||||||
|
#define LORA_DEFAULT_SS_PIN LORA_IRQ_DUMB
|
||||||
|
#define LORA_DEFAULT_RESET_PIN -1
|
||||||
|
#define LORA_DEFAULT_DIO0_PIN -1
|
||||||
|
#else
|
||||||
|
#define LORA_DEFAULT_SPI SPI
|
||||||
|
#define LORA_DEFAULT_SPI_FREQUENCY 8E6
|
||||||
|
#define LORA_DEFAULT_SS_PIN 10
|
||||||
|
#define LORA_DEFAULT_RESET_PIN 9
|
||||||
|
#define LORA_DEFAULT_DIO0_PIN 2
|
||||||
|
#endif
|
||||||
|
|
||||||
#define PA_OUTPUT_RFO_PIN 0
|
#define PA_OUTPUT_RFO_PIN 0
|
||||||
#define PA_OUTPUT_PA_BOOST_PIN 1
|
#define PA_OUTPUT_PA_BOOST_PIN 1
|
||||||
|
|
||||||
class LoRaClass : public Stream {
|
class LoRaClass : public Stream {
|
||||||
public:
|
public:
|
||||||
@ -39,9 +49,11 @@ public:
|
|||||||
virtual int peek();
|
virtual int peek();
|
||||||
virtual void flush();
|
virtual void flush();
|
||||||
|
|
||||||
|
#ifndef ARDUINO_SAMD_MKRWAN1300
|
||||||
void onReceive(void(*callback)(int));
|
void onReceive(void(*callback)(int));
|
||||||
|
|
||||||
void receive(int size = 0);
|
void receive(int size = 0);
|
||||||
|
#endif
|
||||||
void idle();
|
void idle();
|
||||||
void sleep();
|
void sleep();
|
||||||
|
|
||||||
@ -62,6 +74,7 @@ public:
|
|||||||
byte random();
|
byte random();
|
||||||
|
|
||||||
void setPins(int ss = LORA_DEFAULT_SS_PIN, int reset = LORA_DEFAULT_RESET_PIN, int dio0 = LORA_DEFAULT_DIO0_PIN);
|
void setPins(int ss = LORA_DEFAULT_SS_PIN, int reset = LORA_DEFAULT_RESET_PIN, int dio0 = LORA_DEFAULT_DIO0_PIN);
|
||||||
|
void setSPI(SPIClass& spi);
|
||||||
void setSPIFrequency(uint32_t frequency);
|
void setSPIFrequency(uint32_t frequency);
|
||||||
|
|
||||||
void dumpRegisters(Stream& out);
|
void dumpRegisters(Stream& out);
|
||||||
@ -85,6 +98,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
SPISettings _spiSettings;
|
SPISettings _spiSettings;
|
||||||
|
SPIClass* _spi;
|
||||||
int _ss;
|
int _ss;
|
||||||
int _reset;
|
int _reset;
|
||||||
int _dio0;
|
int _dio0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user