/* Started Transceiver Program over after making some serial
- mistakes.
- Need to be more careful with external memory.
- Need to better organize code. Started again on 7/25/12
- Decided to use SDR-Radio on my PC and now I'll only
- need to program for the communication link between the
- Ardudino Mega_AD9954_SDR-Radio on PC
- FREQ MUST BE 11 BYTES?
- NEED TO DETERMINE WHICH VFO IS CURRENT
- FIGURE OUT HOW TO CONNECT !!
*/
// include the library code:
#include <EEPROM.h>
#include <SoftwareSerial.h>
/* Global Constants */
const int FA(), FB(), FAS(), FBS(), FC(), FR0(); //VFO commands
const int IF(), IF1(), IF0(); // Transmit
const int SMO(), MD(), PS(), GT(), SH(), SL(); //
const int AG(), MU(), VS(); //
String NA("Ron's Homebrew SDR"); //name of radio
#define CLK 1.0e8 //clock frequency of AD9854
#define TUW 2.81e14 //tuning word mulitplier = 2_48
// Global Variables
long tuneWord(0);
long byte6(0);
char byte5(0), byte4(0), byte3(0), byte2(0), byte1(0), byte0(0);
float freq(0);
long buffer1(0);
char inByte(0), outByte(0);
float total;
// Construct LED Pin
const int ledPin(13);
/* Serial to PC */
#define pcrxPin 0
#define pctxPin 1
/* Serial to AD9954 VFO A*/
#define ArxPin 51
#define AtxPin 50
#define AClock 52
#define AresetDDS 53
/* Serial to AD9954 VFO B*/
#define BrxPin 19
#define BtxPin 18
#define BClock 21
#define BresetDDS 20
SoftwareSerial mySerialA(ArxPin, AtxPin); // RX, TX
SoftwareSerial mySerialB(BrxPin, BtxPin); // RX, TX
//Eeprom Reader
// start reading from the first byte (address 0) of the EEPROM
int address = 0;
volatile byte value;
// End of Eeprom Reader
void setup() {
pinMode(ArxPin, INPUT);
pinMode(AtxPin, OUTPUT);
pinMode(AClock, OUTPUT);
pinMode(AresetDDS, OUTPUT);
pinMode(pcrxPin, INPUT);
pinMode(pctxPin, OUTPUT);
pinMode(BrxPin, INPUT);
pinMode(BtxPin, OUTPUT);
pinMode(BClock, OUTPUT);
pinMode(BresetDDS, OUTPUT);
//set data rate to computer
Serial.begin(57600);
establishContact();
//set data rate for AD9954 VFO A
mySerialA.begin(57600);
mySerialA.print(AresetDDS, '0');
//set data rate for AD9954 VFO B
mySerialB.begin(57600);
mySerialB.print(BresetDDS, '0');
}
/* Eeprom Read Setup Routine /
void eepromReadsetup()
{
}
/ End of Eeprom Read Setup Routine */
void loop()
{
if (Serial.available()>0)
{
inByte = Serial.read();
}
/* FA; Frequency query command AD9954 sends frequecy to PC /
if (inByte=='FA') //FA, What is frequency VFO A?
{
mySerialA.write(2); //write to Register 2 AD9854
}
inByte = mySerialA.read(); //returns byte 5 tuning word VFO A
byte5 = inByte;
inByte = mySerialA.read(); //byte 4
byte4 = inByte;
inByte = mySerialA.read(); //byte 3
byte3 = inByte;
inByte = mySerialA.read(); //byte 2
byte2 = inByte;
inByte = mySerialA.read(); //byte 1
byte1 = inByte;
inByte = mySerialA.read(); // byte 0
byte0 = inByte;
total = float('byte5','byte4','byte3','byte2','byte1','byte0');
convTuningWord(total);
Serial.write(freq); //write freq FA to pc 11 BYTES
mySerialA.print(AresetDDS, '0');
/ End of FA: Frequency query command and response VFO A */
/* Set Frequency FAS for VFO A /
if (inByte=='FAS')
{
// write FAS to AD9954
mySerialA.write(130); //write to Register 2 VFO A
}
Serial.read(buffer1);
freqConv(float(buffer1));
mySerialA.write(tuneWord);
mySerialA.print(BresetDDS, '0');
/ End of FAS write frequency to VFO A */
}
/* Establish contact subroutine /
int establishContact() {
while ((Serial.available() <= 0) {
Serial.print('65'); // send a 65
delay(300);
if Serial.read = '65' {
Serial.print('66')
return;
}
}
/ End of Establish Contact Routine */
/* Eeprom Read Loop */
void eepromReadloop()
{
}
/* End of Eeprom Read Loop */
/* Tuning Word Calculation from Frequency provided /
float freqConv()
{
tuneWord = ((freqTUW)/CLK) //converts freq
// to tuning word
}
return(tuneWord);
/* End of Tuning Word Routine */
/* Frequency Calculation from Tuning Word provided by AD9854 /
float convTuningWord()
{
freq = ((CLKtuneWord)/TUW); //converts tuning
//word to frequency
}
return(freq);
/* End of Frequency Calculation Routine */
/* EOF */