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

View File

@ -983,7 +983,6 @@ void HamShield::enableDTMFReceive(){
tx_data = 0x1E3C; tx_data = 0x1E3C;
HSwriteWord(devAddr, 0x79, tx_data); 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, A1846S_DTMF_ENABLE_BIT, 1, 1);
HSwriteBitsW(devAddr, A1846S_DTMF_ENABLE_REG, A18462_DTMF_DET_TIME_BIT, A18462_DTMF_DET_TIME_LEN, 24); 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 // idle time
HSwriteBitsW(devAddr, A1846S_DTMF_TIME_REG, A1846S_DTMF_IDLE_TIME_BIT, A1846S_DTMF_IDLE_TIME_LEN, 50); 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 // 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; tone1 = 770*10;
} else if ((code >= 7 && code <= 9) || code == 0xC) { } else if ((code >= 7 && code <= 9) || code == 0xC) {
tone1 = 852*10; tone1 = 852*10;
} else if (code >= 0xD) { } else if (code >= 0xD || code == 0) {
tone1 = 941*10; tone1 = 941*10;
} }

View File

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