2014-11-05 21:06:39 +00:00
|
|
|
|
|
|
|
|
2014-11-28 20:42:28 +00:00
|
|
|
#include "rfm02.h"
|
2014-11-05 21:06:39 +00:00
|
|
|
|
|
|
|
uint8_t _pinFSK;
|
|
|
|
uint8_t _pinNIRQ;
|
|
|
|
uint8_t _pinSOMI;
|
|
|
|
uint8_t _pinSIMO;
|
|
|
|
uint8_t _pinChipSelect;
|
|
|
|
uint8_t _pinSerialClock;
|
|
|
|
|
|
|
|
// Booster Pack Pins FR5969
|
2014-11-28 20:42:28 +00:00
|
|
|
// 7 - P2.2 for SPI_CLK mode
|
|
|
|
// 15 - P1.6 for SPI_SIMO mode
|
|
|
|
// 14 - P1.7 for SPI_SOMI mode
|
|
|
|
// 5 - P2.5 output pin for SPI_CS
|
|
|
|
// 18 - P3.0 nIRQ for sending data
|
|
|
|
// 3 - P2.6 as FSK input data
|
|
|
|
// Set display's VCC and DISP pins to high
|
2014-11-05 21:06:39 +00:00
|
|
|
|
|
|
|
|
2014-12-15 20:52:39 +00:00
|
|
|
static const uint8_t P_CS = 11;
|
|
|
|
static const uint8_t P_FSK = 9;
|
|
|
|
static const uint8_t P_NIRQ = 10;
|
|
|
|
|
|
|
|
/*
|
2014-11-05 21:06:39 +00:00
|
|
|
static const uint8_t P_CS = 4;
|
|
|
|
static const uint8_t P_FSK = 3;
|
|
|
|
static const uint8_t P_NIRQ = 18;
|
2014-12-15 20:52:39 +00:00
|
|
|
*/
|
2014-11-05 21:06:39 +00:00
|
|
|
// empty constructor
|
|
|
|
RFM02::RFM02() {
|
|
|
|
RFM02(P_CS, P_FSK, P_NIRQ);
|
|
|
|
}
|
|
|
|
|
|
|
|
// constructor with variables
|
2014-11-28 20:42:28 +00:00
|
|
|
RFM02::RFM02(uint8_t pinChipSelect, uint8_t pinFSK, uint8_t pinNIRQ)
|
|
|
|
{
|
2014-11-05 21:06:39 +00:00
|
|
|
_pinChipSelect = pinChipSelect;
|
|
|
|
_pinFSK = pinFSK;
|
|
|
|
_pinNIRQ = pinNIRQ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RFM02::begin() {
|
2014-11-28 20:42:28 +00:00
|
|
|
digitalWrite(_pinChipSelect, HIGH); // set chip select high
|
|
|
|
pinMode(_pinChipSelect, OUTPUT); // set chip select as output
|
2014-11-05 21:06:39 +00:00
|
|
|
|
2014-11-28 20:42:28 +00:00
|
|
|
digitalWrite(_pinFSK, LOW); // set FSK to low
|
|
|
|
pinMode(_pinFSK, OUTPUT); // set FSK pin as output
|
2014-11-05 21:06:39 +00:00
|
|
|
|
2014-11-28 20:42:28 +00:00
|
|
|
pinMode(P_NIRQ, INPUT); // set nIRQ pin as input
|
2014-11-05 21:06:39 +00:00
|
|
|
|
2014-11-28 20:42:28 +00:00
|
|
|
configureDeviceSettings(); // configure RFM01
|
2014-11-05 21:06:39 +00:00
|
|
|
|
2014-11-28 20:42:28 +00:00
|
|
|
pinMode(RED_LED, OUTPUT); // set red led as output
|
|
|
|
digitalWrite(RED_LED, HIGH); // blink red led 50 ms
|
|
|
|
// to indicate setup ready
|
2014-11-12 20:12:33 +00:00
|
|
|
delay(50);
|
|
|
|
digitalWrite(RED_LED, LOW);
|
2014-11-05 21:06:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RFM02::writeRegister(uint8_t HighByte, uint8_t LowByte) {
|
|
|
|
digitalWrite(_pinChipSelect,LOW);
|
|
|
|
SPI.transfer(HighByte);
|
|
|
|
SPI.transfer(LowByte);
|
|
|
|
digitalWrite(_pinChipSelect,HIGH);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void RFM02::configureDeviceSettings() {
|
2014-11-07 07:46:21 +00:00
|
|
|
writeRegister(0xCC,0x00); // read status
|
2014-11-09 20:14:24 +00:00
|
|
|
writeRegister(0x93,0x82); // 868MHz Band +/- 90kHz Bandbreite
|
2014-11-07 07:46:21 +00:00
|
|
|
writeRegister(0xA6,0x86); // 868.35 MHz
|
2014-11-08 20:41:42 +00:00
|
|
|
writeRegister(0xD0,0x40); // RATE/2
|
2014-12-10 20:21:32 +00:00
|
|
|
writeRegister(0xC8,0x23); // 38.4/2 = 19.2kbps
|
2014-11-07 07:46:21 +00:00
|
|
|
writeRegister(0xC2,0x20); // Bit Sync active
|
|
|
|
writeRegister(0xC0,0x01); // disable TX
|
|
|
|
writeRegister(0xD2,0x40); // PLL 25%
|
2014-12-10 20:21:32 +00:00
|
|
|
writeRegister(0xB0,0x00); // 0 db
|
2014-11-07 07:46:21 +00:00
|
|
|
writeRegister(0xE0,0x00); // 'disable wakeup timer
|
2014-11-12 20:12:33 +00:00
|
|
|
|
2014-11-05 21:28:53 +00:00
|
|
|
}
|
2014-11-05 21:06:39 +00:00
|
|
|
|
2014-11-06 16:06:21 +00:00
|
|
|
// Data via FSK
|
|
|
|
/******************************************************************************/
|
|
|
|
/* Sending data via the FSK-Pin as Input-Pin */
|
|
|
|
/* */
|
|
|
|
/* After the PowerAmplifier has turned on ( ea=1 ) from rfm02-module */
|
|
|
|
/* comes a clock corresponding to the data-rate set before on nIRQ. */
|
|
|
|
/* The data to be transmitted is bitwise set on the FSK-Pin of the */
|
|
|
|
/* module, after the falling edge of nIRQ. With the following edge */
|
|
|
|
/* of nIRQ this bit is read in and sent out. */
|
|
|
|
/* nSEL must be high, SCK low, both all the time */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* TESTED: 28.09.2014 with Deviation +/- 90kHz and 435.000 MHz */
|
|
|
|
/* up to 115.000BPS */
|
|
|
|
/* */
|
|
|
|
/* Support & Copyright: tigarus.programming@web.de */
|
|
|
|
/******************************************************************************/
|
2014-11-06 18:47:46 +00:00
|
|
|
void RFM02::RFM02_TX_DataByte_FSK(uint8_t DataByte){
|
2014-11-06 16:06:21 +00:00
|
|
|
uint8_t i=8;
|
|
|
|
// PowerAmplifier is here already enabled, impulses on nIRQ corresponding to the
|
2014-12-08 20:15:38 +00:00
|
|
|
// set data-rate, nSEL is high, SCK is low
|
2014-12-10 20:21:32 +00:00
|
|
|
|
2014-11-08 20:41:42 +00:00
|
|
|
digitalWrite(_pinChipSelect,HIGH);
|
2014-12-08 20:15:38 +00:00
|
|
|
while(i){ // do 8 times
|
|
|
|
i=i-1;
|
|
|
|
// wait for the 0-1-edge of nIRQ, reading in the data
|
|
|
|
while(!(digitalRead(_pinNIRQ)));
|
|
|
|
// wait for 1-0-edge to send the last bit
|
|
|
|
while((digitalRead(_pinNIRQ)));
|
|
|
|
// if not '0' write over with '1'
|
|
|
|
if( DataByte & BIT7 )
|
|
|
|
digitalWrite(_pinFSK, HIGH); // write '1' if most significant bit is '1'
|
|
|
|
else
|
2014-11-07 07:46:21 +00:00
|
|
|
digitalWrite(_pinFSK, LOW); //OUT_PORT_REG &= ~FSK; // first set Bitx as '0'
|
2014-12-08 20:15:38 +00:00
|
|
|
// shift DataByte one bit left to write the next bit
|
|
|
|
DataByte <<= 1;
|
2014-11-06 16:06:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-13 19:31:04 +00:00
|
|
|
|
|
|
|
void RFM02::sendMessage(uint8_t *txData, uint8_t size)
|
|
|
|
{
|
|
|
|
|
|
|
|
//digitalWrite(_pinChipSelect, LOW); // CS LOW
|
|
|
|
writeRegister(0xC0,0x39); // enable TX
|
|
|
|
//digitalWrite(_pinChipSelect, HIGH); // CS HIGH
|
2014-12-10 20:21:32 +00:00
|
|
|
delay(2);
|
2014-11-13 19:31:04 +00:00
|
|
|
RFM02_TX_DataByte_FSK(0xAA); // preamble
|
|
|
|
RFM02_TX_DataByte_FSK(0xAA); // preamble
|
|
|
|
RFM02_TX_DataByte_FSK(0xAA); // preamble
|
|
|
|
|
|
|
|
RFM02_TX_DataByte_FSK(0x2D); // sync word high
|
|
|
|
RFM02_TX_DataByte_FSK(0xD4); // sync word low
|
|
|
|
|
|
|
|
for(int myLoop=0;myLoop<MESSAGELENGTH;myLoop++)
|
|
|
|
{
|
|
|
|
RFM02_TX_DataByte_FSK(txData[myLoop]); // sync word lowtxData[myLoop] = myLoop;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
RFM02_TX_DataByte_FSK('H'); // data
|
|
|
|
RFM02_TX_DataByte_FSK('E'); // data
|
|
|
|
RFM02_TX_DataByte_FSK('L'); // data
|
|
|
|
RFM02_TX_DataByte_FSK('L'); // data
|
|
|
|
RFM02_TX_DataByte_FSK('O'); // data
|
|
|
|
|
|
|
|
RFM02_TX_DataByte_FSK(1); // data
|
|
|
|
RFM02_TX_DataByte_FSK(2); // data
|
|
|
|
RFM02_TX_DataByte_FSK(3); // data
|
|
|
|
RFM02_TX_DataByte_FSK(4); // data
|
|
|
|
|
|
|
|
RFM02_TX_DataByte_FSK(0xA5); // ende zeichen
|
|
|
|
*/
|
2014-12-08 20:15:38 +00:00
|
|
|
//delayMicroseconds(2410); // delay until carrier turn off
|
|
|
|
//digitalWrite(_pinFSK, HIGH);
|
2014-12-10 20:21:32 +00:00
|
|
|
|
|
|
|
// while((digitalRead(_pinNIRQ)));
|
|
|
|
//while(!(digitalRead(_pinNIRQ)));
|
|
|
|
|
|
|
|
//while((digitalRead(_pinNIRQ)));
|
|
|
|
// while(!(digitalRead(_pinNIRQ)));
|
|
|
|
//__delay_cycles(1500);
|
2014-12-08 20:15:38 +00:00
|
|
|
delay(1);
|
|
|
|
|
2014-11-13 19:31:04 +00:00
|
|
|
|
|
|
|
//digitalWrite(_pinChipSelect, LOW); // CS LOW
|
|
|
|
writeRegister(0xC0,0x01); // disable TX
|
|
|
|
//digitalWrite(_pinChipSelect, HIGH); // CS HIGH
|
|
|
|
|
|
|
|
}
|