Merge pull request #98 from LowPowerLab/revert-93-master
Revert "Allow choosing the SPI interface"
This commit is contained in:
commit
8b7a74a03c
50
RFM69.cpp
50
RFM69.cpp
|
|
@ -85,7 +85,7 @@ bool RFM69::initialize(uint8_t freqBand, uint8_t nodeID, uint8_t networkID)
|
||||||
|
|
||||||
digitalWrite(_slaveSelectPin, HIGH);
|
digitalWrite(_slaveSelectPin, HIGH);
|
||||||
pinMode(_slaveSelectPin, OUTPUT);
|
pinMode(_slaveSelectPin, OUTPUT);
|
||||||
_spi.begin();
|
SPI.begin();
|
||||||
unsigned long start = millis();
|
unsigned long start = millis();
|
||||||
uint8_t timeout = 50;
|
uint8_t timeout = 50;
|
||||||
do writeReg(REG_SYNCVALUE1, 0xAA); while (readReg(REG_SYNCVALUE1) != 0xaa && millis()-start < timeout);
|
do writeReg(REG_SYNCVALUE1, 0xAA); while (readReg(REG_SYNCVALUE1) != 0xaa && millis()-start < timeout);
|
||||||
|
|
@ -287,14 +287,14 @@ void RFM69::sendFrame(uint8_t toAddress, const void* buffer, uint8_t bufferSize,
|
||||||
|
|
||||||
// write to FIFO
|
// write to FIFO
|
||||||
select();
|
select();
|
||||||
_spi.transfer(REG_FIFO | 0x80);
|
SPI.transfer(REG_FIFO | 0x80);
|
||||||
_spi.transfer(bufferSize + 3);
|
SPI.transfer(bufferSize + 3);
|
||||||
_spi.transfer(toAddress);
|
SPI.transfer(toAddress);
|
||||||
_spi.transfer(_address);
|
SPI.transfer(_address);
|
||||||
_spi.transfer(CTLbyte);
|
SPI.transfer(CTLbyte);
|
||||||
|
|
||||||
for (uint8_t i = 0; i < bufferSize; i++)
|
for (uint8_t i = 0; i < bufferSize; i++)
|
||||||
_spi.transfer(((uint8_t*) buffer)[i]);
|
SPI.transfer(((uint8_t*) buffer)[i]);
|
||||||
unselect();
|
unselect();
|
||||||
|
|
||||||
// no need to wait for transmit mode to be ready since its handled by the radio
|
// no need to wait for transmit mode to be ready since its handled by the radio
|
||||||
|
|
@ -314,10 +314,10 @@ void RFM69::interruptHandler() {
|
||||||
//RSSI = readRSSI();
|
//RSSI = readRSSI();
|
||||||
setMode(RF69_MODE_STANDBY);
|
setMode(RF69_MODE_STANDBY);
|
||||||
select();
|
select();
|
||||||
_spi.transfer(REG_FIFO & 0x7F);
|
SPI.transfer(REG_FIFO & 0x7F);
|
||||||
PAYLOADLEN = _spi.transfer(0);
|
PAYLOADLEN = SPI.transfer(0);
|
||||||
PAYLOADLEN = PAYLOADLEN > 66 ? 66 : PAYLOADLEN; // precaution
|
PAYLOADLEN = PAYLOADLEN > 66 ? 66 : PAYLOADLEN; // precaution
|
||||||
TARGETID = _spi.transfer(0);
|
TARGETID = SPI.transfer(0);
|
||||||
if(!(_promiscuousMode || TARGETID == _address || TARGETID == RF69_BROADCAST_ADDR) // match this node's address, or broadcast address or anything in promiscuous mode
|
if(!(_promiscuousMode || TARGETID == _address || TARGETID == RF69_BROADCAST_ADDR) // match this node's address, or broadcast address or anything in promiscuous mode
|
||||||
|| PAYLOADLEN < 3) // address situation could receive packets that are malformed and don't fit this libraries extra fields
|
|| PAYLOADLEN < 3) // address situation could receive packets that are malformed and don't fit this libraries extra fields
|
||||||
{
|
{
|
||||||
|
|
@ -329,8 +329,8 @@ void RFM69::interruptHandler() {
|
||||||
}
|
}
|
||||||
|
|
||||||
DATALEN = PAYLOADLEN - 3;
|
DATALEN = PAYLOADLEN - 3;
|
||||||
SENDERID = _spi.transfer(0);
|
SENDERID = SPI.transfer(0);
|
||||||
uint8_t CTLbyte = _spi.transfer(0);
|
uint8_t CTLbyte = SPI.transfer(0);
|
||||||
|
|
||||||
ACK_RECEIVED = CTLbyte & RFM69_CTL_SENDACK; // extract ACK-received flag
|
ACK_RECEIVED = CTLbyte & RFM69_CTL_SENDACK; // extract ACK-received flag
|
||||||
ACK_REQUESTED = CTLbyte & RFM69_CTL_REQACK; // extract ACK-requested flag
|
ACK_REQUESTED = CTLbyte & RFM69_CTL_REQACK; // extract ACK-requested flag
|
||||||
|
|
@ -339,7 +339,7 @@ void RFM69::interruptHandler() {
|
||||||
|
|
||||||
for (uint8_t i = 0; i < DATALEN; i++)
|
for (uint8_t i = 0; i < DATALEN; i++)
|
||||||
{
|
{
|
||||||
DATA[i] = _spi.transfer(0);
|
DATA[i] = SPI.transfer(0);
|
||||||
}
|
}
|
||||||
if (DATALEN < RF69_MAX_DATA_LEN) DATA[DATALEN] = 0; // add null at end of string
|
if (DATALEN < RF69_MAX_DATA_LEN) DATA[DATALEN] = 0; // add null at end of string
|
||||||
unselect();
|
unselect();
|
||||||
|
|
@ -395,9 +395,9 @@ void RFM69::encrypt(const char* key) {
|
||||||
if (key != 0)
|
if (key != 0)
|
||||||
{
|
{
|
||||||
select();
|
select();
|
||||||
_spi.transfer(REG_AESKEY1 | 0x80);
|
SPI.transfer(REG_AESKEY1 | 0x80);
|
||||||
for (uint8_t i = 0; i < 16; i++)
|
for (uint8_t i = 0; i < 16; i++)
|
||||||
_spi.transfer(key[i]);
|
SPI.transfer(key[i]);
|
||||||
unselect();
|
unselect();
|
||||||
}
|
}
|
||||||
writeReg(REG_PACKETCONFIG2, (readReg(REG_PACKETCONFIG2) & 0xFE) | (key ? 1 : 0));
|
writeReg(REG_PACKETCONFIG2, (readReg(REG_PACKETCONFIG2) & 0xFE) | (key ? 1 : 0));
|
||||||
|
|
@ -420,8 +420,8 @@ int16_t RFM69::readRSSI(bool forceTrigger) {
|
||||||
uint8_t RFM69::readReg(uint8_t addr)
|
uint8_t RFM69::readReg(uint8_t addr)
|
||||||
{
|
{
|
||||||
select();
|
select();
|
||||||
_spi.transfer(addr & 0x7F);
|
SPI.transfer(addr & 0x7F);
|
||||||
uint8_t regval = _spi.transfer(0);
|
uint8_t regval = SPI.transfer(0);
|
||||||
unselect();
|
unselect();
|
||||||
return regval;
|
return regval;
|
||||||
}
|
}
|
||||||
|
|
@ -429,8 +429,8 @@ uint8_t RFM69::readReg(uint8_t addr)
|
||||||
void RFM69::writeReg(uint8_t addr, uint8_t value)
|
void RFM69::writeReg(uint8_t addr, uint8_t value)
|
||||||
{
|
{
|
||||||
select();
|
select();
|
||||||
_spi.transfer(addr | 0x80);
|
SPI.transfer(addr | 0x80);
|
||||||
_spi.transfer(value);
|
SPI.transfer(value);
|
||||||
unselect();
|
unselect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -443,12 +443,12 @@ void RFM69::select() {
|
||||||
_SPSR = SPSR;
|
_SPSR = SPSR;
|
||||||
#endif
|
#endif
|
||||||
// set RFM69 SPI settings
|
// set RFM69 SPI settings
|
||||||
_spi.setDataMode(SPI_MODE0);
|
SPI.setDataMode(SPI_MODE0);
|
||||||
_spi.setBitOrder(MSBFIRST);
|
SPI.setBitOrder(MSBFIRST);
|
||||||
#ifdef __arm__
|
#ifdef __arm__
|
||||||
_spi.setClockDivider(SPI_CLOCK_DIV16);
|
SPI.setClockDivider(SPI_CLOCK_DIV16);
|
||||||
#else
|
#else
|
||||||
_spi.setClockDivider(SPI_CLOCK_DIV4); // decided to slow down from DIV2 after SPI stalling in some instances, especially visible on mega1284p when RFM69 and FLASH chip both present
|
SPI.setClockDivider(SPI_CLOCK_DIV4); // decided to slow down from DIV2 after SPI stalling in some instances, especially visible on mega1284p when RFM69 and FLASH chip both present
|
||||||
#endif
|
#endif
|
||||||
digitalWrite(_slaveSelectPin, LOW);
|
digitalWrite(_slaveSelectPin, LOW);
|
||||||
}
|
}
|
||||||
|
|
@ -527,8 +527,8 @@ void RFM69::readAllRegs()
|
||||||
for (uint8_t regAddr = 1; regAddr <= 0x4F; regAddr++)
|
for (uint8_t regAddr = 1; regAddr <= 0x4F; regAddr++)
|
||||||
{
|
{
|
||||||
select();
|
select();
|
||||||
_spi.transfer(regAddr & 0x7F); // send address + r/w bit
|
SPI.transfer(regAddr & 0x7F); // send address + r/w bit
|
||||||
regVal = _spi.transfer(0);
|
regVal = SPI.transfer(0);
|
||||||
unselect();
|
unselect();
|
||||||
|
|
||||||
Serial.print(regAddr, HEX);
|
Serial.print(regAddr, HEX);
|
||||||
|
|
|
||||||
5
RFM69.h
5
RFM69.h
|
|
@ -26,7 +26,6 @@
|
||||||
#ifndef RFM69_h
|
#ifndef RFM69_h
|
||||||
#define RFM69_h
|
#define RFM69_h
|
||||||
#include <Arduino.h> // assumes Arduino IDE v1.0 or greater
|
#include <Arduino.h> // assumes Arduino IDE v1.0 or greater
|
||||||
#include <SPI.h>
|
|
||||||
|
|
||||||
#define RF69_MAX_DATA_LEN 61 // to take advantage of the built in AES/CRC we want to limit the frame size to the internal FIFO size (66 bytes - 3 bytes overhead - 2 bytes crc)
|
#define RF69_MAX_DATA_LEN 61 // to take advantage of the built in AES/CRC we want to limit the frame size to the internal FIFO size (66 bytes - 3 bytes overhead - 2 bytes crc)
|
||||||
#define RF69_SPI_CS SS // SS is the SPI slave select pin, for instance D10 on ATmega328
|
#define RF69_SPI_CS SS // SS is the SPI slave select pin, for instance D10 on ATmega328
|
||||||
|
|
@ -86,7 +85,7 @@ class RFM69 {
|
||||||
static volatile int16_t RSSI; // most accurate RSSI during reception (closest to the reception)
|
static volatile int16_t RSSI; // most accurate RSSI during reception (closest to the reception)
|
||||||
static volatile uint8_t _mode; // should be protected?
|
static volatile uint8_t _mode; // should be protected?
|
||||||
|
|
||||||
RFM69(uint8_t slaveSelectPin=RF69_SPI_CS, uint8_t interruptPin=RF69_IRQ_PIN, bool isRFM69HW=false, uint8_t interruptNum=RF69_IRQ_NUM, SPIClass &spi = SPI) {
|
RFM69(uint8_t slaveSelectPin=RF69_SPI_CS, uint8_t interruptPin=RF69_IRQ_PIN, bool isRFM69HW=false, uint8_t interruptNum=RF69_IRQ_NUM) {
|
||||||
_slaveSelectPin = slaveSelectPin;
|
_slaveSelectPin = slaveSelectPin;
|
||||||
_interruptPin = interruptPin;
|
_interruptPin = interruptPin;
|
||||||
_interruptNum = interruptNum;
|
_interruptNum = interruptNum;
|
||||||
|
|
@ -94,7 +93,6 @@ class RFM69 {
|
||||||
_promiscuousMode = false;
|
_promiscuousMode = false;
|
||||||
_powerLevel = 31;
|
_powerLevel = 31;
|
||||||
_isRFM69HW = isRFM69HW;
|
_isRFM69HW = isRFM69HW;
|
||||||
_spi = spi;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool initialize(uint8_t freqBand, uint8_t ID, uint8_t networkID=1);
|
bool initialize(uint8_t freqBand, uint8_t ID, uint8_t networkID=1);
|
||||||
|
|
@ -140,7 +138,6 @@ class RFM69 {
|
||||||
bool _promiscuousMode;
|
bool _promiscuousMode;
|
||||||
uint8_t _powerLevel;
|
uint8_t _powerLevel;
|
||||||
bool _isRFM69HW;
|
bool _isRFM69HW;
|
||||||
SPIClass _spi = SPI;
|
|
||||||
#if defined (SPCR) && defined (SPSR)
|
#if defined (SPCR) && defined (SPSR)
|
||||||
uint8_t _SPCR;
|
uint8_t _SPCR;
|
||||||
uint8_t _SPSR;
|
uint8_t _SPSR;
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
// Please maintain this license information along with authorship
|
// Please maintain this license information along with authorship
|
||||||
// and copyright notices in any redistribution of this code
|
// and copyright notices in any redistribution of this code
|
||||||
// **********************************************************************************
|
// **********************************************************************************
|
||||||
#ifdef __AVR__
|
#ifndef __arm__
|
||||||
#include <RFM69_OTA.h>
|
#include <RFM69_OTA.h>
|
||||||
#include <RFM69registers.h>
|
#include <RFM69registers.h>
|
||||||
#include <avr/wdt.h>
|
#include <avr/wdt.h>
|
||||||
|
|
@ -518,4 +518,4 @@ void resetUsingWatchdog(uint8_t DEBUG)
|
||||||
wdt_enable(WDTO_15MS);
|
wdt_enable(WDTO_15MS);
|
||||||
while(1) if (DEBUG) Serial.print(F("."));
|
while(1) if (DEBUG) Serial.print(F("."));
|
||||||
}
|
}
|
||||||
#endif // __AVR__
|
#endif
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
// Please maintain this license information along with authorship
|
// Please maintain this license information along with authorship
|
||||||
// and copyright notices in any redistribution of this code
|
// and copyright notices in any redistribution of this code
|
||||||
// **********************************************************************************
|
// **********************************************************************************
|
||||||
#ifdef __AVR__
|
#ifndef __arm__
|
||||||
|
|
||||||
#ifndef RFM69_OTA_H
|
#ifndef RFM69_OTA_H
|
||||||
#define RFM69_OTA_H
|
#define RFM69_OTA_H
|
||||||
|
|
@ -78,5 +78,5 @@ uint8_t BYTEfromHEX(char MSB, char LSB);
|
||||||
uint8_t readSerialLine(char* input, char endOfLineChar=10, uint8_t maxLength=115, uint16_t timeout=1000);
|
uint8_t readSerialLine(char* input, char endOfLineChar=10, uint8_t maxLength=115, uint16_t timeout=1000);
|
||||||
void PrintHex83(uint8_t* data, uint8_t length);
|
void PrintHex83(uint8_t* data, uint8_t length);
|
||||||
|
|
||||||
#endif // RFM69_OTA_H
|
#endif
|
||||||
#endif // __AVR__
|
#endif
|
||||||
Loading…
Reference in New Issue