Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stm32f1 support #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 0 additions & 84 deletions DHTxx.cpp

This file was deleted.

20 changes: 0 additions & 20 deletions DHTxx.h

This file was deleted.

57 changes: 40 additions & 17 deletions DavisRFM69.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Driver implementation for HopeRF RFM69W/RFM69HW, Semtech SX1231/1231H used for
// compatibility with the frequency hopped, spread spectrum signals from a Davis Instrument
// wireless Integrated Sensor Suite (ISS)
// wireless Integrated Sensor Suite (ISS). This library has been tested against both the
// Moteino from LowPowerLab, and an ESP-12E wired directly to an RFM69W module.
//
// This is part of the DavisRFM69 library from https://github.com/dekay/DavisRFM69
// (C) DeKay 2014 [email protected]
// (C) DeKay 2014-2015 [email protected]
//
// As I consider this to be a derived work for now from the RFM69W library from LowPowerLab,
// it is released under the same Creative Commons Attrib Share-Alike License
Expand All @@ -18,7 +19,7 @@ volatile uint8_t DavisRFM69::DATA[DAVIS_PACKET_LEN];
volatile uint8_t DavisRFM69::_mode; // current transceiver state
volatile bool DavisRFM69::_packetReceived = false;
volatile uint8_t DavisRFM69::CHANNEL = 0;
volatile int16_t DavisRFM69::RSSI; // RSSI measured immediately after payload reception
volatile int16_t DavisRFM69::RSSI; // RSSI measured after packet data read
DavisRFM69* DavisRFM69::selfPointer;

void DavisRFM69::initialize()
Expand All @@ -31,13 +32,13 @@ void DavisRFM69::initialize()
/* 0x04 */ { REG_BITRATELSB, RF_BITRATELSB_19200},
/* 0x05 */ { REG_FDEVMSB, RF_FDEVMSB_4800}, // Davis uses a deviation of 4.8 kHz on Rx
/* 0x06 */ { REG_FDEVLSB, RF_FDEVLSB_4800},
/* 0x07 to 0x09 are REG_FRFMSB to LSB. No sense setting them here. Done in main routine.
// 0x07 to 0x09 are REG_FRFMSB to LSB. No sense setting them here. Done in main routine.
/* 0x0B */ { REG_AFCCTRL, RF_AFCCTRL_LOWBETA_OFF }, // TODO: Should use LOWBETA_ON, but having trouble getting it working
// looks like PA1 and PA2 are not implemented on RFM69W, hence the max output power is 13dBm
// +17dBm and +20dBm are possible on RFM69HW
// +13dBm formula: Pout=-18+OutputPower (with PA0 or PA1**)
// +17dBm formula: Pout=-14+OutputPower (with PA1 and PA2)**
// +20dBpaym formula: Pout=-11+OutputPower (with PA1 and PA2)** and high power PA settings (section 3.3.7 in datasheet)
// +20dBm formula: Pout=-11+OutputPower (with PA1 and PA2)** and high power PA settings (section 3.3.7 in datasheet)
///* 0x11 */ { REG_PALEVEL, RF_PALEVEL_PA0_ON | RF_PALEVEL_PA1_OFF | RF_PALEVEL_PA2_OFF | RF_PALEVEL_OUTPUTPOWER_11111},
///* 0x13 */ { REG_OCP, RF_OCP_ON | RF_OCP_TRIM_95 }, //over current protection (default is 95mA)
/* 0x18 */ { REG_LNA, RF_LNA_ZIN_50 | RF_LNA_GAINSELECT_AUTO}, // Not sure which is correct!
Expand All @@ -57,7 +58,7 @@ void DavisRFM69::initialize()
/* 0x2a & 0x2b RegRxTimeout1 and 2, respectively */
/* 0x2c RegPreambleMsb - use zero default */
/* 0x2d */ { REG_PREAMBLELSB, 4 }, // Davis has four preamble bytes 0xAAAAAAAA
/* 0x2e */ { REG_SYNCCONFIG, RF_SYNC_ON | RF_SYNC_FIFOFILL_AUTO | RF_SYNC_SIZE_2 | RF_SYNC_TOL_2 }, // Allow a couple erros in the sync word
/* 0x2e */ { REG_SYNCCONFIG, RF_SYNC_ON | RF_SYNC_FIFOFILL_AUTO | RF_SYNC_SIZE_2 | RF_SYNC_TOL_2 }, // Allow a couple errors in the sync word
/* 0x2f */ { REG_SYNCVALUE1, 0xcb }, // Davis ISS first sync byte. http://madscientistlabs.blogspot.ca/2012/03/first-you-get-sugar.html
/* 0x30 */ { REG_SYNCVALUE2, 0x89 }, // Davis ISS second sync byte.
/* 0x31 - 0x36 REG_SYNCVALUE3 - 8 not used */
Expand All @@ -78,22 +79,30 @@ void DavisRFM69::initialize()
pinMode(_slaveSelectPin, OUTPUT);
SPI.begin();

// Is the RFM69 module alive?
do writeReg(REG_SYNCVALUE1, 0xaa); while (readReg(REG_SYNCVALUE1) != 0xaa);
do writeReg(REG_SYNCVALUE1, 0x55); while (readReg(REG_SYNCVALUE1) != 0x55);

for (uint8_t i = 0; CONFIG[i][0] != 255; i++)
writeReg(CONFIG[i][0], CONFIG[i][1]);

setHighPower(_isRFM69HW); //called regardless if it's a RFM69W or RFM69HW
setHighPower(_isRFM69HW); // Called regardless if it's a RFM69W or RFM69HW
setMode(RF69_MODE_STANDBY);
while ((readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // Wait for ModeReady
pinMode(RF69_IRQ_PIN, INPUT);
attachInterrupt(_interruptNum, DavisRFM69::isr0, RISING);

rcCalibration(); // Perform the coarse cal in case we haven't done POR in a long time

selfPointer = this;
}

void DavisRFM69::interruptHandler() {
RSSI = readRSSI(); // Read up front when it is most likely the carrier is still up
// See https://github.com/esp8266/Arduino/issues/1020 for how user libraries with
// interrupts can crash the ESP. Better to be safe than sorry for now.
#if defined(ESP8266)
ETS_GPIO_INTR_DISABLE();
#endif
if (_mode == RF69_MODE_RX && (readReg(REG_IRQFLAGS2) & RF_IRQFLAGS2_PAYLOADREADY))
{
setMode(RF69_MODE_STANDBY);
Expand All @@ -104,7 +113,11 @@ void DavisRFM69::interruptHandler() {

_packetReceived = true;
unselect(); // Unselect RFM69 module, enabling interrupts
RSSI = readRSSI(); // RSSI of last received packet remains available after reception
}
#if defined(ESP8266)
ETS_GPIO_INTR_ENABLE();
#endif
}

bool DavisRFM69::canSend()
Expand Down Expand Up @@ -155,12 +168,18 @@ void DavisRFM69::setChannel(uint8_t channel)
{
CHANNEL = channel;
if (CHANNEL > DAVIS_FREQ_TABLE_LENGTH - 1) CHANNEL = 0;
setMode(RF69_MODE_STANDBY);
writeReg(REG_FRFMSB, pgm_read_byte(&FRF[CHANNEL][0]));
writeReg(REG_FRFMID, pgm_read_byte(&FRF[CHANNEL][1]));
writeReg(REG_FRFLSB, pgm_read_byte(&FRF[CHANNEL][2]));
receiveBegin();
}

void DavisRFM69::waitHere()
{
_packetReceived = false;
}

void DavisRFM69::hop()
{
setChannel(++CHANNEL);
Expand Down Expand Up @@ -202,7 +221,6 @@ void DavisRFM69::setFrequency(uint32_t FRF)

void DavisRFM69::setMode(uint8_t newMode)
{
//Serial.println(newMode);
if (newMode == _mode) return;

switch (newMode) {
Expand All @@ -229,11 +247,9 @@ void DavisRFM69::setMode(uint8_t newMode)
// we are using packet mode, so this check is not really needed
// but waiting for mode ready is necessary when going from sleep because the FIFO may not
// be immediately available from previous mode
while (_mode == RF69_MODE_SLEEP && (readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // Wait for ModeReady

while (_mode == RF69_MODE_SLEEP && (readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); // Wait for ModeReady
_mode = newMode;
//Serial.print("Mode set to ");
//Serial.println(_mode);
}

void DavisRFM69::sleep() {
Expand Down Expand Up @@ -289,9 +305,13 @@ void DavisRFM69::writeReg(uint8_t addr, uint8_t value)
// Select the transceiver
void DavisRFM69::select() {
noInterrupts();
// Save current SPI settings
#if defined(ARDUINO_ARCH_AVR)
// Save current SPI settings on Moteino's. That board has a SPI flash
// as well as a SPI interface to the RFM69, so you need to save the old
// SPI config before talking to the RFM69. We aren't doing this on the ESP.
_SPCR = SPCR;
_SPSR = SPSR;
#endif
// Set RFM69 SPI settings
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
Expand All @@ -302,9 +322,12 @@ void DavisRFM69::select() {
// Unselect the transceiver chip
void DavisRFM69::unselect() {
digitalWrite(_slaveSelectPin, HIGH);
// Restore SPI settings to what they were before talking to RFM69
// Restore SPI settings on Moteino to what they were before talking to RFM69.
// See comment in DavisRFM69::select() for why.
#if defined(ARDUINO_ARCH_AVR)
SPCR = _SPCR;
SPSR = _SPSR;
#endif
interrupts();
}

Expand Down Expand Up @@ -341,9 +364,9 @@ void DavisRFM69::readAllRegs()
unselect();

Serial.print(regAddr, HEX);
Serial.print(" - ");
Serial.print(F(" - "));
Serial.print(regVal,HEX);
Serial.print(" - ");
Serial.print(F(" - "));
Serial.println(regVal,BIN);
}
unselect();
Expand All @@ -353,7 +376,7 @@ uint8_t DavisRFM69::readTemperature(uint8_t calFactor) // Returns centigrade
{
setMode(RF69_MODE_STANDBY);
writeReg(REG_TEMP1, RF_TEMP1_MEAS_START);
while ((readReg(REG_TEMP1) & RF_TEMP1_MEAS_RUNNING)) Serial.print('*');
while ((readReg(REG_TEMP1) & RF_TEMP1_MEAS_RUNNING)) Serial.print(F("*"));
return ~readReg(REG_TEMP2) + COURSE_TEMP_COEF + calFactor; //'complement'corrects the slope, rising temp = rising val
} // COURSE_TEMP_COEF puts reading in the ballpark, user can add additional correction

Expand Down
23 changes: 17 additions & 6 deletions DavisRFM69.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Driver definition for HopeRF RFM69W/RFM69HW, Semtech SX1231/1231H used for
// compatibility with the frequency hopped, spread spectrum signals from a Davis Instrument
// wireless Integrated Sensor Suite (ISS)
// wireless Integrated Sensor Suite (ISS). This library has been tested against both the
// Moteino from LowPowerLab, and an ESP-12E wired directly to an RFM69W module.
//
// This is part of the DavisRFM69 library from https://github.com/dekay/DavisRFM69
// (C) DeKay 2014 [email protected]
// (C) DeKay 2014-2016 [email protected]
//
// As I consider this to be a derived work from the RFM69W library from LowPowerLab,
// it is released under the same Creative Commons Attrib Share-Alike License
Expand All @@ -18,17 +19,18 @@
// America) and EU frequencies are defined at this time. Australia and New
// Zealand are placeholders. Note however that the frequencies for AU and NZ
// are not known at this time.
#define DAVIS_FREQS_US
//#define DAVIS_FREQS_US
//#define DAVIS_FREQS_EU
//#define DAVIS_FREQS_AU
//#define DAVIS_FREQS_NZ

#include <Davisdef.h>
#include <Arduino.h> //assumes Arduino IDE v1.0 or greater

#define DAVIS_PACKET_LEN 10 // ISS has fixed packet length of 10 bytes, including CRC and retransmit CRC
#define RF69_SPI_CS SS // SS is the SPI slave select pin, for instance D10 on ATmega328

#define DAVIS_PACKET_LEN 10 // ISS has fixed packet length of 10 bytes,
// including CRC and retransmit CRC
#define RF69_SPI_CS SS // SS is the SPI slave select pin
// For instance D10 on ATmega328
// INT0 on AVRs should be connected to RFM69's DIO0 (ex on ATmega328 it's D2, on ATmega644/1284 it's D2)
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
#define RF69_IRQ_PIN 2
Expand All @@ -39,6 +41,14 @@
#elif defined(__AVR_ATmega32U4__)
#define RF69_IRQ_PIN 3
#define RF69_IRQ_NUM 0
#elif defined(ESP8266)
// ESP interrupt number and pin number are a direct relation
// See http://www.esp8266.com/viewtopic.php?f=32&t=4694
#define RF69_IRQ_PIN 5
#define RF69_IRQ_NUM 5
#elif defined(ARDUINO_ARCH_STM32F1)
#define RF69_IRQ_PIN PA0
#define RF69_IRQ_NUM 0
#endif

#define CSMA_LIMIT -90 // upper RX signal sensitivity threshold in dBm for carrier sense access
Expand Down Expand Up @@ -109,6 +119,7 @@ class DavisRFM69 {
static volatile uint8_t hopIndex;
void setChannel(uint8_t channel);
void hop();
void waitHere();
uint16_t crc16_ccitt(volatile uint8_t *buf, uint8_t len, uint16_t initCrc = 0);

void initialize();
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ This library is in its early stages but I wanted to get something functional out
This library has been developed on a Moteino R3 [(see here for the new R4 version)](http://lowpowerlab.com/shop/Moteino-R4)
fitted with an RFM69W (Semtech SX1231/SX1231) transceiver module.

Support has also been added for ESP8266 modules. The ISSRx_ESP example was developed on a NodeMCU ESP-12E based module connected directly to an RFM69W transceiver. See the code for a description of the hookup.

##Installation
[See this blog post](http://madscientistlabs.blogspot.ca/2014/02/build-your-own-davis-weather-station_17.html) where I combines ISS Reception capabilities along with hookups to sensors for indoor monitoring of temperature, pressure, and humidity. Note that this code no longer requires the installation of [LowPowerLab's RFM69 library](https://github.com/LowPowerLab/RFM69) discussed in that post, but you will still need to install his [SPIFlash library](https://github.com/LowPowerLab/SPIFlash). Since that post was written, I have also added support for the DS3231 Real Time Clock chip. To get this to work from a software perspective, you will need [this RTC library](https://github.com/mizraith/RTClib) in your Arduino "libraries" folder.

Expand All @@ -37,9 +39,9 @@ fitted with an RFM69W (Semtech SX1231/SX1231) transceiver module.
Reception quality has been greatly improved in this release. ~~There looks to be a bug where the hop-ahead code has broken, but I expect that will be fixed soon~~ I am getting around 99% good packets now. Please let me know if you find any issues.

##Sample Usage
[VP2](https://github.com/dekay/DavisRFM69/blob/master/Examples/VP2/VP2.ino) is an emulation of the Davis Vantage Pro2 console that works with Sandaysoft's Cumulus weather software. As noted above, you will need [this RTC library](https://github.com/mizraith/RTClib) in your Arduino "libraries" folder.
[ISSRx](https://github.com/dekay/DavisRFM69/blob/master/examples/ISSRx/ISSRx.ino) is an example of sniffing the wireless packets out of the air and streaming them out the serial port. A version for the ESP8266 is in progress.

The ISSRx Example hasn't been updated in a while and may be broken. Just so you know...
[VP2](https://github.com/dekay/DavisRFM69/blob/master/Examples/VP2/VP2.ino) is an emulation of the Davis Vantage Pro2 console that works with Sandaysoft's Cumulus weather software. As noted above, you will need [this RTC library](https://github.com/mizraith/RTClib) in your Arduino "libraries" folder. Unfortunately, this example will be broken right now as I've concentrated on the ESP8266 for now.

##Blog Writeups
[ISS Reception](http://madscientistlabs.blogspot.ca/2014/01/more-than-one-way-to-skin-cat.html), along with the best GIF ever.
Expand All @@ -51,4 +53,4 @@ I started playing around with my VP2 Wireless console when I discovered its litt

I learned a lot by doing this and I like to think that opening up the console has been an overall win for Davis. I also consider this to be MY data, and I want access to it ([Davis' failed attempts to shut this down notwithstanding](http://meteo.annoyingdesigns.com/DavisSPI.pdf)).

And, just because.
And, just because.
Loading