diff --git a/examples/HandyTalkie/HandyTalkie.ino b/examples/HandyTalkie/HandyTalkie.ino index 4223c17..0186b1e 100644 --- a/examples/HandyTalkie/HandyTalkie.ino +++ b/examples/HandyTalkie/HandyTalkie.ino @@ -20,6 +20,8 @@ // create object for radio HamShield radio; +// To use non-standard pins, use the following initialization +//HamShield radio(ncs_pin, clk_pin, dat_pin); #define LED_PIN 13 #define RSSI_REPORT_RATE_MS 5000 @@ -50,9 +52,10 @@ void setup() { // initialize serial communication Serial.begin(9600); - Serial.println("press the switch to begin..."); + Serial.println("press the switch or send any character to begin..."); - while (digitalRead(SWITCH_PIN)); + while (digitalRead(SWITCH_PIN) && !Serial.available()); + Serial.read(); // flush // let the AU ot of reset digitalWrite(RESET_PIN, HIGH); diff --git a/src/HamShield.cpp b/src/HamShield.cpp index 34ed0a7..14459c8 100644 --- a/src/HamShield.cpp +++ b/src/HamShield.cpp @@ -120,40 +120,19 @@ const unsigned char AFSK_space[] PROGMEM = { 140, 228, 250, 166, 53, 0, 53, 166, volatile int ptt = false; volatile long bouncer = 0; -/** Default constructor, uses default I2C address. - * @see A1846S_DEFAULT_ADDRESS - */ -HamShield::HamShield() { - devAddr = A1; // devAddr is the chip select pin used by the HamShield - sHamShield = this; - - pinMode(devAddr, OUTPUT); - digitalWrite(devAddr, HIGH); - pinMode(CLK, OUTPUT); - digitalWrite(CLK, HIGH); - pinMode(DAT, OUTPUT); - digitalWrite(DAT, HIGH); -} - /** Specific address constructor. * @param chip select pin for HamShield * @see A1846S_DEFAULT_ADDRESS * @see A1846S_ADDRESS_AD0_LOW * @see A1846S_ADDRESS_AD0_HIGH */ -HamShield::HamShield(uint8_t cs_pin) { +HamShield::HamShield(uint8_t cs_pin = nSEN, uint8_t clk_pin = CLK, uint8_t dat_pin = DAT) { devAddr = cs_pin; - pinMode(devAddr, OUTPUT); - digitalWrite(devAddr, HIGH); - pinMode(CLK, OUTPUT); - digitalWrite(CLK, HIGH); - pinMode(DAT, OUTPUT); - digitalWrite(DAT, HIGH); + HSsetPins(cs_pin, clk_pin, dat_pin); } - /** Power on and prepare for general usage. * */ diff --git a/src/HamShield.h b/src/HamShield.h index 08ea810..b6f91f0 100644 --- a/src/HamShield.h +++ b/src/HamShield.h @@ -232,9 +232,8 @@ class HamShield { public: // public singleton for ISRs to reference static HamShield *sHamShield; // HamShield singleton, used for ISRs mostly - - HamShield(); - HamShield(uint8_t cs_pin); + + HamShield(uint8_t cs_pin = nSEN, uint8_t clk_pin = CLK, uint8_t dat_pin = DAT); void initialize(); // defaults to 12.5kHz void initialize(bool narrowBand); // select 12.5kHz if true or 25kHz if false diff --git a/src/HamShield_comms.cpp b/src/HamShield_comms.cpp index d3c173d..c803185 100644 --- a/src/HamShield_comms.cpp +++ b/src/HamShield_comms.cpp @@ -4,6 +4,26 @@ #include "HamShield_comms.h" + + +uint8_t ncs_pin = nSEN; +uint8_t clk_pin = CLK; +uint8_t dat_pin = DAT; + +void HSsetPins(uint8_t ncs, uint8_t clk, uint8_t dat) { + ncs_pin = ncs; + clk_pin = clk; + dat_pin = dat; + + pinMode(ncs_pin, OUTPUT); + digitalWrite(ncs_pin, HIGH); + pinMode(clk_pin, OUTPUT); + digitalWrite(clk_pin, HIGH); + pinMode(dat_pin, OUTPUT); + digitalWrite(dat_pin, HIGH); + +} + int8_t HSreadBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data) { uint16_t b; @@ -33,22 +53,22 @@ int8_t HSreadWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data) uint16_t temp_dat; // bitbang for great justice! *data = 0; - pinMode(DAT, OUTPUT); + pinMode(dat_pin, OUTPUT); regAddr = regAddr | (1 << 7); digitalWrite(devAddr, 0); //PORTC &= ~(1<<1); //devAddr used as chip select for (int i = 0; i < 8; i++) { temp = ((regAddr & (0x80 >> i)) != 0); - digitalWrite(CLK, 0); //PORTC &= ~(1<<5); // - digitalWrite(DAT, temp); - digitalWrite(CLK, 1); //PORTC |= (1<<5); // + digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); // + digitalWrite(dat_pin, temp); + digitalWrite(clk_pin, 1); //PORTC |= (1<<5); // } - // change direction of DAT - pinMode(DAT, INPUT); // DDRC &= ~(1<<4); // + // change direction of dat_pin + pinMode(dat_pin, INPUT); // DDRC &= ~(1<<4); // for (int i = 15; i >= 0; i--) { - digitalWrite(CLK, 0); //PORTC &= ~(1<<5); // - digitalWrite(CLK, 1); //PORTC |= (1<<5); // - temp_dat = digitalRead(DAT); //((PINC & (1<<4)) != 0); + digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); // + digitalWrite(clk_pin, 1); //PORTC |= (1<<5); // + temp_dat = digitalRead(dat_pin); //((PINC & (1<<4)) != 0); temp_dat = temp_dat << i; *data |= temp_dat; } @@ -91,21 +111,21 @@ bool HSwriteWord(uint8_t devAddr, uint8_t regAddr, uint16_t data) //digitalWrite(13, HIGH); // bitbang for great justice! - pinMode(DAT, OUTPUT); + pinMode(dat_pin, OUTPUT); regAddr = regAddr & ~(1 << 7); digitalWrite(devAddr, 0); // PORTC &= ~(1<<1); //CS for (int i = 0; i < 8; i++) { temp_reg = ((regAddr & (0x80 >> i)) != 0); - digitalWrite(CLK, 0); //PORTC &= ~(1<<5); // - digitalWrite(DAT, regAddr & (0x80 >> i)); - digitalWrite(CLK, 1); // PORTC |= (1<<5); // + digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); // + digitalWrite(dat_pin, regAddr & (0x80 >> i)); + digitalWrite(clk_pin, 1); // PORTC |= (1<<5); // } for (int i = 0; i < 16; i++) { temp_dat = ((data & (0x8000 >> i)) != 0); - digitalWrite(CLK, 0); //PORTC &= ~(1<<5); // - digitalWrite(DAT, temp_dat); - digitalWrite(CLK, 1); // PORTC |= (1<<5); // + digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); // + digitalWrite(dat_pin, temp_dat); + digitalWrite(clk_pin, 1); // PORTC |= (1<<5); // } digitalWrite(devAddr, 1); //PORTC |= (1<<1); //CS diff --git a/src/HamShield_comms.h b/src/HamShield_comms.h index 853153e..3132b7e 100644 --- a/src/HamShield_comms.h +++ b/src/HamShield_comms.h @@ -11,6 +11,8 @@ #define CLK A5 #define DAT A4 +void HSsetPins(uint8_t ncs, uint8_t clk, uint8_t dat); + int8_t HSreadBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data); int8_t HSreadBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data); int8_t HSreadWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data);