This commit is contained in:
2019-08-22 07:58:15 +02:00
parent 365795300d
commit ddd569e2b3
219 changed files with 0 additions and 72609 deletions

View File

@@ -1,138 +0,0 @@
//----------------------------------------------------------------------------
// Description: This file contains definitions specific to the CC1101.
// The configuration registers, strobe commands, and status registers are
// defined, as well as some common masks for these registers.
//
// Texas Instruments, Inc.
// July 2006
//----------------------------------------------------------------------------
#ifndef CC1101_h
#define CC1101_h
//
#include <inttypes.h>
//
// CC1101 Configuration Registers.
//
#define CC1101_IOCFG2 0x00 // GDO2 Output Pin Configuration
#define CC1101_IOCFG1 0x01 // GDO1 Output Pin Configuration
#define CC1101_IOCFG0 0x02 // GDO0 Output Pin Configuration
#define CC1101_FIFOTHR 0x03 // RX FIFO and TX FIFO Thresholds
#define CC1101_SYNC1 0x04 // Sync Word, High Byte
#define CC1101_SYNC0 0x05 // Sync Word, Low Byte
#define CC1101_PKTLEN 0x06 // Packet Length
#define CC1101_PKTCTRL1 0x07 // Packet Automation Control
#define CC1101_PKTCTRL0 0x08 // Packet Automation Control
#define CC1101_ADDR 0x09 // Device Address
#define CC1101_CHANNR 0x0A // Channel Number
#define CC1101_FSCTRL1 0x0B // Frequency Synthesizer Control
#define CC1101_FSCTRL0 0x0C // Frequency Synthesizer Control
#define CC1101_FREQ2 0x0D // Frequency Control Word, High Byte
#define CC1101_FREQ1 0x0E // Frequency Control Word, Middle Byte
#define CC1101_FREQ0 0x0F // Frequency Control Word, Low Byte
#define CC1101_MDMCFG4 0x10 // Modem Configuration
#define CC1101_MDMCFG3 0x11 // Modem Configuration
#define CC1101_MDMCFG2 0x12 // Modem Configuration
#define CC1101_MDMCFG1 0x13 // Modem Configuration
#define CC1101_MDMCFG0 0x14 // Modem Configuration
#define CC1101_DEVIATN 0x15 // Modem Deviation Setting
#define CC1101_MCSM2 0x16 // Main Radio Control State Machine Configuration
#define CC1101_MCSM1 0x17 // Main Radio Control State Machine Configuration
#define CC1101_MCSM0 0x18 // Main Radio Control State Machine Configuration
#define CC1101_FOCCFG 0x19 // Frequency Offset Compensation Configuration
#define CC1101_BSCFG 0x1A // Bit Synchronization Configuration
#define CC1101_AGCCTRL2 0x1B // AGC Control
#define CC1101_AGCCTRL1 0x1C // AGC Control
#define CC1101_AGCCTRL0 0x1D // AGC Control
#define CC1101_WOREVT1 0x1E // High Byte Event0 Timeout
#define CC1101_WOREVT0 0x1F // Low Byte Event0 Timeout
#define CC1101_WORCTRL 0x20 // Wake On Radio Control
#define CC1101_FREND1 0x21 // Front End RX Configuration
#define CC1101_FREND0 0x22 // Front End TX Configuration
#define CC1101_FSCAL3 0x23 // Frequency Synthesizer Calibration
#define CC1101_FSCAL2 0x24 // Frequency Synthesizer Calibration
#define CC1101_FSCAL1 0x25 // Frequency Synthesizer Calibration
#define CC1101_FSCAL0 0x26 // Frequency Synthesizer Calibration
#define CC1101_RCCTRL1 0x27 // RC Oscillator Configuration
#define CC1101_RCCTRL0 0x28 // RC Oscillator Configuration
#define CC1101_FSTEST 0x29 // Frequency Synthesizer Calibration Control
#define CC1101_PTEST 0x2A // Production Test
#define CC1101_AGCTEST 0x2B // AGC Test
#define CC1101_TEST2 0x2C // Various Test Settings
#define CC1101_TEST1 0x2D // Various Test Settings
#define CC1101_TEST0 0x2E // Various Test Settings
//
// CC1101 Status Registers.
//
#define CC1101_PARTNUM 0x30 // Chip ID
#define CC1101_VERSION 0x31 // Chip ID
#define CC1101_FREQEST 0x32 // Frequency Offset Estimate from Demodulator
#define CC1101_LQI 0x33 // Demodulator Estimate for Link Quality
#define CC1101_RSSI 0x34 // Received Signal Strength Indication
#define CC1101_MARCSTATE 0x35 // Main Radio Control State Machine State
#define CC1101_WORTIME1 0x36 // High Byte of WOR Time
#define CC1101_WORTIME0 0x37 // Low Byte of WOR Time
#define CC1101_PKTSTATUS 0x38 // Current GDOx Status and Packet Status
#define CC1101_VCO_VC_DAC 0x39 // Current Setting from PLL Calibration Module
#define CC1101_TXBYTES 0x3A // Underflow and Number of Bytes
#define CC1101_RXBYTES 0x3B // Overflow and Number of Bytes
#define CC1101_RCCTRL1_STATUS 0x3C // Last RC Oscillator Calibration Result
#define CC1101_RCCTRL0_STATUS 0x3D // Last RC Oscillator Calibration Result
//
// CC1101 PA Table, TX FIFO and RX FIFO.
//
#define CC1101_PATABLE 0x3E // PA TABLE address
#define CC1101_TXFIFO 0x3F // TX FIFO address
#define CC1101_RXFIFO 0x3F // RX FIFO address
//
// CC1101 Command Strobes.
//
#define CC1101_SRES 0x30 // Reset CC1101 chip
#define CC1101_SFSTXON 0x31 // Enable and calibrate frequency synthesizer (if MCSM0.FS_AUTOCAL = 1). If in RX (with CCA):
// Go to a wait state where only the synthesizer is running (for quick RX / TX turnaround).
#define CC1101_SXOFF 0x32 // Turn off crystal oscillator
#define CC1101_SCAL 0x33 // Calibrate frequency synthesizer and turn it off. SCAL can be strobed from IDLE mode without
// setting manual calibration mode (MCSM0.FS_AUTOCAL = 0)
#define CC1101_SRX 0x34 // Enable RX. Perform calibration first if coming from IDLE and MCSM0.FS_AUTOCAL = 1
#define CC1101_STX 0x35 // In IDLE state: Enable TX. Perform calibration first if MCSM0.FS_AUTOCAL = 1.
// If in RX state and CCA is enabled: Only go to TX if channel is clear
#define CC1101_SIDLE 0x36 // Exit RX / TX, turn off frequency synthesizer and exit Wake-On-Radio mode if applicable
#define CC1101_SWOR 0x38 // Start automatic RX polling sequence (Wake-on-Radio) if WORCTRL.RC_PD = 0
#define CC1101_SPWD 0x39 // Enter power down mode when CSn goes high
#define CC1101_SFRX 0x3A // Flush the RX FIFO buffer. Only issue SFRX in IDLE or RXFIFO_OVERFLOW states
#define CC1101_SFTX 0x3B // Flush the TX FIFO buffer. Only issue SFTX in IDLE or TXFIFO_UNDERFLOW states
#define CC1101_SWORRST 0x3C // Reset real time clock to Event1 value
#define CC1101_SNOP 0x3D // No operation. May be used to get access to the chip status byte
//
// CC1101 Transfer Types.
//
#define WRITE_BURST 0x40
#define READ_SINGLE 0x80
#define READ_BURST 0xC0
//
// CC1101 Returned Status Bytes.
//
#define CC1101_STATE_IDLE 0x01
#define CC1101_STATE_ENDCAL 0x0C
#define CC1101_STATE_RX 0x0D
#define CC1101_STATE_RXFIFO_ERROR 0x11
#define CC1101_STATE_TX 0x13
#define CC1101_STATE_TX_END 0x14
#define CC1101_STATE_TXFIFO_ERROR 0x16
//
// CC1101 Helper Macros.
//
#define setRxState() cmdStrobe(CC1101_SRX) // Enter Rx state
#define setTxState() cmdStrobe(CC1101_STX) // Enter Tx state
#define setIdleState() cmdStrobe(CC1101_SIDLE) // Enter Idle state
#define flushRxFifo() cmdStrobe(CC1101_SFRX) // Flush Rx FIFO
#define flushTxFifo() cmdStrobe(CC1101_SFTX) // Flush Tx FIFO
//
// CC1101 PA Table.
//
const uint8_t PA_TABLE[8] = {0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0};
//
//
//
#endif

View File

@@ -1,486 +0,0 @@
/*
Davis.cpp
Arduino library that implements the Davis Instruments wireless
weather station protocol for the RFBee.
Version 0.8
Copyright (c) 2012 by Ray H. Dees
NOTE: This code is currently below version 1.0, and therefore is
lacking some functionality or documentation, or may not be fully
tested.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "CC1101.h"
#include "Davis.h"
#include "SPI.h"
//
// Initialize the Global Variables.
//
volatile uint8_t hopIndex = 0;
volatile int pktRssi;
volatile uint8_t pktLqi;
volatile int freqError;
volatile uint16_t pktCount = 0;
volatile uint16_t pktMiss = 0;
volatile uint8_t timer = 0;
volatile uint8_t now = 0;
volatile uint8_t next = 64;
volatile uint8_t rxing = 0;
volatile uint8_t hopping = 0;
//
// Intialize Class Variables.
//
uint8_t DAVIS::rxBuffer[BUFFER_SIZE];
volatile uint8_t DAVIS::rxBufferIndex = 0;
volatile uint8_t DAVIS::rxBufferLength = 0;
volatile uint8_t DAVIS::freqComp[51];
//
// Implements the standard Arduino begin() function.
//
void DAVIS::begin(void)
{
NO_INTERRUPTS(); // Disable Interrupts while changes are made.
ADCSRA = 0x00; // Disable the analog comparator.
EICRA = 0x00;
EICRA |= (1 << ISC01 | 1 << ISC00); // Setup Interrupt 0 for Rising edge.
EIFR |= (1 << INTF0); // Clear pending interrupts.
EIMSK |= (1 << INT0); // Enable Interrupt 0.
//TCCR1B = 0x00; // Disable Timer 1.
//ASSR = 0x00; // Set Timer 2 to System Clock.
//TCCR2A = 0x00; // Reset TCCR2A.
//TCCR2A = (1 << WGM21); // Set CTC mode.
//TCCR2B = 0x00; // Reset TCCR2B.
//TCCR2B = (1 << CS22 | 1 << CS21 | 1 << CS20); // Prescale by 1024.
//TIFR2 = (1 << OCF2B | 1 << OCF2A | 1 << TOV2); // Clear pending interrupts.
//OCR2A = 0x4D; // Set Compare Match for .01 seconds.
//TIMSK2 = 0x00; // Reset TIMSK2. TIMSK2 &= ~(1 << OCIE2A) Defined as TIMER2_STOP.
//TIMSK2 = (1 << OCIE2A); // Timer 2 Compare Match A Interrupt Enable. Defined as TIMER2_RUN.
pinMode(SS, OUTPUT); // Set Slave Select as an OUTPUT.
digitalWrite(SS, HIGH); // Set it HIGH.
pinMode(GDO0, INPUT); // Set INT0 as an INPUT.
pinMode(GDO2, INPUT); // Set INT1 as an INPUT (Future Use).
//
// These pins correspond to LED's located on the Uart Bee.
//
pinMode(9, OUTPUT); // RSSI Pin - Indicates Hopping.
digitalWrite(9, LOW); // Set it LOW.
pinMode(14, OUTPUT); // ASSOC Pin - Indicates Sync.
digitalWrite(14, LOW); // Set it LOW.
pinMode(15, OUTPUT); // ON Pin (Not currently used.)
digitalWrite(15, LOW); // Set it LOW.
SPI.begin(); // Start the SPI.
SPCR |= (1 << SPR0);
reset(); // Reset the CC1101.
setRegisters(); // Configure the CC1101.
for (uint8_t i = 0; i < 6; i++) // Preset the frequency compensation.
freqComp[i] = DAVIS_FSCTRL0;
INTERRUPTS(); // Enable Interrupts.
}
//
// Reset the CC1101.
//
void DAVIS::reset(void)
{
digitalWrite(SS, HIGH); // Deselect the CC1101.
delayMicroseconds(10);
digitalWrite(SS, LOW); // Select the CC1101.
delayMicroseconds(10);
digitalWrite(SS, HIGH); // Deselect the CC1101.
delayMicroseconds(50);
digitalWrite(SS, LOW); // Select the CC1101.
SPI.transfer(CC1101_SRES); // Send reset command strobe.
digitalWrite(SS, HIGH); // Deselect the CC1101.
}
//
// Write the CC1101 Configuration Registers.
//
void DAVIS::setRegisters(void)
{
writeRegister(CC1101_IOCFG2, DAVIS_IOCFG2);
writeRegister(CC1101_IOCFG1, DAVIS_IOCFG1);
writeRegister(CC1101_IOCFG0, DAVIS_IOCFG0);
writeRegister(CC1101_FIFOTHR, DAVIS_FIFOTHR);
writeRegister(CC1101_SYNC1, DAVIS_SYNC1);
writeRegister(CC1101_SYNC0, DAVIS_SYNC0);
writeRegister(CC1101_PKTLEN, DAVIS_PKTLEN);
writeRegister(CC1101_PKTCTRL1, DAVIS_PKTCTRL1);
writeRegister(CC1101_PKTCTRL0, DAVIS_PKTCTRL0);
writeRegister(CC1101_ADDR, DAVIS_ADDR);
writeRegister(CC1101_CHANNR, DAVIS_CHANNR);
writeRegister(CC1101_FSCTRL1, DAVIS_FSCTRL1);
writeRegister(CC1101_FSCTRL0, DAVIS_FSCTRL0);
writeRegister(CC1101_FREQ2, DAVIS_FREQ2);
writeRegister(CC1101_FREQ1, DAVIS_FREQ1);
writeRegister(CC1101_FREQ0, DAVIS_FREQ0);
writeRegister(CC1101_MDMCFG4, DAVIS_MDMCFG4);
writeRegister(CC1101_MDMCFG3, DAVIS_MDMCFG3);
writeRegister(CC1101_MDMCFG2, DAVIS_MDMCFG2);
writeRegister(CC1101_MDMCFG1, DAVIS_MDMCFG1);
writeRegister(CC1101_MDMCFG0, DAVIS_MDMCFG0);
writeRegister(CC1101_DEVIATN, DAVIS_DEVIATN);
writeRegister(CC1101_MCSM2, DAVIS_MCSM2);
writeRegister(CC1101_MCSM1, DAVIS_MCSM1);
writeRegister(CC1101_MCSM0, DAVIS_MCSM0);
writeRegister(CC1101_FOCCFG, DAVIS_FOCCFG);
writeRegister(CC1101_BSCFG, DAVIS_BSCFG);
writeRegister(CC1101_AGCCTRL2, DAVIS_AGCCTRL2);
writeRegister(CC1101_AGCCTRL1, DAVIS_AGCCTRL1);
writeRegister(CC1101_AGCCTRL0, DAVIS_AGCCTRL0);
writeRegister(CC1101_WOREVT1, DAVIS_WOREVT1);
writeRegister(CC1101_WOREVT0, DAVIS_WOREVT0);
writeRegister(CC1101_WORCTRL, DAVIS_WORCTRL);
writeRegister(CC1101_FREND1, DAVIS_FREND1);
writeRegister(CC1101_FREND0, DAVIS_FREND0);
writeRegister(CC1101_FSCAL3, DAVIS_FSCAL3);
writeRegister(CC1101_FSCAL2, DAVIS_FSCAL2);
writeRegister(CC1101_FSCAL1, DAVIS_FSCAL1);
writeRegister(CC1101_FSCAL0, DAVIS_FSCAL0);
writeRegister(CC1101_RCCTRL1, DAVIS_RCCTRL1);
writeRegister(CC1101_RCCTRL0, DAVIS_RCCTRL0);
writeRegister(CC1101_FSTEST, DAVIS_FSTEST);
writeRegister(CC1101_PTEST, DAVIS_PTEST);
writeRegister(CC1101_AGCTEST, DAVIS_AGCTEST);
writeRegister(CC1101_TEST2, DAVIS_TEST2);
writeRegister(CC1101_TEST1, DAVIS_TEST1);
writeRegister(CC1101_TEST0, DAVIS_TEST0);
writeBurst(CC1101_PATABLE, (uint8_t*)PA_TABLE, 8);
setFrequency(hopIndex);
digitalWrite(15, HIGH);
}
//
// Write a strobe command.
//
void DAVIS::cmdStrobe(uint8_t command)
{
digitalWrite(SS, LOW); // Select the CC1101.
SPI.transfer(command); // Send strobe command.
digitalWrite(SS, HIGH); // Deselect the CC1101 .
}
//
// Write to a single register.
//
void DAVIS::writeRegister(uint8_t regAddr, uint8_t value)
{
digitalWrite(SS, LOW); // Select the CC1101.
SPI.transfer(regAddr); // Send register address.
SPI.transfer(value); // Send value.
digitalWrite(SS, HIGH); // Deselect the CC1101.
}
//
// Write to sequential registers.
//
void DAVIS::writeBurst(uint8_t regAddr, uint8_t *buffer, uint8_t length)
{
uint8_t addr, i;
addr = regAddr | WRITE_BURST; // Enable burst transfer.
digitalWrite(SS, LOW); // Select the CC1101.
SPI.transfer(addr); // Send register base address.
for(i = 0; i < length; i++)
SPI.transfer(buffer[i]); // Send values byte by byte.
digitalWrite(SS, HIGH); // Deselect the CC1101.
}
//
// Read from a single register.
//
uint8_t DAVIS::readRegister(uint8_t regAddr)
{
uint8_t addr, value;
addr = regAddr | READ_SINGLE;
digitalWrite(SS, LOW); // Select the CC1101.
SPI.transfer(addr); // Send register address.
value = SPI.transfer(0x00); // Read value.
digitalWrite(SS, HIGH); // Deselect the CC1101.
return value;
}
//
// Read from sequential registers.
//
void DAVIS::readBurst(uint8_t regAddr, uint8_t *buffer, uint8_t length)
{
uint8_t addr, i;
addr = regAddr | READ_BURST;
digitalWrite(SS, LOW); // Select the CC1101.
SPI.transfer(addr); // Send register base address.
for(i = 0; i < length; i++)
buffer[i] = SPI.transfer(0x00); // Read registers byte by byte.
digitalWrite(SS, HIGH); // Deselect the CC1101.
}
//
// Read the status from a register.
//
uint8_t DAVIS::readStatus(uint8_t regAddr)
{
uint8_t addr, value;
addr = regAddr | READ_BURST;
digitalWrite(SS, LOW); // Select the CC1101.
SPI.transfer(addr); // Send register address.
value = SPI.transfer(0x00); // Read status.
digitalWrite(SS, HIGH); // Deselect the CC1101.
return value;
}
//
// Sets Idle Mode.
//
void DAVIS::idle(void)
{
setIdleState();
}
//
// Sets Rx Mode.
//
void DAVIS::rx(void)
{
setRxState();
while ((Radio.readStatus(CC1101_MARCSTATE) & 0x1F) != CC1101_STATE_RX)
delayMicroseconds(900);
rxing = 1;
writeRegister(CC1101_IOCFG0, DAVIS_IOCFG0);
}
//
// Controls frequency hopping.
//
void DAVIS::hop(void)
{
digitalWrite(9, HIGH); // Turn on hopping LED.
hopIndex++; // Increment the index
if (hopIndex > 4) // Clamp at 51.
hopIndex = 0;
writeRegister(CC1101_FSCTRL0, freqComp[hopIndex]); // Write FSCTRL0.
setFrequency(hopIndex); // Set the frequency.
digitalWrite(9, LOW); // Turn off hopping LED.
}
//
// Sets the RX or TX frequency from the lookup table.
//
void DAVIS::setFrequency(uint8_t index)
{
idle(); // Make sure we are in idle state.
writeRegister(CC1101_FREQ2, pgm_read_byte(&FREQ_2[index])); // Write FREQ2.
writeRegister(CC1101_FREQ1, pgm_read_byte(&FREQ_1[index])); // Write FREQ1.
writeRegister(CC1101_FREQ0, pgm_read_byte(&FREQ_0[index])); // Write FREQ0.
flush(); // Flush everything.
}
//
// Receive the data packet.
//
void DAVIS::rxData(void)
{
uint8_t pktVerify, pktLength, freqEst, addr, i;
uint16_t pktCrc = 0xFFFF;
//////////////////////////////////////////// See Errata Note for this section.
pktVerify = readStatus(CC1101_RXBYTES) & 0x7F;
do
{
pktLength = pktVerify;
pktVerify = readStatus(CC1101_RXBYTES) & 0x7F;
}
while (pktLength != pktVerify);
////////////////////////////////////////////
if ((readStatus(CC1101_MARCSTATE) & 0x1F) == CC1101_STATE_RXFIFO_ERROR) // Check for Rx FIFO Overrun.
pktLength = 0;
if (pktLength == DAVIS_PACKET_LENGTH)
{
addr = CC1101_RXFIFO | READ_BURST;
digitalWrite(SS, LOW); // Select the CC1101.
SPI.transfer(addr); // Send register base address.
SPI.setBitOrder(LSBFIRST); // Reverse the bit order.
for(i = 0; i < 10; i++)
rxBuffer[i] = SPI.transfer(0x00); // Read rx data into the buffer.
SPI.setBitOrder(MSBFIRST); // Set the bit order back.
for(i = 10; i < 12; i++)
rxBuffer[i] = SPI.transfer(0x00); // Read RSSI & LQI into the buffer.
digitalWrite(SS, HIGH); // Deselect the CC1101.
pktCrc = calcCrc(rxBuffer, 8); // Get the CRC for first eight bytes.
//pktCrc = 0x0000; // Uncomment to disable CRC checking.
if (pktCrc == 0x0000) // If CRC = 0, valid data is now available.
{
now = timer = 0;
pktRssi = calcRssi(rxBuffer[10]);
pktLqi = (rxBuffer[11] & 0x7F);
freqEst = readStatus(CC1101_FREQEST);
freqError = calcFreqError(freqEst);
freqComp[hopIndex] = freqComp[hopIndex] + freqEst;
pktCount++;
rxBufferLength = pktLength;
rxing = 0;
writeRegister(CC1101_IOCFG0, DAVIS_DISABLED); // Disable CC1101 Rx interrupts.
digitalWrite(14, HIGH);
return;
}
}
idle();
flushRxFifo();
rx();
}
//
// Implements the standard Arduino available() function.
//
int DAVIS::available(void)
{
if (rxBufferIndex == rxBufferLength)
return -1;
else
return rxBufferLength - rxBufferIndex;
}
//
// Implements the standard Arduino read() function.
//
uint8_t DAVIS::read(void)
{
uint8_t value = 0x00;
if (rxBufferIndex < rxBufferLength)
{
value = rxBuffer[rxBufferIndex];
rxBufferIndex++;
}
else
rxBufferIndex = rxBufferLength = 0;
return value;
}
//
// Flushes FIFO's and the receive buffer.
//
void DAVIS::flush(void)
{
flushRxFifo(); // Flush both CC1101 FIFO's.
flushTxFifo();
for (int i = 0; i < BUFFER_SIZE; i++) // Flush the rxBuffer.
rxBuffer[i] = 0x00;
rxBufferLength = rxBufferIndex = 0;
}
//
// Calculates the 16 bit CRC using the Davis method.
//
uint16_t DAVIS::calcCrc(uint8_t *buffer, uint8_t length)
{
uint16_t crc = 0x0000;
while (length-- > 0)
{
crc = (crc << 8) ^ pgm_read_word(&CRC_TABLE[(crc >> 8) ^ (*buffer++)]);
};
return crc;
}
//
// Calculates the RSSI in dBm.
//
char DAVIS::calcRssi(uint8_t value)
{
int rssi;
if (value >= 128)
rssi = ((value - 256) >> 1) - 74; // CC1101 RSSI offset value.
else
rssi = (value >> 1) - 74;
if (rssi < -128)
rssi = -128;
return rssi;
}
//
// Calculates the Frequency Error for display purposes.
//
int DAVIS::calcFreqError(uint8_t value)
{
int error;
if (value >= 128)
error = ((value - 256) >> 1);
else
error = (value >> 1);
return error;
}
//
// INT0 Interrupt Service Routine.
//
ISR(INT0_vect)
{
Radio.rxData();
}
//
// Timer 2 Compare Match A Interrupt Service Routine.
//
ISR(TIMER2_COMPA_vect)
{
timer++;
if (timer >= 4)
{
timer = 0;
now++;
next++;
}
if (now >= 44 && rxing == 0)
Radio.rx();
}
//
//
//
DAVIS Radio;

View File

@@ -1,239 +0,0 @@
/*
Davis.h
Arduino library that implements the Davis Instruments Vantage Vue
weather station protocol for the RFBee.
Version 0.8
Copyright (c) 2012 by Ray H. Dees
NOTE: This code is currently below version 1.0, and therefore is
lacking some functionality or documentation, or may not be fully
tested.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//
#ifndef Davis_h
#define Davis_h
//
#include "Arduino.h"
//
// Arduino Definitions.
//
#define SS 10 // Arduino Digital Pin used for Slave Select - Out
#define GDO0 2 // Arduino Digital Pin used for INT0 - In
#define GDO2 3 // Arduino Digital Pin used for INT1 - In
//
#ifndef NO_INTERRUPTS()
#define NO_INTERRUPTS() uint8_t sreg = SREG; cli()
#define INTERRUPTS() SREG = sreg
#endif
//
#ifndef TIMER2_RUN()
#define TIMER2_RUN() TCNT2 = 0x00; TIMSK2 = (1 << OCIE2A)
#define TIMER2_RESET() TCNT2 = 0x00; timer = 0
#define TIMER2_STOP() TIMSK2 &= ~(1 << OCIE2A)
#endif
//
#define BUFFER_SIZE 16 // TX & RX Buffer Size
//
// Davis Packet Length.
//
#define DAVIS_PACKET_LENGTH 12 // The actual packet length including RSSI & LQI
//
// Davis Register Configuration Settings.
//
#define DAVIS_IOCFG2 0x2E // GDO2 Output Pin Configuration
#define DAVIS_IOCFG1 0x2E // GDO1 Output Pin Configuration
#define DAVIS_IOCFG0 0x01 // GDO0 Output Pin Configuration
//
#define DAVIS_FIFOTHR 0x42 // RX FIFO and TX FIFO Thresholds
//
#define DAVIS_SYNC1 0xCB // Synchronization word, high byte
#define DAVIS_SYNC0 0x89 // Synchronization word, low byte
//
#define DAVIS_PKTLEN 0x0A // Packet Length
#define DAVIS_PKTCTRL1 0xC4 // Packet Automation Control
#define DAVIS_PKTCTRL0 0x00 // Packet Automation Control
//
#define DAVIS_ADDR 0x00 // Device Address
#define DAVIS_CHANNR 0x00 // Channel Number
#define DAVIS_FSCTRL1 0x06 // Frequency Synthesizer Control
#define DAVIS_FSCTRL0 0xF0 // Frequency Synthesizer Control
//
#define DAVIS_FREQ2 0x23 // Frequency Control Word, High Byte
#define DAVIS_FREQ1 0x0D // Frequency Control Word, Middle Byte
#define DAVIS_FREQ0 0x97 // Frequency Control Word, Low Byte
//
#define DAVIS_MDMCFG4 0xC9 // Modem Configuration
#define DAVIS_MDMCFG3 0x83 // Modem Configuration
#define DAVIS_MDMCFG2 0x12 // Modem Configuration
#define DAVIS_MDMCFG1 0x21 // Modem Configuration
#define DAVIS_MDMCFG0 0xF9 // Modem Configuration
//
#define DAVIS_DEVIATN 0x24 // Modem Deviation Setting
//
#define DAVIS_MCSM2 0x07 // Main Radio Control State Machine Configuration
#define DAVIS_MCSM1 0x00 // Main Radio Control State Machine Configuration
#define DAVIS_MCSM0 0x18 // Main Radio Control State Machine Configuration
//
#define DAVIS_FOCCFG 0x16 // Frequency Offset Compensation Configuration
#define DAVIS_BSCFG 0x6C // Bit Synchronization Configuration
//
#define DAVIS_AGCCTRL2 0x43 // AGC Control
#define DAVIS_AGCCTRL1 0x40 // AGC Control
#define DAVIS_AGCCTRL0 0x91 // AGC Control
//
#define DAVIS_WOREVT1 0x87 // High Byte Event0 Timeout
#define DAVIS_WOREVT0 0x6B // Low Byte Event0 Timeout
#define DAVIS_WORCTRL 0xF8 // Wake On Radio Control
//
#define DAVIS_FREND1 0x56 // Front End RX Configuration
#define DAVIS_FREND0 0x10 // Front End TX Configuration
//
#define DAVIS_FSCAL3 0xEF // Frequency Synthesizer Calibration
#define DAVIS_FSCAL2 0x2B // Frequency Synthesizer Calibration
#define DAVIS_FSCAL1 0x2F // Frequency Synthesizer Calibration
#define DAVIS_FSCAL0 0x1F // Frequency Synthesizer Calibration
//
#define DAVIS_RCCTRL1 0x00 // RC Oscillator Configuration
#define DAVIS_RCCTRL0 0x00 // RC Oscillator Configuration
//
#define DAVIS_FSTEST 0x59 // Frequency Synthesizer Calibration Control
#define DAVIS_PTEST 0x7F // Production Test
#define DAVIS_AGCTEST 0x3F // AGC Test
//
#define DAVIS_TEST2 0x81 // Various Test Settings
#define DAVIS_TEST1 0x35 // Various Test Settings
#define DAVIS_TEST0 0x09 // Various Test Settings
//
#define DAVIS_DISABLED 0x2E // Disables GPIO's
//
// Table for FREQ2 settings. (Vantage VUE - EU 868 mHz)
//
static const uint8_t __attribute__ ((progmem)) FREQ_2[5] =
{
0x21, 0x21, 0x21, 0x21, 0x21
};
//
// Table for FREQ1 settings.
//
static const uint8_t __attribute__ ((progmem)) FREQ_1[5] =
{
0x62, 0x65, 0x67, 0x64, 0x66
};
//
// Table for FREQ0 settings.
//
static const uint8_t __attribute__ ((progmem)) FREQ_0[5] =
{
0xE2, 0x40, 0x9D, 0x11, 0x6F
};
//
// CRC Lookup Table.
//
static const uint16_t __attribute__ ((progmem)) CRC_TABLE[256] =
{
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
};
//
// Global Variables.
//
extern volatile uint8_t hopIndex;
extern volatile int pktRssi;
extern volatile uint8_t pktLqi;
extern volatile int freqError;
extern volatile uint16_t pktCount;
extern volatile uint16_t pktMiss;
extern volatile uint8_t timer;
extern volatile uint8_t now;
extern volatile uint8_t next;
extern volatile uint8_t rxing;
extern volatile uint8_t hopping;
//
// DAVIS Class.
//
class DAVIS
{
private:
static uint8_t rxBuffer[];
static volatile uint8_t rxBufferIndex;
static volatile uint8_t rxBufferLength;
static volatile uint8_t freqComp[];
public:
void begin(void);
void reset(void);
void setRegisters(void);
void cmdStrobe(uint8_t command);
void writeRegister(uint8_t regAddr, uint8_t value);
void writeBurst(uint8_t regAddr, uint8_t *buffer, uint8_t length);
uint8_t readRegister(uint8_t regAddr);
void readBurst(uint8_t regAddr, uint8_t *buffer, uint8_t length);
uint8_t readStatus(uint8_t regAddr);
void idle(void);
void rx(void);
void hop(void);
void setFrequency(uint8_t index);
void rxData(void);
int available(void);
uint8_t read(void);
void flush(void);
uint16_t calcCrc(uint8_t *buffer, uint8_t length);
char calcRssi(uint8_t value);
int calcFreqError(uint8_t value);
};
extern DAVIS Radio;
//
//
//
#endif

View File

@@ -1,76 +0,0 @@
/*
Davis logger
*/
// připojení potřebných knihoven
#include <Wire.h>
#include "Davis.h"
#include "SPI.h"
//
byte temp;
String data;
int incByte = 0;
void setup()
{
delay(100);
Serial.begin(9600);
delay(100);
Radio.begin();
Radio.rx();
Serial.println("Done Setup");
}
void loop()
{
if (Radio.available() > 0)
printPacket();
if (hopping)
{
hopping = 0;
Radio.hop();
Radio.rx(); // Un-comment if not using Timer 2.
}
}
void printPacket(void)
{
byte header = Radio.read(); // Where's the header?
byte package[16];
package[0] = hopIndex; // Which frequency are we at?
package[1] = header;
for (int i = 2; i < 11; i++) // The received packet.
{
package[i] = Radio.read();
}
package[11] = pktRssi;
package[12] = pktLqi;
package[13] = freqError;
package[14] = next;
package[15] = pktCount;
String data = "{'hop':" + String(package[0]) + "," +
"'h':" + String(package[1]) + "," +
"'b0':" + String(package[2]) + "," +
"'b1':" + String(package[3]) + "," +
"'b2':" + String(package[4]) + "," +
"'b3':" + String(package[5]) + "," +
"'b4':" + String(package[6]) + "," +
"'b5':" + String(package[7]) + "," +
"'b6':" + String(package[8]) + "," +
"'b7':" + String(package[9]) + "," +
"'b8':" + String(package[10]) + "," +
"'b9':" + String(package[11]) + "," +
"'rssi':" + String(package[12]) + "," +
"'lqi':" + String(package[13]) + "," +
"'nxt':" + String(package[14]) + "," +
"'cnt':" + String(package[15]) + "}";
Serial.println(data);
hopping = 1; // Turn on hopping.
}

View File

@@ -1 +0,0 @@
Working version, flawlesly!