Skip to content

Instantly share code, notes, and snippets.

@ibanezmatt13
Last active August 29, 2015 13:59
Show Gist options
  • Save ibanezmatt13/10481097 to your computer and use it in GitHub Desktop.
Save ibanezmatt13/10481097 to your computer and use it in GitHub Desktop.
#define AUDIO_PIN 6 // GPIO pin on si446x
volatile char *ptr = NULL; // pointer to datastring buffer
volatile boolean sentence_needed = true;
char send_datastring[100] = "";
volatile char *ptr = NULL;
/* for using RTTY */
volatile int tx_status = 0;
char currentbyte;
int currentbitcount;
/* change DOMINOEX to RTTY if required */
#define DOMINOEX
#ifdef RTTY
ISR(TIMER1_COMPA_vect){
switch (tx_status){
case 0: // when the next byte needs to be gotten
if (ptr){
currentbyte = *ptr; // read first byte where pointer is pointing too
if (currentbyte){
tx_status = 1;
sentence_needed = false;
}
else {
sentence_needed = true;
break;
}
}
else {
sentence_needed = true;
break;
}
case 1: // first bit about to be sent
rtty_txbit(0); // send start bit
tx_status = 2;
currentbitcount = 1; // set bit count to 0 ready for incrementing to 7 for last bit of a ASCII-7 byte
break;
case 2: // normal status, transmitting bits of byte (including first and last)
rtty_txbit(currentbyte & 1); // send the currentb bit
if (currentbitcount == 7){ // if we've just transmitted the final bit of the byte
tx_status = 3;
}
currentbyte = currentbyte >> 1; // shift all bits in byte 1 to right so next bit is LSB
currentbitcount++;
break;
case 3: // if all bits have been transmitted and we need to send the first of two stop bits
rtty_txbit(1); // send first stop bit
tx_status = 4;
break;
case 4: // ready to send the last of two stop bits
rtty_txbit(1); // send the final stop bit
ptr++; // increment the pointer for reading next byte in buffer
tx_status = 0;
break;
}
}
void rtty_txbit (int bit)
{
if (bit)
{
digitalWrite(AUDIO_PIN, HIGH);
}
else
{
digitalWrite(AUDIO_PIN, LOW);
}
}
#endif
#ifdef DOMINOEX
ISR(TIMER1_COMPA_vect)
{
static uint8_t current_symbol = 0;
static uint8_t current_char = 0x00;
static uint8_t symbol_index = 0;
uint8_t next_symbol;
next_symbol = varicode[current_char][symbol_index++]; // get next symbol from varicode table
current_symbol = (current_symbol + next_symbol + 2) % 18; // update for next symbol transmission
setChannel(current_symbol); // set next tone for transmission on si446x
// if reached end of either 2 or 3 symbol character, set index to 3 for executing next code
if(symbol_index < 3 && !(varicode[current_char][symbol_index] & 0x08)) {
symbol_index = 3;
}
// if we still have more symbols to send
if(symbol_index != 3){
return;
}
symbol_index = 0; // reset symbol index for next character
if(sentence_needed == false && ptr){
current_char = *ptr;
ptr++;
if(current_char){
sentence_needed = false;
}
else{
sentence_needed = true;
}
}
else{
sentence_needed = true;
}
}
#endif
void initialise_interrupt()
{
// initialize Timer1
cli(); // disable global interrupts
TCCR1A = 0; // set entire TCCR1A register to 0
TCCR1B = 0; // same for TCCR1B
#ifdef RTTY
OCR1A = F_CPU / 1024 / RTTY_BAUD - 1;
#endif
#ifdef DOMINOEX
OCR1A = F_CPU / 16000 - 1; // DOMINOEX16 only
#endif
TCCR1B |= (1 << WGM12); // turn on CTC mode:
// Set CS10 and CS12 bits for:
TCCR1B |= (1 << CS10);
TCCR1B |= (1 << CS12);
// enable timer compare interrupt:
TIMSK1 |= (1 << OCIE1A);
sei(); // enable global interrupts
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment