working DTMF

This commit is contained in:
Morgan Redfield 2018-06-24 17:12:04 -07:00
parent c340fef0b4
commit 24082d5a11
3 changed files with 36 additions and 46 deletions

View File

@ -1,20 +1,17 @@
/* Hamshield
* Example: HandyTalkie
* This is a simple example to demonstrate HamShield receive
* and transmit functionality.
* Example: DTMF
* This is a simple example to demonstrate how to ues DTMF.
*
* 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 Arduino, open the Serial Monitor. Press the button on
* the HamShield to begin setup. After setup is complete, type
* your desired Tx/Rx frequency, in hertz, into the bar at the
* top of the Serial Monitor and click the "Send" button.
* To test with another HandyTalkie (HT), key up on your HT
* and make sure you can hear it through the headphones
* attached to the HamShield. Key up on the HamShield by
* holding the button.
*/
* into the HamShield RF jack.
* Connect the Arduino to wall power and then to your computer
* via USB. After uploading this program to your Arduino, open
* the Serial Monitor. Press the button on the HamShield to
* begin setup. After setup is complete, type in a DTMF value
* (0-9, A, B, C, D, *, #) and hit enter. The corresponding
* DTMF tones will be transmitted. The sketch will also print
* any received DTMF tones to the screen.
**/
#include <HamShield.h>
@ -55,16 +52,13 @@ void setup() {
// verify connection
Serial.println("Testing device connections...");
Serial.println(radio.testConnection() ? "RDA radio connection successful" : "RDA radio connection failed");
Serial.println(radio.testConnection() ? "HamShield connection successful" : "HamShield connection failed");
// initialize device
Serial.println("Initializing I2C devices...");
radio.initialize(); // initializes automatically for UHF 12.5kHz channel
Serial.println("setting default Radio configuration");
radio.dangerMode();
// set frequency
Serial.println("setting squelch");
radio.setSQHiThresh(-10);
@ -76,20 +70,16 @@ void setup() {
radio.setSQOn();
//radio.setSQOff();
// set frequency
Serial.println("changing frequency");
freq = 415000;
freq = 420000;
radio.frequency(freq);
// set RX volume to minimum to reduce false positives on DTMF rx
radio.setVolume1(0);
radio.setVolume1(4);
radio.setVolume2(0);
// set to receive
radio.setModeReceive();
Serial.print("config register is: ");
Serial.println(radio.readCtlReg());
Serial.println(radio.readRSSI());
radio.setRfPower(0);
@ -97,7 +87,7 @@ void setup() {
pinMode(LED_PIN, OUTPUT);
// set up DTMF
radio.enableDTMFReceive(); // enabled DTMF
radio.enableDTMFReceive();
Serial.println("ready");
}
@ -117,8 +107,11 @@ void loop() {
} else {
Serial.println('?'); // invalid code
}
while (radio.getDTMFSample() == 1) {
// wait until this code is done
int j = 0;
while (j < 4) {
if (radio.getDTMFSample() == 0) {
j++;
}
delay(10);
}
}
@ -130,7 +123,7 @@ void loop() {
if (c == '#') {
code = 0xF;
} else if (c=='*') {
code == 0xE;
code = 0xE;
} else if (c >= 'A' && c <= 'D') {
code = c - 'A' + 0xA;
} else if (c >= '0' && c <= '9') {
@ -141,24 +134,22 @@ void loop() {
return;
}
// set tones
radio.setDTMFCode(code);
// start transmitting
radio.setDTMFCode(code); // set first
radio.setTxSourceTones();
radio.setModeTransmit();
// TODO: may need to set DTMF enable again
delay(300); // wait for TX to come to full power
// wait until done
// wait until ready
while (radio.getDTMFTxActive() != 1) {
// wait until we're ready for a new code
delay(10);
}
radio.setDTMFCode(code);
// TODO: fix timing
//while (radio.getDTMFTxActive() != 0) {
while (radio.getDTMFTxActive() != 0) {
// wait until this code is done
delay(1000);
//}
delay(10);
}
// done with tone
radio.setModeReceive();

View File

@ -983,7 +983,6 @@ void HamShield::enableDTMFReceive(){
tx_data = 0x1E3C;
HSwriteWord(devAddr, 0x79, tx_data);
HSwriteBitsW(devAddr, A1846S_DTMF_ENABLE_REG, 7, 8, 0x18);
HSwriteBitsW(devAddr, A1846S_DTMF_ENABLE_REG, A1846S_DTMF_ENABLE_BIT, 1, 1);
HSwriteBitsW(devAddr, A1846S_DTMF_ENABLE_REG, A18462_DTMF_DET_TIME_BIT, A18462_DTMF_DET_TIME_LEN, 24);
@ -991,13 +990,13 @@ void HamShield::enableDTMFReceive(){
// idle time
HSwriteBitsW(devAddr, A1846S_DTMF_TIME_REG, A1846S_DTMF_IDLE_TIME_BIT, A1846S_DTMF_IDLE_TIME_LEN, 50);
HSreadWord(devAddr, 0x6F, radio_i2c_buf);
Serial.println(radio_i2c_buf[0]);
// tx time
HSwriteBitsW(devAddr, A1846S_DTMF_TIME_REG, A1846S_DUALTONE_TX_TIME_BIT, A1846S_DUALTONE_TX_TIME_LEN, 50);
HSwriteBitsW(devAddr, A1846S_DTMF_TIME_REG, A1846S_DUALTONE_TX_TIME_BIT, A1846S_DUALTONE_TX_TIME_LEN, 60);
HSwriteBitsW(devAddr, 0x57, 0, 1, 1); // send dtmf to speaker out
//HSwriteBitsW(devAddr, 0x57, 0, 1, 1); // send dtmf to speaker out
// turn on pre/de-emphasis
HSwriteBitsW(devAddr, A1846S_EMPH_FILTER_REG, A1846S_EMPH_FILTER_EN, 1, 1);
}
@ -1038,7 +1037,7 @@ void HamShield::setDTMFCode(uint16_t code){
tone1 = 770*10;
} else if ((code >= 7 && code <= 9) || code == 0xC) {
tone1 = 852*10;
} else if (code >= 0xD) {
} else if (code >= 0xD || code == 0) {
tone1 = 941*10;
}

View File

@ -163,7 +163,7 @@
#define A1846S_SQ_OUT_SEL_BIT 7 // sq_out_sel
// Bitfields for A1846S_EMPH_FILTER_REG
#define A1846S_EMPH_FILTER_EN 3
#define A1846S_EMPH_FILTER_EN 7
// Bitfields for A1846S_FLAG_REG
#define A1846S_RXON_RF_FLAG_BIT 10 // 1 when rxon is enabled