diff --git a/HamShield.cpp b/HamShield.cpp index d0438ed..5ab2b1f 100644 --- a/HamShield.cpp +++ b/HamShield.cpp @@ -136,11 +136,7 @@ HamShield::HamShield(uint8_t address) { /** Power on and prepare for general usage. * */ -void HamShield::initialize() { - // set up PWM output for RF power control - commenting out to get rid of terrible buzzing noise - // pwr_control_pin = 9; - - +void HamShield::initialize() { // Note: these initial settings are for UHF 12.5kHz channel // see the A1846S register table and initial settings for more info @@ -156,6 +152,11 @@ void HamShield::initialize() { tx_data = 0x03AC; // default is 0x32C I2Cdev::writeWord(devAddr, 0x09, tx_data); + // AGC problem improve settings? + tx_data = 0x43A0; + I2Cdev::writeWord(devAddr, 0x0A, tx_data); + tx_data = 0xA100; + I2Cdev::writeWord(devAddr, 0x13, tx_data); tx_data = 0x0031; I2Cdev::writeWord(devAddr, 0x31, tx_data); // included as per AU supplied register table @@ -167,15 +168,15 @@ void HamShield::initialize() { I2Cdev::writeWord(devAddr, 0x34, tx_data); // Rx digital gain - included as per AU supplied register table // bits 6:0 are for digital voice gain - tx_data = 0x470F; + tx_data = 0x060f; //0x470F; I2Cdev::writeWord(devAddr, 0x41, tx_data); // bits 11:8 are for voice digital gain after tx ADC downsample // bits 7:0 are for rx volume control - tx_data = 0x0DFF; + tx_data = 0x0AFF; I2Cdev::writeWord(devAddr, 0x44, tx_data); // addx was A1846S_RX_VOLUME_REG - tx_data = 0x7FFF; + tx_data = 0x7F2F; I2Cdev::writeWord(devAddr, 0x47, tx_data);// soft mute tx_data = 0x2C62; @@ -193,13 +194,13 @@ void HamShield::initialize() { tx_data = 0x1C00; I2Cdev::writeWord(devAddr, 0x57, tx_data);// bypass rssi lpfilter - tx_data = 0x0EDB; + tx_data = 0x0EDD; I2Cdev::writeWord(devAddr, 0x5A, tx_data);// SQ detection time tx_data = 0x101E; I2Cdev::writeWord(devAddr, 0x60, tx_data);// SQ noise threshold - tx_data = 0x16AD; + tx_data = 0x3FFF; I2Cdev::writeWord(devAddr, 0x63, tx_data);// pre-emphasis bypass threshold // calibration @@ -214,22 +215,28 @@ void HamShield::initialize() { delay(10); // continue default setup in 12.5kHz mode + tx_data = 0x3D37; + I2Cdev::writeWord(devAddr, 0x11, tx_data); // tuning bit + + tx_data = 0x0100; + I2Cdev::writeWord(devAddr, 0x12, tx_data); // tuning bit + tx_data = 0x1100; I2Cdev::writeWord(devAddr, 0x15, tx_data); // tuning bit - tx_data = 0x1495; // 4495 + tx_data = 0x4495; // 4495 I2Cdev::writeWord(devAddr, 0x32, tx_data); // agc target power tx_data = 0x40C3; I2Cdev::writeWord(devAddr, 0x3A, tx_data); // modu_det_sel sq setting - tx_data = 0x0F1E; + tx_data = 0x0407; I2Cdev::writeWord(devAddr, 0x3C, tx_data); // pk_det_thr sq setting tx_data = 0x28D0; I2Cdev::writeWord(devAddr, 0x3F, tx_data); // pk_det_thr sq setting - tx_data = 0x20BE; + tx_data = 0x203E; I2Cdev::writeWord(devAddr, 0x48, tx_data); // pk_det_thr sq setting tx_data = 0x0A50; @@ -241,7 +248,7 @@ void HamShield::initialize() { tx_data = 0x2494; I2Cdev::writeWord(devAddr, 0x65, tx_data); // setting th_sif for SQ rssi detect - tx_data = 0x2494; + tx_data = 0xEB2E;//0x2494; I2Cdev::writeWord(devAddr, 0x66, tx_data); // setting th_sif for SQ rssi detect // AGC gain table settings @@ -250,28 +257,40 @@ void HamShield::initialize() { tx_data = 0x0001; I2Cdev::writeWord(devAddr, 0x7F, tx_data); - tx_data = 0x0014; - I2Cdev::writeWord(devAddr, 0x06, tx_data); + tx_data = 0x000C; + I2Cdev::writeWord(devAddr, 0x05, tx_data); tx_data = 0x020C; - I2Cdev::writeWord(devAddr, 0x07, tx_data); - tx_data = 0x0214; - I2Cdev::writeWord(devAddr, 0x08, tx_data); + I2Cdev::writeWord(devAddr, 0x06, tx_data); tx_data = 0x030C; - I2Cdev::writeWord(devAddr, 0x09, tx_data); - tx_data = 0x0314; - I2Cdev::writeWord(devAddr, 0x0A, tx_data); + I2Cdev::writeWord(devAddr, 0x07, tx_data); tx_data = 0x0324; - I2Cdev::writeWord(devAddr, 0x0B, tx_data); - tx_data = 0x0344; - I2Cdev::writeWord(devAddr, 0x0C, tx_data); + I2Cdev::writeWord(devAddr, 0x08, tx_data); tx_data = 0x1344; + I2Cdev::writeWord(devAddr, 0x09, tx_data); + tx_data = 0x3F44;// + I2Cdev::writeWord(devAddr, 0x0A, tx_data); + tx_data = 0x3F44; + I2Cdev::writeWord(devAddr, 0x0B, tx_data); + tx_data = 0x3F44; + I2Cdev::writeWord(devAddr, 0x0C, tx_data); + tx_data = 0x3F44; I2Cdev::writeWord(devAddr, 0x0D, tx_data); - tx_data = 0x1B44; + tx_data = 0x3F44; I2Cdev::writeWord(devAddr, 0x0E, tx_data); tx_data = 0x3F44; I2Cdev::writeWord(devAddr, 0x0F, tx_data); - tx_data = 0xE0EB; + tx_data = 0xE0ED; I2Cdev::writeWord(devAddr, 0x12, tx_data); + tx_data = 0xF2FE; + I2Cdev::writeWord(devAddr, 0x13, tx_data); + tx_data = 0x0A16; + I2Cdev::writeWord(devAddr, 0x14, tx_data); + tx_data = 0x2424; + I2Cdev::writeWord(devAddr, 0x15, tx_data); + tx_data = 0x2424; + I2Cdev::writeWord(devAddr, 0x16, tx_data); + tx_data = 0x2424; + I2Cdev::writeWord(devAddr, 0x17, tx_data); // done writing to upper page addresses, so set 0x7F back tx_data = 0x0000; @@ -339,32 +358,21 @@ void HamShield::setFrequency(uint32_t freq_khz) { radio_frequency = freq_khz; uint32_t freq_raw = freq_khz << 4; // shift by 4 to multiply by 16 (was shift by 3 in old 1846 chip) + // turn off tx/rx + I2Cdev::writeBitsW(devAddr, A1846S_CTL_REG, 6, 2, 0); + // if we're using a 12MHz crystal and the frequency is // 136.5M,409.5M and 455M, then we have to do special stuff if (radio_frequency == 136500 || radio_frequency == 490500 || radio_frequency == 455000) { - // close TX or RX - I2Cdev::readWord(devAddr, 0x00, radio_i2c_buf); - I2Cdev::writeWord(devAddr, 0x30, 0x06); - // set up AU1846 for funky freq I2Cdev::writeWord(devAddr, 0x05, 0x86D3); - // open TX or RX - I2Cdev::writeWord(devAddr, 0x30, radio_i2c_buf[0]); } else { - // just undo it regardless of what the last frequency was - // close TX or RX - I2Cdev::readWord(devAddr, 0x00, radio_i2c_buf); - I2Cdev::writeWord(devAddr, 0x30, 0x06); - // set up AU1846 for normal freq I2Cdev::writeWord(devAddr, 0x05, 0x8763); - - // open TX or RX - I2Cdev::writeWord(devAddr, 0x30, radio_i2c_buf[0]); } // send top 16 bits to A1846S_FREQ_HI_REG @@ -373,54 +381,35 @@ void HamShield::setFrequency(uint32_t freq_khz) { // send bottom 16 bits to A1846S_FREQ_LO_REG freq_half = (uint16_t) (freq_raw & 0xFFFF); I2Cdev::writeWord(devAddr, A1846S_FREQ_LO_REG, freq_half); + + if (rx_active) { + setRX(true); + } else if (tx_active) { + setTX(true); + } } uint32_t HamShield::getFrequency() { return radio_frequency; } -void HamShield::setUHF() { - setGpioHi(2); // turn off VHF - setGpioLow(3); // turn on UHF +void HamShield::setTxBand2m() { + setGpioLow(4); // V1 + setGpioHi(5); // V2 } -void HamShield::setVHF() { - setGpioHi(3); // turn off UHF - setGpioLow(2); // turn on VHF +void HamShield::setTxBand1_2m() { + setGpioHi(4); // V1 + setGpioLow(5); // V2 } -void HamShield::setNoFilters() { - setGpioHi(3); // turn off UHF - setGpioHi(2); // turn off VHF +void HamShield::setTxBand70cm() { + setGpioHi(4); // V1 + setGpioHi(5); // V2 } -/* -// band -// 00 - 400-520MHz -// 10 - 200-260MHz -// 11 - 134-174MHz -// TODO: add write to 0x32 based on band selection -void HamShield::setBand(uint16_t band){ - if (band == 0) { - setUHF(); - } else if (band == 2) { - // not quite in the band for our filters, but use VHF - setVHF(); - } else if (band == 3) { - setVHF(); - } else { - // illegal write code, turn UHF and VHF channels both off - setNoFilters(); - // turn off transmit as well to make sure we don't break anything - setTX(0); - } - I2Cdev::writeBitsW(devAddr, A1846S_BAND_SEL_REG, A1846S_BAND_SEL_BIT, A1846S_BAND_SEL_LENGTH, band); -} -uint16_t HamShield::getBand(){ - I2Cdev::readBitsW(devAddr, A1846S_BAND_SEL_REG, A1846S_BAND_SEL_BIT, A1846S_BAND_SEL_LENGTH, radio_i2c_buf); - return radio_i2c_buf[0]; -} -*/ + + /* // xtal frequency (kHz) @@ -493,15 +482,30 @@ uint16_t HamShield::getChanMode(){ void HamShield::setTX(bool on_noff){ // make sure RX is off if (on_noff) { - setRX(false); - - // set RX output off - setGpioHi(4); // remember that RX and TX are active low - // set TX output on - setGpioLow(5); // remember that RX and TX are active low + tx_active = true; + rx_active = false; + setRX(false); + + if((radio_frequency >= 134000) && (radio_frequency <= 174000)) { + setTxBand2m(); + } + if((radio_frequency >= 200000) && (radio_frequency <= 260000)) { + setTxBand1_2m(); + } + if((radio_frequency >= 400000) && (radio_frequency <= 520000)) { + setTxBand70cm(); + } + + delay(500); } I2Cdev::writeBitW(devAddr, A1846S_CTL_REG, A1846S_TX_MODE_BIT, on_noff); + + /* + if (on_noff) { + delay(6000); + } + */ } bool HamShield::getTX(){ I2Cdev::readBitW(devAddr, A1846S_CTL_REG, A1846S_TX_MODE_BIT, radio_i2c_buf); @@ -509,15 +513,15 @@ bool HamShield::getTX(){ } void HamShield::setRX(bool on_noff){ - // make sure TX is off - if (on_noff) { - setTX(false); - - // set TX output off - setGpioHi(5); // remember that RX and TX are active low - // set RX output on - setGpioLow(4); // remember that RX and TX are active low - } + // make sure TX is off + if (on_noff) { + tx_active = false; + rx_active = true; + setTX(false); + + setGpioLow(4); // V1 + setGpioLow(5); // V2 + } I2Cdev::writeBitW(devAddr, A1846S_CTL_REG, A1846S_RX_MODE_BIT, on_noff); } @@ -529,25 +533,30 @@ bool HamShield::getRX(){ void HamShield::setModeTransmit(){ // check to see if we should allow them to do this if(restrictions == true) { - if((radio_frequency > 139999) & (radio_frequency < 148001)) { setRX(false); setTX(true); } - if((radio_frequency > 218999) & (radio_frequency < 225001)) { setRX(false); setTX(true); } - if((radio_frequency > 419999) & (radio_frequency < 450001)) { setRX(false); setTX(true); } + if((radio_frequency > 139999) & (radio_frequency < 148001)) { setRX(false); } + if((radio_frequency > 218999) & (radio_frequency < 225001)) { setRX(false); } + if((radio_frequency > 419999) & (radio_frequency < 450001)) { setRX(false); } } else { - // turn off rx, turn on tx - setRX(false); // break before make setTX(true); } } void HamShield::setModeReceive(){ // turn on rx, turn off tx - setTX(false); // break before make setRX(true); } void HamShield::setModeOff(){ - // turn off rx, turn off tx, set pwr_dwn bit - setTX(false); - setRX(false); -} + // turn off tx/rx + I2Cdev::writeBitsW(devAddr, A1846S_CTL_REG, 6, 2, 0); + + // turn off amplifiers + setGpioLow(4); // V1 + setGpioLow(5); // V2 + + tx_active = false; + rx_active = true; + + //TODO: set pwr_dwn bit +} // set tx source // 000 - Nothing @@ -983,6 +992,11 @@ uint16_t HamShield::getGpioMode(uint16_t gpio){ return radio_i2c_buf[0]; } +uint16_t HamShield::getGpios(){ + I2Cdev::readWord(devAddr, A1846S_GPIO_MODE_REG, radio_i2c_buf); + return radio_i2c_buf[0]; +} + // Int void HamShield::enableInterrupt(uint16_t interrupt){ I2Cdev::writeBitW(devAddr, A1846S_INT_MODE_REG, interrupt, 1); @@ -1053,34 +1067,41 @@ uint16_t HamShield::readDTMFCode(){ void HamShield::setRfPower(uint8_t pwr) { - int max_pwr = 15; - if (pwr > max_pwr) { - pwr = max_pwr; - } - - I2Cdev::writeBitsW(devAddr, A1846S_PABIAS_REG, A1846S_PADRV_BIT, A1846S_PADRV_LENGTH, pwr); + int max_pwr = 15; + if (pwr > max_pwr) { + pwr = max_pwr; + } + + // turn off tx/rx + I2Cdev::writeBitsW(devAddr, A1846S_CTL_REG, 6, 2, 0); + + I2Cdev::writeBitsW(devAddr, A1846S_PABIAS_REG, A1846S_PADRV_BIT, A1846S_PADRV_LENGTH, pwr); + + if (rx_active) { + setRX(true); + } else if (tx_active) { + setTX(true); + } } bool HamShield::frequency(uint32_t freq_khz) { + if((freq_khz >= 134000) && (freq_khz <= 174000)) { - setVHF(); - //setBand(3); // 0b11 is 134-174MHz + setTxBand2m(); setFrequency(freq_khz); return true; } if((freq_khz >= 200000) && (freq_khz <= 260000)) { - setVHF(); - //setBand(2); // 10 is 200-260MHz + setTxBand1_2m(); setFrequency(freq_khz); return true; } if((freq_khz >= 400000) && (freq_khz <= 520000)) { - setUHF(); - //setBand(00); // 00 is 400-520MHz + setTxBand70cm(); setFrequency(freq_khz); return true; } diff --git a/HamShield.h b/HamShield.h index b29178b..9b36e1d 100644 --- a/HamShield.h +++ b/HamShield.h @@ -18,8 +18,8 @@ #define HAMSHIELD_MORSE_DOT 100 // Morse code dot length (smaller is faster WPM) #define HAMSHIELD_MORSE_BUFFER_SIZE 80 // Char buffer size for morse code text -#define HAMSHIELD_AUX_BUTTON 5 // Pin assignment for AUX button -#define HAMSHIELD_PWM_PIN 11 // Pin assignment for PWM output +#define HAMSHIELD_AUX_BUTTON 2 // Pin assignment for AUX button +#define HAMSHIELD_PWM_PIN 3 // Pin assignment for PWM output #define HAMSHIELD_EMPTY_CHANNEL_RSSI -110 // Default threshold where channel is considered "clear" #define HAMSHIELD_AFSK_RX_FIFO_LEN 16 @@ -272,16 +272,10 @@ class HamShield { uint32_t getFrequency(); // band - // 00 - 400-520MHz - // 10 - 200-260MHz - // 11 - 134-174MHz - void setBand(uint16_t band); - uint16_t getBand(); - - void setUHF(); - void setVHF(); - void setNoFilters(); - bool frequency(uint32_t freq_khz); + void setTxBand2m(); + void setTxBand1_2m(); + void setTxBand70cm(); + bool frequency(uint32_t freq_khz); // xtal frequency (kHz) // 12-14MHz crystal: this reg is set to crystal freq_khz @@ -483,6 +477,7 @@ class HamShield { void setGpioLow(uint16_t gpio); void setGpioHi(uint16_t gpio); uint16_t getGpioMode(uint16_t gpio); + uint16_t getGpios(); // Int void enableInterrupt(uint16_t interrupt); @@ -551,7 +546,8 @@ class HamShield { private: uint8_t devAddr; uint16_t radio_i2c_buf[4]; - int pwr_control_pin; + bool tx_active; + bool rx_active; uint32_t radio_frequency; uint32_t FRS[]; uint32_t GMRS[]; diff --git a/KISS.h b/KISS.h index dd839e6..d89ecaf 100644 --- a/KISS.h +++ b/KISS.h @@ -20,11 +20,11 @@ public: TIFR1 = _BV(ICF1); // Clear the timer flag dds->clockTick(); if(++tcnt == (DDS_REFCLK_DEFAULT/9600)) { - PORTD |= _BV(2); // Diagnostic pin (D2) + //PORTD |= _BV(2); // Diagnostic pin (D2) radio->afsk.timer(); tcnt = 0; } - PORTD &= ~(_BV(2)); + //PORTD &= ~(_BV(2)); } private: Stream *io; diff --git a/examples/AFSK-PacketTester/AFSK-PacketTester.ino b/examples/AFSK-PacketTester/AFSK-PacketTester.ino index 0090620..7458e6a 100644 --- a/examples/AFSK-PacketTester/AFSK-PacketTester.ino +++ b/examples/AFSK-PacketTester/AFSK-PacketTester.ino @@ -11,6 +11,12 @@ #include #include +//TODO: move these into library +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + + HamShield radio; DDS dds; String messagebuff = ""; @@ -20,16 +26,27 @@ String textmessage = ""; int msgptr = 0; void setup() { + // 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 pwr to the radio + digitalWrite(RESET_PIN, HIGH); + Serial.begin(115200); Wire.begin(); - pinMode(2, OUTPUT); - pinMode(3, OUTPUT); + + radio.initialize(); radio.frequency(144390); - radio.setRfPower(15); + radio.setRfPower(8); dds.start(); radio.afsk.start(&dds); - pinMode(11, INPUT); // Bodge for now, as pin 3 is hotwired to pin 11 delay(100); Serial.println("HELLO"); } diff --git a/examples/AFSK-SerialMessenger/AFSK-SerialMessenger.ino b/examples/AFSK-SerialMessenger/AFSK-SerialMessenger.ino index 9329398..a9e9657 100644 --- a/examples/AFSK-SerialMessenger/AFSK-SerialMessenger.ino +++ b/examples/AFSK-SerialMessenger/AFSK-SerialMessenger.ino @@ -11,6 +11,10 @@ #include #include +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + HamShield radio; DDS dds; String messagebuff = ""; @@ -20,16 +24,25 @@ String textmessage = ""; int msgptr = 0; void setup() { + // 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 the radio + digitalWrite(RESET_PIN, HIGH); + Serial.begin(115200); Wire.begin(); - pinMode(2, OUTPUT); - pinMode(3, OUTPUT); radio.initialize(); radio.frequency(145570); radio.setRfPower(15); dds.start(); radio.afsk.start(&dds); - pinMode(11, INPUT); // Bodge for now, as pin 3 is hotwired to pin 11 delay(100); Serial.println("HELLO"); } @@ -75,7 +88,7 @@ void prepMessage() { if(radio.afsk.txReady()) { Serial.println(F("txReady")); - radio.setModeTransmit(); + //radio.setModeTransmit(); //delay(100); if(radio.afsk.txStart()) { Serial.println(F("txStart")); @@ -97,14 +110,15 @@ void prepMessage() { radio.setModeReceive(); } - + +// TODO: d2 is now our switch, so don't write to that ISR(TIMER2_OVF_vect) { TIFR2 = _BV(TOV2); static uint8_t tcnt = 0; if(++tcnt == 8) { - digitalWrite(2, HIGH); + //digitalWrite(2, HIGH); dds.clockTick(); - digitalWrite(2, LOW); + //digitalWrite(2, LOW); tcnt = 0; } } @@ -112,7 +126,7 @@ ISR(TIMER2_OVF_vect) { ISR(ADC_vect) { static uint8_t tcnt = 0; TIFR1 = _BV(ICF1); // Clear the timer flag - PORTD |= _BV(2); // Diagnostic pin (D2) + //PORTD |= _BV(2); // Diagnostic pin (D2) dds.clockTick(); if(++tcnt == 1) { if(radio.afsk.encoder.isSending()) { @@ -120,7 +134,7 @@ ISR(ADC_vect) { } tcnt = 0; } - PORTD &= ~(_BV(2)); // Pin D2 off again + //PORTD &= ~(_BV(2)); // Pin D2 off again } diff --git a/examples/AFSKSend/AFSKSend.ino b/examples/AFSKSend/AFSKSend.ino index fbc9f99..1174ade 100644 --- a/examples/AFSKSend/AFSKSend.ino +++ b/examples/AFSKSend/AFSKSend.ino @@ -4,19 +4,33 @@ HamShield radio; DDS dds; +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + #define DON(p) PORTD |= _BV((p)) #define DOFF(p) PORTD &= ~(_BV((p))) void setup() { Serial.begin(9600); Wire.begin(); - pinMode(2, OUTPUT); - pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(7, OUTPUT); + // 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 pwr to the radio + digitalWrite(RESET_PIN, HIGH); + Serial.println(F("Radio test connection")); Serial.println(radio.testConnection(), DEC); Serial.println(F("Initialize")); @@ -24,14 +38,12 @@ void setup() { radio.initialize(); Serial.println(F("Frequency")); delay(100); - radio.setVHF(); radio.frequency(145010); //radio.setRfPower(0); delay(100); dds.start(); delay(100); radio.afsk.start(&dds); - pinMode(11, INPUT); // Bodge for now, as pin 3 is hotwired to pin 11 delay(100); dds.setFrequency(0); dds.on(); diff --git a/examples/AX25Receive/AX25Receive.ino b/examples/AX25Receive/AX25Receive.ino index cbc6671..b82f446 100644 --- a/examples/AX25Receive/AX25Receive.ino +++ b/examples/AX25Receive/AX25Receive.ino @@ -1,24 +1,35 @@ #include #include +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + HamShield radio; DDS dds; void setup() { + // 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); + Serial.begin(9600); Wire.begin(); - pinMode(2, OUTPUT); - pinMode(3, OUTPUT); Serial.println(F("Radio test connection")); Serial.println(radio.testConnection(), DEC); Serial.println(F("Initialize")); delay(100); radio.initialize(); radio.frequency(145010); - radio.setVHF(); radio.setSQOff(); - I2Cdev::writeWord(A1846S_DEV_ADDR_SENLOW, 0x30, 0x06); - I2Cdev::writeWord(A1846S_DEV_ADDR_SENLOW, 0x30, 0x26); I2Cdev::writeWord(A1846S_DEV_ADDR_SENLOW, 0x44, 0b11111111); Serial.println(F("Frequency")); delay(100); @@ -36,7 +47,6 @@ void setup() { delay(100); radio.afsk.start(&dds); Serial.println(F("Starting...")); - pinMode(11, INPUT); // Bodge for now, as pin 3 is hotwired to pin 11 delay(100); dds.setAmplitude(255); } @@ -57,11 +67,12 @@ void loop() { } } +//TODO: d2 is the switch input, so remove this ISR(ADC_vect) { static uint8_t tcnt = 0; TIFR1 = _BV(ICF1); // Clear the timer flag - PORTD |= _BV(2); // Diagnostic pin (D2) + //PORTD |= _BV(2); // Diagnostic pin (D2) //dds.clockTick(); radio.afsk.timer(); - PORTD &= ~(_BV(2)); // Pin D2 off again + //PORTD &= ~(_BV(2)); // Pin D2 off again } diff --git a/examples/CrystalCalibration/CrystalCalibration.ino b/examples/CrystalCalibration/CrystalCalibration.ino index 58c8b89..a6a6f8c 100644 --- a/examples/CrystalCalibration/CrystalCalibration.ino +++ b/examples/CrystalCalibration/CrystalCalibration.ino @@ -5,21 +5,32 @@ #include #include +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + HamShield radio; DDS dds; void setup() { + // 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); + Serial.begin(9600); Wire.begin(); radio.initialize(); - radio.setVHF(); radio.setRfPower(0); radio.setFrequency(145050); - pinMode(2, OUTPUT); - pinMode(3, OUTPUT); - pinMode(11, INPUT); - dds.start(); dds.setFrequency(1200); dds.on(); @@ -236,7 +247,7 @@ ISR(ADC_vect) { static uint8_t lastADC = 127; cli(); TIFR1 = _BV(ICF1); - PORTD |= _BV(2); + //PORTD |= _BV(2); dds.clockTick(); sei(); if(listening) { @@ -255,5 +266,5 @@ ISR(ADC_vect) { } lastADC = ADCH; } - PORTD &= ~_BV(2); + //PORTD &= ~_BV(2); } diff --git a/examples/DDS/DDS.ino b/examples/DDS/DDS.ino index 78ca76c..c995c8b 100644 --- a/examples/DDS/DDS.ino +++ b/examples/DDS/DDS.ino @@ -2,18 +2,31 @@ #include #include + +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + HamShield radio; DDS dds; void setup() { + // 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); + Wire.begin(); radio.initialize(); radio.setRfPower(0); - radio.setVHF(); radio.setFrequency(145060); - pinMode(2, OUTPUT); - pinMode(3, OUTPUT); - pinMode(11, INPUT); radio.setModeTransmit(); dds.start(); dds.playWait(600, 3000); @@ -37,10 +50,10 @@ ISR(ADC_vect) { static unsigned char tcnt = 0; TIFR1 = _BV(ICF1); // Clear the timer flag if(++tcnt == 4) { - digitalWrite(2, HIGH); + //digitalWrite(2, HIGH); tcnt = 0; } dds.clockTick(); - digitalWrite(2, LOW); + //digitalWrite(2, LOW); } #endif diff --git a/examples/FMBeacon/FMBeacon.ino b/examples/FMBeacon/FMBeacon.ino index 0b6d37b..3035ce0 100644 --- a/examples/FMBeacon/FMBeacon.ino +++ b/examples/FMBeacon/FMBeacon.ino @@ -9,11 +9,26 @@ Beacon will check to see if the channel is clear before it will transmit. #include #include +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + // Create a new instance of our HamSheild class, called 'radio' HamShield radio; // Run our start up things here void setup() { + // 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); + digitalWrite(RESET_PIN, HIGH); + // Set up the serial port at 9600 Baud Serial.begin(9600); @@ -30,10 +45,9 @@ void setup() { // Tell the HamShield to start up radio.initialize(); - radio.setRfPower(15); + radio.setRfPower(8); // Configure the HamShield to transmit and recieve on 446.000MHz radio.frequency(145570); - pinMode(11, INPUT); // Bodge for now, as pin 3 is hotwired to pin 11 Serial.println("Radio Configured."); } diff --git a/examples/FoxHunt/FoxHunt.ino b/examples/FoxHunt/FoxHunt.ino index d71aab8..70fb926 100755 --- a/examples/FoxHunt/FoxHunt.ino +++ b/examples/FoxHunt/FoxHunt.ino @@ -3,6 +3,10 @@ #include #include +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + // transmit for 1 minute, every 10 minutes #define TRANSMITLENGTH 1 @@ -11,7 +15,18 @@ HAMShield radio; -void setup() { +void setup() { + // 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); + digitalWrite(RESET_PIN, HIGH); + Wire.begin(); radio.initialize(); radio.setFrequency(145510); diff --git a/examples/FunctionalTest/FunctionalTest.ino b/examples/FunctionalTest/FunctionalTest.ino index 63e7ba8..c60b2f4 100644 --- a/examples/FunctionalTest/FunctionalTest.ino +++ b/examples/FunctionalTest/FunctionalTest.ino @@ -3,9 +3,24 @@ #include #include +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + HamShield radio; void setup() { + // 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); + digitalWrite(RESET_PIN, HIGH); + Wire.begin(); Serial.begin(9600); Serial.println("If the sketch freezes at radio status, there is something wrong with power or the shield"); diff --git a/examples/Gauges/Gauges.ino b/examples/Gauges/Gauges.ino index b18647d..4cfc97b 100755 --- a/examples/Gauges/Gauges.ino +++ b/examples/Gauges/Gauges.ino @@ -10,6 +10,10 @@ Simple gauges for the radio receiver. #include #include +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + HAMShield radio; void clr() { @@ -19,7 +23,18 @@ void clr() { Serial.print("[H"); // cursor to home command } -void setup() { +void setup() { + // 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); + digitalWrite(RESET_PIN, HIGH); + analogReference(DEFAULT); Serial.begin(115200); Wire.begin(); diff --git a/examples/HAMBot/HAMBot.ino b/examples/HAMBot/HAMBot.ino index 54d5bf5..3a13290 100755 --- a/examples/HAMBot/HAMBot.ino +++ b/examples/HAMBot/HAMBot.ino @@ -5,13 +5,28 @@ #include #include +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + HAMShield radio; -void setup() { +void setup() { + // 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); + digitalWrite(RESET_PIN, HIGH); + Robot.begin(); Wire.begin(); radio.initialize(); - radio.setFrequency(145510); + radio.frequency(145510); } void loop() { diff --git a/examples/Identifier/Identifier.ino b/examples/Identifier/Identifier.ino index 94f73c9..add371b 100755 --- a/examples/Identifier/Identifier.ino +++ b/examples/Identifier/Identifier.ino @@ -6,11 +6,16 @@ Arduino audio overlay example */ + #include #include #define DOT 100 +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + HAMShield radio; const char *bascii = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,?'!/()&:;=+-_\"$@", @@ -21,7 +26,18 @@ const char *callsign = {"1ZZ9ZZ/B"} ; char morsebuffer[8]; -void setup() { +void setup() { +// 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); + digitalWrite(RESET_PIN, HIGH); + Serial.begin(9600); Serial.println("starting up.."); Wire.begin(); @@ -29,7 +45,7 @@ void setup() { int result = radio.testConnection(); Serial.println(result,DEC); radio.initialize(); - radio.setFrequency(446000); + radio.frequency(446000); radio.setVolume1(0xF); radio.setVolume2(0xF); radio.setModeReceive(); diff --git a/examples/JustTransmit/JustTransmit.ino b/examples/JustTransmit/JustTransmit.ino index 4d31201..49b04d7 100644 --- a/examples/JustTransmit/JustTransmit.ino +++ b/examples/JustTransmit/JustTransmit.ino @@ -3,9 +3,24 @@ #include #include +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + HamShield radio; void setup() { + // 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); + digitalWrite(RESET_PIN, HIGH); + Wire.begin(); Serial.begin(9600); Serial.println("If the sketch freezes at radio status, there is something wrong with power or the shield"); diff --git a/examples/KISS/KISS.ino b/examples/KISS/KISS.ino index e308284..eb18a8c 100644 --- a/examples/KISS/KISS.ino +++ b/examples/KISS/KISS.ino @@ -6,20 +6,35 @@ HamShield radio; DDS dds; KISS kiss(&Serial, &radio, &dds); +//TODO: move these into library +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + void setup() { - pinMode(2, OUTPUT); - pinMode(3, OUTPUT); - pinMode(11, INPUT); + // 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); + digitalWrite(RESET_PIN, LOW); Serial.begin(9600); + + while (digitalRead(SWITCH_PIN)); + + // let the AU ot of reset + digitalWrite(RESET_PIN, HIGH); + Wire.begin(); radio.initialize(); - radio.setVHF(); radio.setSQOff(); - radio.setFrequency(145010); - I2Cdev::writeWord(A1846S_DEV_ADDR_SENLOW, 0x30, 0x06); - I2Cdev::writeWord(A1846S_DEV_ADDR_SENLOW, 0x30, 0x26); - I2Cdev::writeWord(A1846S_DEV_ADDR_SENLOW, 0x44, 0x05FF); + radio.setFrequency(144390); + //I2Cdev::writeWord(A1846S_DEV_ADDR_SENLOW, 0x44, 0x05FF); dds.start(); radio.afsk.start(&dds); diff --git a/examples/PSK31Transmit/PSK31Transmit.ino b/examples/PSK31Transmit/PSK31Transmit.ino index 13a3e0f..02bcad8 100644 --- a/examples/PSK31Transmit/PSK31Transmit.ino +++ b/examples/PSK31Transmit/PSK31Transmit.ino @@ -1,13 +1,25 @@ #include #include "varicode.h" +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + DDS dds; void setup() { + // 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); + digitalWrite(RESET_PIN, HIGH); + Serial.begin(9600); - pinMode(11, OUTPUT); - pinMode(3, OUTPUT); - pinMode(2, OUTPUT); // put your setup code here, to run once: dds.setReferenceClock(32000); dds.start(); @@ -65,7 +77,7 @@ ISR(ADC_vect) { if(tcnt > (255-81)) dds.setAmplitude(amplitudeShape[(tcnt-174)/2]); dds.clockTick(); - PORTD &= ~_BV(2); + //PORTD &= ~_BV(2); if(outer++ == 3) { outer = 0; } else { @@ -89,5 +101,5 @@ ISR(ADC_vect) { dds.changePhaseDeg(+180); } } - PORTD &= ~_BV(2); + //PORTD &= ~_BV(2); } diff --git a/examples/Parrot/Parrot.ino b/examples/Parrot/Parrot.ino index 18e1c91..d523171 100755 --- a/examples/Parrot/Parrot.ino +++ b/examples/Parrot/Parrot.ino @@ -9,6 +9,10 @@ A bit robotic and weird #include #include +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + #define RATE 500 #define SIZE 1500 @@ -21,6 +25,17 @@ int16_t rssi; byte mode = 8; void setup() { + // 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); + digitalWrite(RESET_PIN, HIGH); + Wire.begin(); // int result = radio.testConnection(); radio.initialize(); diff --git a/examples/QPSK63Transmit/QPSK63Transmit.ino b/examples/QPSK63Transmit/QPSK63Transmit.ino index e57c245..2b23909 100644 --- a/examples/QPSK63Transmit/QPSK63Transmit.ino +++ b/examples/QPSK63Transmit/QPSK63Transmit.ino @@ -1,13 +1,26 @@ #include #include "varicode.h" +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + DDS dds; void setup() { + // 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); + digitalWrite(RESET_PIN, LOW); + + Serial.begin(9600); - pinMode(11, OUTPUT); - pinMode(3, OUTPUT); - pinMode(2, OUTPUT); // put your setup code here, to run once: dds.setReferenceClock(32000); dds.start(); diff --git a/examples/SSTV/SSTV.ino b/examples/SSTV/SSTV.ino index e4787c0..6620947 100755 --- a/examples/SSTV/SSTV.ino +++ b/examples/SSTV/SSTV.ino @@ -4,6 +4,10 @@ Sends an SSTV test pattern */ +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + #define DOT 100 #define CALLSIGN "1ZZ9ZZ/B" @@ -17,14 +21,25 @@ int16_t rssi; /* get our radio ready */ -void setup() { +void setup() { + // 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); + digitalWrite(RESET_PIN, HIGH); + Wire.begin(); Serial.begin(9600); Serial.print("Radio status: "); int result = radio.testConnection(); Serial.println(result); radio.initialize(); - radio.setFrequency(446000); + radio.frequency(446000); radio.setModeReceive(); } diff --git a/examples/SSTV_M1_Static/SSTV_M1_Static.ino b/examples/SSTV_M1_Static/SSTV_M1_Static.ino index a86b757..fc5a53f 100644 --- a/examples/SSTV_M1_Static/SSTV_M1_Static.ino +++ b/examples/SSTV_M1_Static/SSTV_M1_Static.ino @@ -4,6 +4,10 @@ #include #include +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + HamShield radio; DDS dds; // Defined at the end of the sketch @@ -15,6 +19,17 @@ extern const uint16_t image[256*20] PROGMEM; ddsAccumulator_t freqTable[3]; void setup() { + // 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); + digitalWrite(RESET_PIN, HIGH); + Serial.begin(9600); Wire.begin(); // Query the HamShield for status information @@ -26,11 +41,7 @@ void setup() { // Tell the HamShield to start up radio.initialize(); radio.setRfPower(0); - radio.setVHF(); - radio.setFrequency(145500); - pinMode(2, OUTPUT); - pinMode(3, OUTPUT); - pinMode(11, INPUT); // HiZ + radio.frequency(145500); // put your setup code here, to run once: //dds.setReferenceClock(34965/4); dds.start(); diff --git a/examples/SerialTransceiver/SerialTransceiver.ino b/examples/SerialTransceiver/SerialTransceiver.ino index 400c20f..e55d92a 100644 --- a/examples/SerialTransceiver/SerialTransceiver.ino +++ b/examples/SerialTransceiver/SerialTransceiver.ino @@ -49,6 +49,10 @@ Debug Msg @; 32 character debug message #include "Wire.h" #include "HamShield.h" +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + int state; int txcount = 0; long timer = 0; @@ -68,6 +72,17 @@ HamShield radio; void setup() { + // 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); + digitalWrite(RESET_PIN, HIGH); + Serial.begin(115200); Serial.print(";;;;;;;;;;;;;;;;;;;;;;;;;;"); Wire.begin(); diff --git a/examples/SignalTest/SignalTest.ino b/examples/SignalTest/SignalTest.ino index 11bb298..12461a6 100755 --- a/examples/SignalTest/SignalTest.ino +++ b/examples/SignalTest/SignalTest.ino @@ -14,6 +14,10 @@ Plays back the current signal strength level and morses out it's call sign at th #include #include +#define PWM_PIN 3 +#define RESET_PIN A3 +#define SWITCH_PIN 2 + HAMShield radio; int16_t rssi; int peak = -150; @@ -73,14 +77,25 @@ const unsigned char dbm[] PROGMEM = { /* get our radio ready */ -void setup() { +void setup() { + // 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); + digitalWrite(RESET_PIN, HIGH); + Wire.begin(); Serial.begin(9600); Serial.print("Radio status: "); int result = radio.testConnection(); Serial.println(result); radio.initialize(); - radio.setFrequency(446000); + radio.frequency(446000); radio.setVolume1(0xF); radio.setVolume2(0xF); radio.setModeReceive(); @@ -104,7 +119,7 @@ void loop() { if(rssi < -120) { Serial.println("Transmit On"); - radio.setTX(1); + radio.setModeTransmit(); delay(250); tone(11,1000,500); delay(1000); @@ -131,9 +146,8 @@ void loop() { delay(1000); Serial.println("done!"); radio.morseOut(CALLSIGN); - radio.setTX(0); - Serial.println("Transmit off"); radio.setModeReceive(); + Serial.println("Transmit off"); delay(1000); } }