2016-08-14 02:25:46 +00:00
|
|
|
/* Hamshield
|
|
|
|
* Example: AX25 Receive
|
|
|
|
* This example receives AFSK test data. You will need seperate
|
|
|
|
* AFSK equipment to send data for this example.
|
|
|
|
* Connect the HamShield to your Arduino. Screw the antenna
|
|
|
|
* into the HamShield RF jack. Plug a pair of headphones into
|
|
|
|
* the HamShield. Connect the Arduino to wall power and then to
|
|
|
|
* your computer via USB. After uploading this program to your
|
|
|
|
* adruino, open the Serial Monitor so you will see the AFSK
|
|
|
|
* packet. Send AFSK packet from AFSK equipment at 145.01MHz.
|
|
|
|
|
|
|
|
* Note: add message receive code
|
|
|
|
*/
|
|
|
|
|
2015-07-06 17:40:50 +00:00
|
|
|
#include <HamShield.h>
|
2016-08-17 21:17:56 +00:00
|
|
|
#include <DDS.h>
|
2016-08-20 01:52:36 +00:00
|
|
|
#include <packet.h>
|
2015-07-06 17:40:50 +00:00
|
|
|
|
2015-11-23 16:54:10 +00:00
|
|
|
#define PWM_PIN 3
|
|
|
|
#define RESET_PIN A3
|
|
|
|
#define SWITCH_PIN 2
|
|
|
|
|
2015-07-06 17:40:50 +00:00
|
|
|
HamShield radio;
|
|
|
|
DDS dds;
|
2016-08-17 21:17:56 +00:00
|
|
|
AFSK afsk;
|
2015-07-06 17:40:50 +00:00
|
|
|
|
|
|
|
void setup() {
|
2015-11-23 16:54:10 +00:00
|
|
|
// NOTE: if not using PWM out, it should be held low to avoid tx noise
|
|
|
|
pinMode(PWM_PIN, OUTPUT);
|
|
|
|
digitalWrite(PWM_PIN, LOW);
|
|
|
|
|
|
|
|
// prep the switch
|
|
|
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
|
|
|
|
|
|
|
// set up the reset control pin
|
|
|
|
pinMode(RESET_PIN, OUTPUT);
|
|
|
|
// turn on radio
|
|
|
|
digitalWrite(RESET_PIN, HIGH);
|
|
|
|
|
2015-07-06 17:40:50 +00:00
|
|
|
Serial.begin(9600);
|
2016-04-14 02:12:06 +00:00
|
|
|
|
2015-07-06 17:40:50 +00:00
|
|
|
Serial.println(F("Radio test connection"));
|
|
|
|
Serial.println(radio.testConnection(), DEC);
|
|
|
|
Serial.println(F("Initialize"));
|
|
|
|
delay(100);
|
|
|
|
radio.initialize();
|
2015-07-14 01:01:32 +00:00
|
|
|
radio.frequency(145010);
|
2015-07-10 17:58:37 +00:00
|
|
|
radio.setSQOff();
|
2015-07-06 17:40:50 +00:00
|
|
|
Serial.println(F("Frequency"));
|
|
|
|
delay(100);
|
2015-07-10 17:58:37 +00:00
|
|
|
Serial.print(F("Squelch(H/L): "));
|
|
|
|
Serial.print(radio.getSQHiThresh());
|
|
|
|
Serial.print(F(" / "));
|
|
|
|
Serial.println(radio.getSQLoThresh());
|
|
|
|
radio.setModeReceive();
|
2015-07-06 17:40:50 +00:00
|
|
|
Serial.println(F("DDS Start"));
|
|
|
|
delay(100);
|
|
|
|
dds.start();
|
|
|
|
Serial.println(F("AFSK start"));
|
|
|
|
delay(100);
|
2016-08-17 21:17:56 +00:00
|
|
|
afsk.start(&dds);
|
2015-07-06 17:40:50 +00:00
|
|
|
Serial.println(F("Starting..."));
|
|
|
|
delay(100);
|
|
|
|
dds.setAmplitude(255);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t last = 0;
|
|
|
|
void loop() {
|
2016-08-17 21:17:56 +00:00
|
|
|
if(afsk.decoder.read() || afsk.rxPacketCount()) {
|
2015-07-06 17:40:50 +00:00
|
|
|
// A true return means something was put onto the packet FIFO
|
|
|
|
// If we actually have data packets in the buffer, process them all now
|
2016-08-17 21:17:56 +00:00
|
|
|
while(afsk.rxPacketCount()) {
|
|
|
|
AFSK::Packet *packet = afsk.getRXPacket();
|
2015-07-10 17:58:37 +00:00
|
|
|
Serial.print(F("Packet: "));
|
2015-07-06 17:40:50 +00:00
|
|
|
if(packet) {
|
2015-07-14 01:01:32 +00:00
|
|
|
packet->printPacket(&Serial);
|
2015-07-06 17:40:50 +00:00
|
|
|
AFSK::PacketBuffer::freePacket(packet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-23 16:54:10 +00:00
|
|
|
//TODO: d2 is the switch input, so remove this
|
2015-07-06 17:40:50 +00:00
|
|
|
ISR(ADC_vect) {
|
|
|
|
static uint8_t tcnt = 0;
|
|
|
|
TIFR1 = _BV(ICF1); // Clear the timer flag
|
2015-11-23 16:54:10 +00:00
|
|
|
//PORTD |= _BV(2); // Diagnostic pin (D2)
|
2015-07-06 17:40:50 +00:00
|
|
|
//dds.clockTick();
|
2016-08-17 21:17:56 +00:00
|
|
|
afsk.timer();
|
2015-11-23 16:54:10 +00:00
|
|
|
//PORTD &= ~(_BV(2)); // Pin D2 off again
|
2015-07-06 17:40:50 +00:00
|
|
|
}
|