Updated AFSK/AX25 examples for modifications to AFSK library.

This commit is contained in:
Stephen Olesen 2015-07-13 19:01:32 -06:00
parent a22b814d63
commit ab7613c8d3
2 changed files with 31 additions and 79 deletions

View File

@ -1,16 +1,21 @@
#define DDS_REFCLK_DEFAULT 9600
#include <HamShield.h> #include <HamShield.h>
#include <Wire.h> #include <Wire.h>
HamShield radio; HamShield radio;
DDS dds; DDS dds;
#define DON(p) PORTD |= _BV((p))
#define DOFF(p) PORTD &= ~(_BV((p)))
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
Wire.begin(); Wire.begin();
pinMode(2, OUTPUT); pinMode(2, OUTPUT);
pinMode(3, OUTPUT); pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
Serial.println(F("Radio test connection")); Serial.println(F("Radio test connection"));
Serial.println(radio.testConnection(), DEC); Serial.println(radio.testConnection(), DEC);
@ -20,21 +25,24 @@ void setup() {
Serial.println(F("Frequency")); Serial.println(F("Frequency"));
delay(100); delay(100);
radio.setVHF(); radio.setVHF();
radio.frequency(145050); radio.frequency(145010);
radio.setRfPower(0); //radio.setRfPower(0);
Serial.println(F("DDS Start"));
delay(100); delay(100);
dds.start(); dds.start();
Serial.println(F("AFSK start"));
delay(100); delay(100);
radio.afsk.start(&dds); radio.afsk.start(&dds);
Serial.println(F("Starting..."));
pinMode(11, INPUT); // Bodge for now, as pin 3 is hotwired to pin 11 pinMode(11, INPUT); // Bodge for now, as pin 3 is hotwired to pin 11
delay(100); delay(100);
dds.setFrequency(0);
dds.on();
dds.setAmplitude(255);
I2Cdev::writeWord(A1846S_DEV_ADDR_SENLOW, 0x44, 0b0000011111111111);
//I2Cdev::writeWord(A1846S_DEV_ADDR_SENLOW, 0x53, 0x0);
//I2Cdev::writeWord(A1846S_DEV_ADDR_SENLOW, 0x32, 0xffff);
} }
void loop() { void loop() {
// put your main code here, to run repeatedly: DON(6);
AFSK::Packet *packet = AFSK::PacketBuffer::makePacket(22 + 32); AFSK::Packet *packet = AFSK::PacketBuffer::makePacket(22 + 32);
packet->start(); packet->start();
packet->appendCallsign("VE6SLP",0); packet->appendCallsign("VE6SLP",0);
@ -42,7 +50,8 @@ void loop() {
packet->appendFCS(0x03); packet->appendFCS(0x03);
packet->appendFCS(0xf0); packet->appendFCS(0xf0);
packet->print(F("Hello ")); packet->print(F("Hello "));
packet->println(millis()); packet->print(millis());
packet->println(F("\r\nThis is a test of the HamShield Kickstarter prototype. de VE6SLP"));
packet->finish(); packet->finish();
bool ret = radio.afsk.putTXPacket(packet); bool ret = radio.afsk.putTXPacket(packet);
@ -50,10 +59,10 @@ void loop() {
if(radio.afsk.txReady()) { if(radio.afsk.txReady()) {
Serial.println(F("txReady")); Serial.println(F("txReady"));
radio.setModeTransmit(); radio.setModeTransmit();
//delay(100);
if(radio.afsk.txStart()) { if(radio.afsk.txStart()) {
Serial.println(F("txStart")); Serial.println(F("txStart"));
} else { } else {
Serial.println(F("Tx Start failure"));
radio.setModeReceive(); radio.setModeReceive();
} }
} }
@ -61,37 +70,25 @@ void loop() {
Serial.println("tick"); Serial.println("tick");
// Wait up to 2.5 seconds to finish sending, and stop transmitter. // Wait up to 2.5 seconds to finish sending, and stop transmitter.
// TODO: This is hackery. // TODO: This is hackery.
DOFF(6);
for(int i = 0; i < 500; i++) { for(int i = 0; i < 500; i++) {
if(radio.afsk.encoder.isDone()) if(radio.afsk.encoder.isDone())
break; break;
delay(50); delay(50);
Serial.println("Not done");
} }
Serial.println("Done sending"); Serial.println("Done sending");
delay(100);
radio.setModeReceive(); radio.setModeReceive();
delay(30000); delay(2000);
} }
/*ISR(TIMER2_OVF_vect) {
TIFR2 = _BV(TOV2);
static uint8_t tcnt = 0;
if(++tcnt == 8) {
digitalWrite(2, HIGH);
dds.clockTick();
digitalWrite(2, LOW);
tcnt = 0;
}
}*/
ISR(ADC_vect) { ISR(ADC_vect) {
static uint8_t tcnt = 0;
TIFR1 = _BV(ICF1); // Clear the timer flag TIFR1 = _BV(ICF1); // Clear the timer flag
PORTD |= _BV(2); // Diagnostic pin (D2) DON(4);
dds.clockTick(); dds.clockTick();
if(++tcnt == 1) { DON(5);
if(radio.afsk.encoder.isSending()) {
radio.afsk.timer(); radio.afsk.timer();
} DOFF(5);
tcnt = 0; DOFF(4);
}
PORTD &= ~(_BV(2)); // Pin D2 off again
} }

View File

@ -1,31 +1,20 @@
#define DDS_REFCLK_DEFAULT 9600
#include <HamShield.h> #include <HamShield.h>
#include <Wire.h> #include <Wire.h>
//#include <LiquidCrystal_I2C.h>
//LiquidCrystal_I2C lcd(0x27,16,2);
HamShield radio; HamShield radio;
DDS dds; DDS dds;
volatile uint8_t adcMax=0, adcMin=255;
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
Wire.begin(); Wire.begin();
pinMode(2, OUTPUT); pinMode(2, OUTPUT);
pinMode(3, OUTPUT); pinMode(3, OUTPUT);
/*lcd.init();
lcd.setCursor(0,0);
lcd.print(F("RSSI:"));
lcd.setCursor(0,1);
lcd.print(F("ADC:"));*/
Serial.println(F("Radio test connection")); Serial.println(F("Radio test connection"));
Serial.println(radio.testConnection(), DEC); Serial.println(radio.testConnection(), DEC);
Serial.println(F("Initialize")); Serial.println(F("Initialize"));
delay(100); delay(100);
radio.initialize(); radio.initialize();
radio.frequency(144390); radio.frequency(145010);
radio.setVHF(); radio.setVHF();
radio.setSQOff(); radio.setSQOff();
I2Cdev::writeWord(A1846S_DEV_ADDR_SENLOW, 0x30, 0x06); I2Cdev::writeWord(A1846S_DEV_ADDR_SENLOW, 0x30, 0x06);
@ -50,7 +39,6 @@ void setup() {
pinMode(11, INPUT); // Bodge for now, as pin 3 is hotwired to pin 11 pinMode(11, INPUT); // Bodge for now, as pin 3 is hotwired to pin 11
delay(100); delay(100);
dds.setAmplitude(255); dds.setAmplitude(255);
//lcd.backlight();
} }
uint32_t last = 0; uint32_t last = 0;
@ -62,51 +50,18 @@ void loop() {
AFSK::Packet *packet = radio.afsk.getRXPacket(); AFSK::Packet *packet = radio.afsk.getRXPacket();
Serial.print(F("Packet: ")); Serial.print(F("Packet: "));
if(packet) { if(packet) {
packet->print(&Serial); packet->printPacket(&Serial);
AFSK::PacketBuffer::freePacket(packet); AFSK::PacketBuffer::freePacket(packet);
} }
} }
Serial.println("");
} }
/* if(last < millis()) {
uint16_t buf;
lcd.setCursor(6,0);
lcd.print(radio.readRSSI());
lcd.print(F(" "));
lcd.setCursor(6,1);
lcd.print(adcMax);
lcd.print(F(" / "));
lcd.print(adcMin);
lcd.print(F(" "));
lcd.setCursor(11,0);
lcd.print(radio.afsk.decoder.isReceiving());
adcMin=255; adcMax=0;
last = millis()+100;
}*/
} }
/*ISR(TIMER2_OVF_vect) {
TIFR2 = _BV(TOV2);
static uint8_t tcnt = 0;
if(++tcnt == 8) {
digitalWrite(2, HIGH);
dds.clockTick();
digitalWrite(2, LOW);
tcnt = 0;
}
}*/
ISR(ADC_vect) { ISR(ADC_vect) {
static uint8_t tcnt = 0; static uint8_t tcnt = 0;
TIFR1 = _BV(ICF1); // Clear the timer flag TIFR1 = _BV(ICF1); // Clear the timer flag
PORTD |= _BV(2); // Diagnostic pin (D2) PORTD |= _BV(2); // Diagnostic pin (D2)
//dds.clockTick(); //dds.clockTick();
radio.afsk.timer(); radio.afsk.timer();
if(ADCH>adcMax) {
adcMax = ADCH;
}
if(ADCH<adcMin) {
adcMin = ADCH;
}
PORTD &= ~(_BV(2)); // Pin D2 off again PORTD &= ~(_BV(2)); // Pin D2 off again
} }