Skip to content

Instantly share code, notes, and snippets.

@skelly skelly/spektrum_sat_bind.pde Secret
Created Aug 19, 2011

Embed
What would you like to do?
Arduino sketch for binding with Spektrum RC satellite receivers.
// Spektrum satellite binding
// quick test sketch by Sam Kelly, sam@3drobotics.com
// with info from rcgroups, mikrokopter, etc.
unsigned long time;
int inData[16];
int inByte;
int index = 0;
void setup()
{
Serial.begin(115200); // to print data to the terminal
SpektrumBind(); // to interface with the Spektrum sat
Serial1.begin(115200);
}
void loop()
{
while(Serial1.available() > 0)
{
for(index = 0; index <= 15; index++)
{
inByte = Serial1.read();
inData[index] = inByte;
Serial.print(inByte);
Serial.print(" ");
}
Serial.println();
}
}
void SpektrumBind(void)
{
unsigned char connected = 0;
UCSR1B &= ~(1 << TXCIE1); // disable Tx interrupt
UCSR1B &= ~(1 << TXEN1); // disable USART1 Tx
PORTD &= ~(1 << PORTD3); // disable pull-up
DDRD |= (1 << DDD3); // Tx as output
PORTD |= (1 << PORTD3); // Set HIGH to enable adapter regulator
UCSR1B &= ~(1 << RXCIE1); // disable Rx interrupt
UCSR1B &= ~(1 << RXEN1); // disable USART1 Rx
PORTD &= ~(1 << PORTD2); // disable pull-up
Serial.println("Spektrum Satellite binding test.");
while(time <= 10000) // Wait 10 seconds for spektrum sat connection
{
time = millis();
if(PIND & (1 << PORTD2))
{
connected = 1;
break;
}
}
if(connected)
{
Serial.println("Connected! Bind now!");
DDRD |= (1 << DDD2); // Rx as output
delay(90); // Delay after Rx startup
// === Update 2011-08-18 ===
// Bind mode data gathered from Spektrum DX8
// 2 low pulses: DSM2 1024/22ms (this works with Doug Weibel's PPM Encoder firmware)
// 3 low pulses: no result
// 4 low pulses: DSM2 2048/11ms
// 5 low pulses: no result
// 6 low pulses: DSMX 22ms
// 7 low pulses: no result
// 8 low pulses: DSMX 11ms
//PORTD |= (1 << PORTD2); delayMicroseconds(116);
//PORTD &= ~(1 << PORTD2); delayMicroseconds(116);
//PORTD |= (1 << PORTD2); delayMicroseconds(116);
//PORTD &= ~(1 << PORTD2); delayMicroseconds(116);
//PORTD |= (1 << PORTD2); delayMicroseconds(116);
//PORTD &= ~(1 << PORTD2); delayMicroseconds(116);
//PORTD |= (1 << PORTD2); delayMicroseconds(116);
//PORTD &= ~(1 << PORTD2); delayMicroseconds(116);
//PORTD |= (1 << PORTD2); delayMicroseconds(116);
//PORTD &= ~(1 << PORTD2); delayMicroseconds(116);
PORTD |= (1 << PORTD2); delayMicroseconds(116);
PORTD &= ~(1 << PORTD2); delayMicroseconds(116);
PORTD |= (1 << PORTD2); delayMicroseconds(116);
PORTD &= ~(1 << PORTD2); delayMicroseconds(116);
PORTD |= (1 << PORTD2); delayMicroseconds(116);
}
else
Serial.println("Timeout.");
DDRD &= ~(1 << DDD2); // Rx as input
PORTD &= ~(1 << PORTD2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.