1
0
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:
Sandeep Mistry 2018-05-07 13:02:06 -04:00 committed by GitHub
parent a2636d10a9
commit 039b138d80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 82 additions and 14 deletions

View File

@ -9,6 +9,7 @@ env:
- BOARD="arduino:samd:arduino_zero_edbg"
- BOARD="arduino:samd:mkr1000"
- BOARD="arduino:samd:mkrzero"
- BOARD="arduino:samd:mkrwan1300"
before_install:
- wget http://downloads.arduino.cc/arduino-$IDE_VERSION-linux64.tar.xz
- tar xf arduino-$IDE_VERSION-linux64.tar.xz
@ -24,9 +25,13 @@ install:
script:
- buildExampleSketch LoRaDumpRegisters
- buildExampleSketch LoRaDuplex
- buildExampleSketch LoRaDuplexCallback
- if [[ "$BOARD" != "arduino:samd:mkrwan1300" ]]; then
buildExampleSketch LoRaDuplexCallback;
fi
- buildExampleSketch LoRaReceiver
- buildExampleSketch LoRaReceiverCallback
- if [[ "$BOARD" != "arduino:samd:mkrwan1300" ]]; then
buildExampleSketch LoRaReceiverCallback;
fi
- buildExampleSketch LoRaSender
- buildExampleSketch LoRaSetSpread
- buildExampleSketch LoRaSetSyncWord

13
API.md
View File

@ -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
### 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
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
**WARNING**: Not supported on the Arduino MKR WAN 1300 board!
#### Register callback
Register a callback function for when a packet is received.

View File

@ -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)
* [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)
* [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

View File

@ -15,6 +15,10 @@
#include <SPI.h> // include libraries
#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 resetPin = 6; // LoRa radio reset
const int irqPin = 1; // change for your board; must be a hardware interrupt pin

View File

@ -1,6 +1,10 @@
#include <SPI.h>
#include <LoRa.h>
#ifdef ARDUINO_SAMD_MKRWAN1300
#error "This example is not compatible with the Arduino MKR WAN 1300 board!"
#endif
void setup() {
Serial.begin(9600);
while (!Serial);

View File

@ -54,7 +54,8 @@
#define MAX_PKT_LENGTH 255
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),
_frequency(0),
_packetIndex(0),
@ -67,6 +68,23 @@ LoRaClass::LoRaClass() :
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
pinMode(_ss, OUTPUT);
// set SS high
@ -83,7 +101,7 @@ int LoRaClass::begin(long frequency)
}
// start SPI
SPI.begin();
_spi->begin();
// check version
uint8_t version = readRegister(REG_VERSION);
@ -122,7 +140,7 @@ void LoRaClass::end()
sleep();
// stop SPI
SPI.end();
_spi->end();
}
int LoRaClass::beginPacket(int implicitHeader)
@ -296,6 +314,7 @@ void LoRaClass::flush()
{
}
#ifndef ARDUINO_SAMD_MKRWAN1300
void LoRaClass::onReceive(void(*callback)(int))
{
_onReceive = callback;
@ -328,6 +347,7 @@ void LoRaClass::receive(int size)
writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_RX_CONTINUOUS);
}
#endif
void LoRaClass::idle()
{
@ -504,6 +524,11 @@ void LoRaClass::setPins(int ss, int reset, int dio0)
_dio0 = dio0;
}
void LoRaClass::setSPI(SPIClass& spi)
{
_spi = &spi;
}
void LoRaClass::setSPIFrequency(uint32_t frequency)
{
_spiSettings = SPISettings(frequency, MSBFIRST, SPI_MODE0);
@ -575,10 +600,10 @@ uint8_t LoRaClass::singleTransfer(uint8_t address, uint8_t value)
digitalWrite(_ss, LOW);
SPI.beginTransaction(_spiSettings);
SPI.transfer(address);
response = SPI.transfer(value);
SPI.endTransaction();
_spi->beginTransaction(_spiSettings);
_spi->transfer(address);
response = _spi->transfer(value);
_spi->endTransaction();
digitalWrite(_ss, HIGH);

View File

@ -7,9 +7,19 @@
#include <Arduino.h>
#include <SPI.h>
#ifdef ARDUINO_SAMD_MKRWAN1300
#define LORA_DEFAULT_SPI SPI1
#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_PA_BOOST_PIN 1
@ -39,9 +49,11 @@ public:
virtual int peek();
virtual void flush();
#ifndef ARDUINO_SAMD_MKRWAN1300
void onReceive(void(*callback)(int));
void receive(int size = 0);
#endif
void idle();
void sleep();
@ -62,6 +74,7 @@ public:
byte random();
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 dumpRegisters(Stream& out);
@ -85,6 +98,7 @@ private:
private:
SPISettings _spiSettings;
SPIClass* _spi;
int _ss;
int _reset;
int _dio0;