-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsi4463-beacon.ino
203 lines (175 loc) · 5.67 KB
/
si4463-beacon.ino
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// Si4463 CW Beacon
//
// Simple CW beacon for Arduino and SiLabs Si4463, forked from RA9YER Alexander
// https://github.com/alexander-sholohov and slightly modified by IU5HKU Marco
//
// Hardware info
// ---------------------
// serial debug port baud rate: 74880
// Si5351A is connected via I2C on pin D1 (SCL) and D2 (SDA) as marked on Wemos D1 mini Lite
// freq0 is used in clock0 output, freq1 in clock1, freq2 in clock2
// on SV1AFN board clock0 is marked J1, clock1 J2, clock2 J3.
//
// Hardware Requirements
// ---------------------
// This firmware must be run on an Arduino compatible board
// tested on Arduino Nano and Arduino Uno.
//
//The MIT License (MIT)
// ---------------------
//Copyright (c) 2016 Alexander Sholohov <ra9yer@yahoo.com>
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
#include "src/morse/morse.h"
#include "src/si4463/si4463.h"
#include <avr/sleep.h>
#include <avr/wdt.h>
const int nSEL = 7; // out
const int siMOSI = 6; // out
const int siMISO = 5; // in
const int siSCK = 4; // out
const int siSDN = 2; // out (Si4463 shutdown)
const int pinOOK = 3; // out
const int pinLED = 13; // out (onboard led)
const int pinEXLED = 12; // out (external led)
bool prevTransmittingActive = false;
// watchdog interrupt
ISR (WDT_vect)
{
wdt_disable(); // disable watchdog
} // end of WDT_vect
// going to sleep
void Sleep(){
// disable ADC
ADCSRA = 0;
// clear various "reset" flags
MCUSR = 0;
// allow changes, disable reset
WDTCSR = bit (WDCE) | bit (WDE);
// set interrupt mode and an interval
WDTCSR = bit (WDIE) | bit (WDP3) | bit (WDP0); // set WDIE, and 8 seconds delay
wdt_reset(); // pat the dog
set_sleep_mode (SLEEP_MODE_PWR_DOWN);
noInterrupts (); // timed sequence follows
sleep_enable();
// turn off brown-out enable in software
MCUCR = bit (BODS) | bit (BODSE);
MCUCR = bit (BODS);
interrupts (); // guarantees next instruction executed
sleep_cpu ();
// cancel sleep as a precaution
sleep_disable();
}
CMorse morse;
CSi4463 transmitter(nSEL, siMOSI, siMISO, siSCK, pinOOK, siSDN);
//------------------------------------------
void setup() {
pinMode(nSEL, OUTPUT);
pinMode(siMOSI, OUTPUT);
pinMode(siMISO, INPUT);
pinMode(siSCK, OUTPUT);
pinMode(siSDN, OUTPUT);
pinMode(pinOOK, OUTPUT);
pinMode(pinLED, OUTPUT);
pinMode(pinEXLED, OUTPUT);
//Serial.begin(9600);
morse.setText("____ VVV VVV IU5HKU/B IU5HKU/B JN53HB JN53HB K"); // <---- place your text here
//transmitter.setDebugSerial(&Serial);
morse.start();
}
//------------------------------------------
void loop() {
// TODO: Remove. Research purpose only.
/*
if (Serial.available()) {
int inByte = Serial.read();
if( inByte == 'o' )
{
Serial.println(F("do si initialize"));
transmitter.initialize();
}
else if( inByte == 't' )
{
Serial.println(F("do tx"));
transmitter.activateTX();
}
else if( inByte == 'r' )
{
Serial.println(F("do ready"));
transmitter.activateRX();
}
else if( inByte == '1' )
{
Serial.println(F("o1"));
digitalWrite(pinOOK, HIGH);
}
else if( inByte == '0' )
{
Serial.println(F("o0"));
digitalWrite(pinOOK, LOW);
}
else if( inByte == '2' )
{
Serial.println(F("morse start"));
morse.start();
}
else if( inByte == '3' )
{
Serial.println(F("morse stop"));
morse.stop();
}
else
{
Serial.println(F("wrong command"));
}
}
*/
// We give CPU time to Morse subsystem.
morse.handleTimeout();
// Send commands to si4463 module based on morse state.
bool txActive = morse.isTransmittingActive();
// detect state changing
if( prevTransmittingActive != txActive )
{
if( txActive )
{
transmitter.exitSDN(); // wakeup si4463 from sleep
transmitter.initialize(); // POR
transmitter.activateTX(); // TX Mode
prevTransmittingActive = true;
}
else
{
transmitter.activateRX(); // RX Mode
transmitter.controlOOK( false );
prevTransmittingActive = false;
transmitter.enterSDN(); // put si4463 to sleep
Sleep(); // put Arduino to sleep for 8"
}
}
if( txActive )
{
// if transmitting is active we handle CW on/off
bool toneOn = morse.isToneActive();
transmitter.controlOOK( toneOn );
// LED duplicate
digitalWrite(pinLED, (toneOn)? HIGH : LOW );
digitalWrite(pinEXLED, (toneOn)? HIGH : LOW );
}
}