/
rfmtest.pde
139 lines (118 loc) · 3.33 KB
/
rfmtest.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* Test tracker which sends out test strings for testing HAB listening station
* RFM22b
* DL-FLDigi settings:
** 50baud
** 460 shift
** 8 bits, no parity, 1 stop bit
*/
#include <stdio.h>
#include <util/crc16.h>
#include <SPI.h>
#include <RFM22.h>
#define RFM_NSEL_PIN 10
int count = 1;
//Setup radio on SPI with NSEL on pin 10
rfm22 radio1(RFM_NSEL_PIN);
void setupRadio(){
delay(3000) ;
rfm22::initSPI();
radio1.init();
delay(500) ;
radio1.write(0x71, 0x00); // unmodulated carrier
//This sets up the GPIOs to automatically switch the antenna depending on Tx or Rx state, only needs to be done at start up.
// 0b and 0c are swapped (compared to other code) because GPIO0 and GPIO1 are swapped connected to TX_ANT and RX_ANT on this HAB supplies breakout.
radio1.write(0x0b,0x15);
radio1.write(0x0c,0x12);
radio1.setFrequency(434.250); // frequency, we modulate it in rtty_txbit()
radio1.write(0x07, 0x08); // turn tx on
radio1.write(0x6D, 0x04);// turn tx low power 14db = 25mW
}
// RTTY Functions - from RJHARRISON's AVR Code
void rtty_txstring (char * string)
{
/* Simple function to sent a char at a time to
** rtty_txbyte function.
** NB Each char is one byte (8 Bits)
*/
char c;
c = *string++;
while ( c != '\0')
{
rtty_txbyte (c);
c = *string++;
}
}
void rtty_txbyte (char c)
{
/* Simple function to sent each bit of a char to
** rtty_txbit function.
** NB The bits are sent Least Significant Bit first
**
** All chars should be preceded with a 0 and
** proceded with a 1. 0 = Start bit; 1 = Stop bit
**
** ASCII_BIT = 7 or 8 for ASCII-7 / ASCII-8
*/
int i;
rtty_txbit (0); // Start bit
// Send bits for for char LSB first
for (i=0;i<8;i++)
{
if (c & 1) rtty_txbit(1);
else rtty_txbit(0);
c = c >> 1;
}
rtty_txbit (1); // Stop bit
rtty_txbit (1); // Stop bit
}
void rtty_txbit (int bit)
{
if (bit)
{
// high; 0x073 is least significant bit of frequency register, 2x156Hz; 156Hz = smallest frequency adjustment possible on the RFM22b
radio1.write(0x073, 0x03);
}
else
{
// low
radio1.write(0x073, 0x00);
}
delayMicroseconds(3370); // 300 baud
// delayMicroseconds(10000); // For 50 Baud uncomment this and the line below.
// delayMicroseconds(10150); // You can't do 20150 it just doesn't work as the
// largest value that will produce an accurate delay is 16383
// See : http://arduino.cc/en/Reference/DelayMicroseconds
}
uint16_t gps_CRC16_checksum (char *string)
{
size_t i;
uint16_t crc;
uint8_t c;
crc = 0xFFFF;
// Calculate checksum ignoring the first two $s
for (i = 2; i < strlen(string); i++)
{
c = string[i];
crc = _crc_xmodem_update (crc, c);
}
return crc;
}
void setup()
{
setupRadio() ;
Serial.begin(9600);
}
void loop() {
char superbuffer [150];
char checksum [10];
int n;
n=sprintf( superbuffer, "$$REVSPACE,%d,Hello to all intelligent life forms everywhere. And to everyone else out there, the secret is to bang the rocks together, guys.", count);
if (n > -1){
n = sprintf (superbuffer, "%s*%04X\n", superbuffer, gps_CRC16_checksum(superbuffer));
rtty_txstring(superbuffer);
Serial.println(superbuffer);
}
count++;
delay(3000);
}