allow non-standard digital control pins
This commit is contained in:
parent
6b05b7754d
commit
7427b426b1
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
// create object for radio
|
// create object for radio
|
||||||
HamShield 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 LED_PIN 13
|
||||||
#define RSSI_REPORT_RATE_MS 5000
|
#define RSSI_REPORT_RATE_MS 5000
|
||||||
|
@ -50,9 +52,10 @@ void setup() {
|
||||||
|
|
||||||
// initialize serial communication
|
// initialize serial communication
|
||||||
Serial.begin(9600);
|
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
|
// let the AU ot of reset
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
|
|
|
@ -120,40 +120,19 @@ const unsigned char AFSK_space[] PROGMEM = { 140, 228, 250, 166, 53, 0, 53, 166,
|
||||||
volatile int ptt = false;
|
volatile int ptt = false;
|
||||||
volatile long bouncer = 0;
|
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.
|
/** Specific address constructor.
|
||||||
* @param chip select pin for HamShield
|
* @param chip select pin for HamShield
|
||||||
* @see A1846S_DEFAULT_ADDRESS
|
* @see A1846S_DEFAULT_ADDRESS
|
||||||
* @see A1846S_ADDRESS_AD0_LOW
|
* @see A1846S_ADDRESS_AD0_LOW
|
||||||
* @see A1846S_ADDRESS_AD0_HIGH
|
* @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;
|
devAddr = cs_pin;
|
||||||
|
|
||||||
pinMode(devAddr, OUTPUT);
|
HSsetPins(cs_pin, clk_pin, dat_pin);
|
||||||
digitalWrite(devAddr, HIGH);
|
|
||||||
pinMode(CLK, OUTPUT);
|
|
||||||
digitalWrite(CLK, HIGH);
|
|
||||||
pinMode(DAT, OUTPUT);
|
|
||||||
digitalWrite(DAT, HIGH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Power on and prepare for general usage.
|
/** Power on and prepare for general usage.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -233,8 +233,7 @@ class HamShield {
|
||||||
// public singleton for ISRs to reference
|
// public singleton for ISRs to reference
|
||||||
static HamShield *sHamShield; // HamShield singleton, used for ISRs mostly
|
static HamShield *sHamShield; // HamShield singleton, used for ISRs mostly
|
||||||
|
|
||||||
HamShield();
|
HamShield(uint8_t cs_pin = nSEN, uint8_t clk_pin = CLK, uint8_t dat_pin = DAT);
|
||||||
HamShield(uint8_t cs_pin);
|
|
||||||
|
|
||||||
void initialize(); // defaults to 12.5kHz
|
void initialize(); // defaults to 12.5kHz
|
||||||
void initialize(bool narrowBand); // select 12.5kHz if true or 25kHz if false
|
void initialize(bool narrowBand); // select 12.5kHz if true or 25kHz if false
|
||||||
|
|
|
@ -4,6 +4,26 @@
|
||||||
|
|
||||||
#include "HamShield_comms.h"
|
#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)
|
int8_t HSreadBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data)
|
||||||
{
|
{
|
||||||
uint16_t b;
|
uint16_t b;
|
||||||
|
@ -33,22 +53,22 @@ int8_t HSreadWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data)
|
||||||
uint16_t temp_dat;
|
uint16_t temp_dat;
|
||||||
// bitbang for great justice!
|
// bitbang for great justice!
|
||||||
*data = 0;
|
*data = 0;
|
||||||
pinMode(DAT, OUTPUT);
|
pinMode(dat_pin, OUTPUT);
|
||||||
regAddr = regAddr | (1 << 7);
|
regAddr = regAddr | (1 << 7);
|
||||||
|
|
||||||
digitalWrite(devAddr, 0); //PORTC &= ~(1<<1); //devAddr used as chip select
|
digitalWrite(devAddr, 0); //PORTC &= ~(1<<1); //devAddr used as chip select
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
temp = ((regAddr & (0x80 >> i)) != 0);
|
temp = ((regAddr & (0x80 >> i)) != 0);
|
||||||
digitalWrite(CLK, 0); //PORTC &= ~(1<<5); //
|
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
|
||||||
digitalWrite(DAT, temp);
|
digitalWrite(dat_pin, temp);
|
||||||
digitalWrite(CLK, 1); //PORTC |= (1<<5); //
|
digitalWrite(clk_pin, 1); //PORTC |= (1<<5); //
|
||||||
}
|
}
|
||||||
// change direction of DAT
|
// change direction of dat_pin
|
||||||
pinMode(DAT, INPUT); // DDRC &= ~(1<<4); //
|
pinMode(dat_pin, INPUT); // DDRC &= ~(1<<4); //
|
||||||
for (int i = 15; i >= 0; i--) {
|
for (int i = 15; i >= 0; i--) {
|
||||||
digitalWrite(CLK, 0); //PORTC &= ~(1<<5); //
|
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
|
||||||
digitalWrite(CLK, 1); //PORTC |= (1<<5); //
|
digitalWrite(clk_pin, 1); //PORTC |= (1<<5); //
|
||||||
temp_dat = digitalRead(DAT); //((PINC & (1<<4)) != 0);
|
temp_dat = digitalRead(dat_pin); //((PINC & (1<<4)) != 0);
|
||||||
temp_dat = temp_dat << i;
|
temp_dat = temp_dat << i;
|
||||||
*data |= temp_dat;
|
*data |= temp_dat;
|
||||||
}
|
}
|
||||||
|
@ -91,21 +111,21 @@ bool HSwriteWord(uint8_t devAddr, uint8_t regAddr, uint16_t data)
|
||||||
//digitalWrite(13, HIGH);
|
//digitalWrite(13, HIGH);
|
||||||
|
|
||||||
// bitbang for great justice!
|
// bitbang for great justice!
|
||||||
pinMode(DAT, OUTPUT);
|
pinMode(dat_pin, OUTPUT);
|
||||||
regAddr = regAddr & ~(1 << 7);
|
regAddr = regAddr & ~(1 << 7);
|
||||||
|
|
||||||
digitalWrite(devAddr, 0); // PORTC &= ~(1<<1); //CS
|
digitalWrite(devAddr, 0); // PORTC &= ~(1<<1); //CS
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
temp_reg = ((regAddr & (0x80 >> i)) != 0);
|
temp_reg = ((regAddr & (0x80 >> i)) != 0);
|
||||||
digitalWrite(CLK, 0); //PORTC &= ~(1<<5); //
|
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
|
||||||
digitalWrite(DAT, regAddr & (0x80 >> i));
|
digitalWrite(dat_pin, regAddr & (0x80 >> i));
|
||||||
digitalWrite(CLK, 1); // PORTC |= (1<<5); //
|
digitalWrite(clk_pin, 1); // PORTC |= (1<<5); //
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
temp_dat = ((data & (0x8000 >> i)) != 0);
|
temp_dat = ((data & (0x8000 >> i)) != 0);
|
||||||
digitalWrite(CLK, 0); //PORTC &= ~(1<<5); //
|
digitalWrite(clk_pin, 0); //PORTC &= ~(1<<5); //
|
||||||
digitalWrite(DAT, temp_dat);
|
digitalWrite(dat_pin, temp_dat);
|
||||||
digitalWrite(CLK, 1); // PORTC |= (1<<5); //
|
digitalWrite(clk_pin, 1); // PORTC |= (1<<5); //
|
||||||
}
|
}
|
||||||
|
|
||||||
digitalWrite(devAddr, 1); //PORTC |= (1<<1); //CS
|
digitalWrite(devAddr, 1); //PORTC |= (1<<1); //CS
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#define CLK A5
|
#define CLK A5
|
||||||
#define DAT A4
|
#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 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 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);
|
int8_t HSreadWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data);
|
||||||
|
|
Loading…
Reference in New Issue