[RF69] Changed pin mapping
This commit is contained in:
parent
540867365c
commit
0bc7208827
11 changed files with 70 additions and 41 deletions
|
@ -17,9 +17,9 @@
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// RF69 has the following connections:
|
// RF69 has the following connections:
|
||||||
// NSS pin: 10
|
// CS pin: 10
|
||||||
// DIO0 pin: 2
|
// DIO0 pin: 2
|
||||||
// DIO1 pin: 3
|
// RESET pin: 3
|
||||||
RF69 rf = new Module(10, 2, 3);
|
RF69 rf = new Module(10, 2, 3);
|
||||||
|
|
||||||
// or using RadioShield
|
// or using RadioShield
|
||||||
|
|
|
@ -13,9 +13,9 @@
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// RF69 has the following connections:
|
// RF69 has the following connections:
|
||||||
// NSS pin: 10
|
// CS pin: 10
|
||||||
// DIO0 pin: 2
|
// DIO0 pin: 2
|
||||||
// DIO1 pin: 3
|
// RESET pin: 3
|
||||||
RF69 rf = new Module(10, 2, 3);
|
RF69 rf = new Module(10, 2, 3);
|
||||||
|
|
||||||
// or using RadioShield
|
// or using RadioShield
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// RF69 has the following connections:
|
// RF69 has the following connections:
|
||||||
// NSS pin: 10
|
// CS pin: 10
|
||||||
// DIO0 pin: 2
|
// DIO0 pin: 2
|
||||||
// DIO1 pin: 3
|
// RESET pin: 3
|
||||||
RF69 rf = new Module(10, 2, 3);
|
RF69 rf = new Module(10, 2, 3);
|
||||||
|
|
||||||
// or using RadioShield
|
// or using RadioShield
|
||||||
|
|
|
@ -13,9 +13,9 @@
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// RF69 has the following connections:
|
// RF69 has the following connections:
|
||||||
// NSS pin: 10
|
// CS pin: 10
|
||||||
// DIO0 pin: 2
|
// DIO0 pin: 2
|
||||||
// DIO1 pin: 3
|
// RESET pin: 3
|
||||||
RF69 rf = new Module(10, 2, 3);
|
RF69 rf = new Module(10, 2, 3);
|
||||||
|
|
||||||
// or using RadioShield
|
// or using RadioShield
|
||||||
|
|
|
@ -19,15 +19,15 @@
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// RF69 has the following connections:
|
// RF69 has the following connections:
|
||||||
// NSS pin: 10
|
// CS pin: 10
|
||||||
// DIO0 pin: 2
|
// DIO0 pin: 2
|
||||||
// DIO1 pin: 3
|
// RESET pin: 3
|
||||||
RF69 rf1 = new Module(10, 2, 3);
|
RF69 rf1 = new Module(10, 2, 3);
|
||||||
|
|
||||||
// second CC1101 has different connections:
|
// second CC1101 has different connections:
|
||||||
// NSS pin: 9
|
// CS pin: 9
|
||||||
// DIO0 pin: 4
|
// DIO0 pin: 4
|
||||||
// DIO1 pin: 5
|
// RESET pin: 5
|
||||||
RF69 rf2 = new Module(9, 4, 5);
|
RF69 rf2 = new Module(9, 4, 5);
|
||||||
|
|
||||||
// or using RadioShield
|
// or using RadioShield
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// RF69 has the following connections:
|
// RF69 has the following connections:
|
||||||
// NSS pin: 10
|
// CS pin: 10
|
||||||
// DIO0 pin: 2
|
// DIO0 pin: 2
|
||||||
// DIO1 pin: 3
|
// RESET pin: 3
|
||||||
RF69 rf = new Module(10, 2, 3);
|
RF69 rf = new Module(10, 2, 3);
|
||||||
|
|
||||||
// or using RadioShield
|
// or using RadioShield
|
||||||
|
|
|
@ -13,9 +13,9 @@
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// RF69 has the following connections:
|
// RF69 has the following connections:
|
||||||
// NSS pin: 10
|
// CS pin: 10
|
||||||
// DIO0 pin: 2
|
// DIO0 pin: 2
|
||||||
// DIO1 pin: 3
|
// RESET pin: 3
|
||||||
RF69 rf = new Module(10, 2, 3);
|
RF69 rf = new Module(10, 2, 3);
|
||||||
|
|
||||||
// or using RadioShield
|
// or using RadioShield
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// RF69 has the following connections:
|
// RF69 has the following connections:
|
||||||
// NSS pin: 10
|
// CS pin: 10
|
||||||
// DIO0 pin: 2
|
// DIO0 pin: 2
|
||||||
// DIO1 pin: 3
|
// RESET pin: 3
|
||||||
RF69 rf = new Module(10, 2, 3);
|
RF69 rf = new Module(10, 2, 3);
|
||||||
|
|
||||||
// or using RadioShield
|
// or using RadioShield
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// RF69 has the following connections:
|
// RF69 has the following connections:
|
||||||
// NSS pin: 10
|
// CS pin: 10
|
||||||
// DIO0 pin: 2
|
// DIO0 pin: 2
|
||||||
// DIO1 pin: 3
|
// RESET pin: 3
|
||||||
RF69 rf = new Module(10, 2, 3);
|
RF69 rf = new Module(10, 2, 3);
|
||||||
|
|
||||||
// or using RadioShield
|
// or using RadioShield
|
||||||
|
|
|
@ -14,7 +14,11 @@ RF69::RF69(Module* module) : PhysicalLayer(RF69_CRYSTAL_FREQ, RF69_DIV_EXPONENT,
|
||||||
|
|
||||||
int16_t RF69::begin(float freq, float br, float rxBw, float freqDev, int8_t power) {
|
int16_t RF69::begin(float freq, float br, float rxBw, float freqDev, int8_t power) {
|
||||||
// set module properties
|
// set module properties
|
||||||
_mod->init(RADIOLIB_USE_SPI, RADIOLIB_INT_0);
|
_mod->init(RADIOLIB_USE_SPI);
|
||||||
|
Module::pinMode(_mod->getIrq(), INPUT);
|
||||||
|
|
||||||
|
// reset the module
|
||||||
|
reset();
|
||||||
|
|
||||||
// try to find the RF69 chip
|
// try to find the RF69 chip
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
|
@ -101,15 +105,34 @@ int16_t RF69::begin(float freq, float br, float rxBw, float freqDev, int8_t powe
|
||||||
return(ERR_NONE);
|
return(ERR_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RF69::reset() {
|
||||||
|
Module::pinMode(_mod->getRst(), OUTPUT);
|
||||||
|
Module::digitalWrite(_mod->getRst(), HIGH);
|
||||||
|
delayMicroseconds(100);
|
||||||
|
Module::digitalWrite(_mod->getRst(), LOW);
|
||||||
|
Module::pinMode(_mod->getRst(), INPUT);
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
int16_t RF69::transmit(uint8_t* data, size_t len, uint8_t addr) {
|
int16_t RF69::transmit(uint8_t* data, size_t len, uint8_t addr) {
|
||||||
|
// calculate timeout (5ms + 500 % of expected time-on-air)
|
||||||
|
uint32_t timeout = 5000000 + (uint32_t)((((float)(len * 8)) / (_br * 1000.0)) * 5000000.0);
|
||||||
|
|
||||||
// start transmission
|
// start transmission
|
||||||
int16_t state = startTransmit(data, len, addr);
|
int16_t state = startTransmit(data, len, addr);
|
||||||
if(state != ERR_NONE) {
|
if(state != ERR_NONE) {
|
||||||
return(state);
|
return(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for transmission end
|
// wait for transmission end or timeout
|
||||||
while(!digitalRead(_mod->getInt0()));
|
uint32_t start = micros();
|
||||||
|
while(!digitalRead(_mod->getIrq())) {
|
||||||
|
if(micros() - start > timeout) {
|
||||||
|
standby();
|
||||||
|
clearIRQFlags();
|
||||||
|
return(ERR_TX_TIMEOUT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// clear interrupt flags
|
// clear interrupt flags
|
||||||
clearIRQFlags();
|
clearIRQFlags();
|
||||||
|
@ -118,15 +141,20 @@ int16_t RF69::transmit(uint8_t* data, size_t len, uint8_t addr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t RF69::receive(uint8_t* data, size_t len) {
|
int16_t RF69::receive(uint8_t* data, size_t len) {
|
||||||
|
// calculate timeout (500 ms + 400 full 64-byte packets at current bit rate)
|
||||||
|
uint32_t timeout = 500000 + (1.0/(_br*1000.0))*(RF69_MAX_PACKET_LENGTH*400.0);
|
||||||
|
|
||||||
// start reception
|
// start reception
|
||||||
int16_t state = startReceive(true);
|
int16_t state = startReceive();
|
||||||
if(state != ERR_NONE) {
|
if(state != ERR_NONE) {
|
||||||
return(state);
|
return(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for packet reception or timeout
|
// wait for packet reception or timeout
|
||||||
while(!digitalRead(_mod->getInt0())) {
|
uint32_t start = micros();
|
||||||
if(digitalRead(_mod->getInt1())) {
|
while(!digitalRead(_mod->getIrq())) {
|
||||||
|
if(micros() - start > timeout) {
|
||||||
|
standby();
|
||||||
clearIRQFlags();
|
clearIRQFlags();
|
||||||
return(ERR_RX_TIMEOUT);
|
return(ERR_RX_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
@ -208,20 +236,14 @@ int16_t RF69::disableAES() {
|
||||||
return(_mod->SPIsetRegValue(RF69_REG_PACKET_CONFIG_2, RF69_AES_OFF, 0, 0));
|
return(_mod->SPIsetRegValue(RF69_REG_PACKET_CONFIG_2, RF69_AES_OFF, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t RF69::startReceive(bool timeout) {
|
int16_t RF69::startReceive() {
|
||||||
// set mode to standby
|
// set mode to standby
|
||||||
int16_t state = setMode(RF69_STANDBY);
|
int16_t state = setMode(RF69_STANDBY);
|
||||||
|
|
||||||
// set RX timeouts and DIO pin mapping
|
// set RX timeouts and DIO pin mapping
|
||||||
if(timeout) {
|
state = _mod->SPIsetRegValue(RF69_REG_DIO_MAPPING_1, RF69_DIO0_PACK_PAYLOAD_READY, 7, 4);
|
||||||
state = _mod->SPIsetRegValue(RF69_REG_DIO_MAPPING_1, RF69_DIO0_PACK_PAYLOAD_READY | RF69_DIO1_PACK_TIMEOUT, 7, 4);
|
|
||||||
state |= _mod->SPIsetRegValue(RF69_REG_RX_TIMEOUT_1, RF69_TIMEOUT_RX_START);
|
state |= _mod->SPIsetRegValue(RF69_REG_RX_TIMEOUT_1, RF69_TIMEOUT_RX_START);
|
||||||
state |= _mod->SPIsetRegValue(RF69_REG_RX_TIMEOUT_2, RF69_TIMEOUT_RSSI_THRESH);
|
state |= _mod->SPIsetRegValue(RF69_REG_RX_TIMEOUT_2, RF69_TIMEOUT_RSSI_THRESH);
|
||||||
} else {
|
|
||||||
state = _mod->SPIsetRegValue(RF69_REG_DIO_MAPPING_1, RF69_DIO0_PACK_PAYLOAD_READY, 7, 6);
|
|
||||||
state |= _mod->SPIsetRegValue(RF69_REG_RX_TIMEOUT_1, RF69_TIMEOUT_RX_START_OFF);
|
|
||||||
state |= _mod->SPIsetRegValue(RF69_REG_RX_TIMEOUT_2, RF69_TIMEOUT_RSSI_THRESH_OFF);
|
|
||||||
}
|
|
||||||
if(state != ERR_NONE) {
|
if(state != ERR_NONE) {
|
||||||
return(state);
|
return(state);
|
||||||
}
|
}
|
||||||
|
@ -238,11 +260,15 @@ int16_t RF69::startReceive(bool timeout) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void RF69::setDio0Action(void (*func)(void)) {
|
void RF69::setDio0Action(void (*func)(void)) {
|
||||||
attachInterrupt(digitalPinToInterrupt(_mod->getInt0()), func, RISING);
|
attachInterrupt(digitalPinToInterrupt(_mod->getIrq()), func, RISING);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RF69::setDio1Action(void (*func)(void)) {
|
void RF69::setDio1Action(void (*func)(void)) {
|
||||||
attachInterrupt(digitalPinToInterrupt(_mod->getInt1()), func, RISING);
|
if(_mod->getGpio() != RADIOLIB_PIN_UNUSED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Module::pinMode(_mod->getGpio(), INPUT);
|
||||||
|
attachInterrupt(digitalPinToInterrupt(_mod->getGpio()), func, RISING);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t RF69::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
|
int16_t RF69::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
|
||||||
|
|
|
@ -464,6 +464,11 @@ class RF69: public PhysicalLayer {
|
||||||
*/
|
*/
|
||||||
int16_t begin(float freq = 434.0, float br = 48.0, float rxBw = 125.0, float freqDev = 50.0, int8_t power = 13);
|
int16_t begin(float freq = 434.0, float br = 48.0, float rxBw = 125.0, float freqDev = 50.0, int8_t power = 13);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Reset method. Will reset the chip to the default state using RST pin.
|
||||||
|
*/
|
||||||
|
void reset();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Blocking binary transmit method.
|
\brief Blocking binary transmit method.
|
||||||
Overloads for string-based transmissions are implemented in PhysicalLayer.
|
Overloads for string-based transmissions are implemented in PhysicalLayer.
|
||||||
|
@ -581,11 +586,9 @@ class RF69: public PhysicalLayer {
|
||||||
/*!
|
/*!
|
||||||
\brief Interrupt-driven receive method. GDO0 will be activated when full packet is received.
|
\brief Interrupt-driven receive method. GDO0 will be activated when full packet is received.
|
||||||
|
|
||||||
\param timeout Enable module-driven timeout. Set to false for listen mode.
|
|
||||||
|
|
||||||
\returns \ref status_codes
|
\returns \ref status_codes
|
||||||
*/
|
*/
|
||||||
int16_t startReceive(bool timeout = false);
|
int16_t startReceive();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Reads data received after calling startReceive method.
|
\brief Reads data received after calling startReceive method.
|
||||||
|
|
Loading…
Add table
Reference in a new issue