Hi
I am trying to create a trivial program for Teensy 4.0 that reads the SBUS output from two R/C receivers, and then routes one only of these to a single serial output, chosen according to the value on a PWM pin on the master receiver.
This is to support SBUS buddy boxing for training new model flyers. The very brief code is below. The part that reads a PWM value is working fine. The part that reads SBUS input seems to work too.
But so far it fails to produce any valid SBUS output, and I'm really hoping someone can tell me why!
(In this short bit of code I want only to read the SBUS input (on Serial1) and then simply output it (to Serial2). Once this much works, I can add another input port and the switch logic of course.)
volatile long int pulse_time;
byte incomingByte;
#define CHANNEL_7_PIN 2
volatile unsigned long timer_start;
volatile int last_interrupt_time;
void setup() {
timer_start = 0;
attachInterrupt(CHANNEL_7_PIN, ReadPWMvalue, CHANGE);
Serial.begin(115200);
Serial1.begin(100000);
Serial2.begin(100000);
}
void loop(){
while (Serial1.available()) {
incomingByte = Serial1.read();
Serial2.write(incomingByte);
}
}
void ReadPWMvalue(){ // Interrupt handler to read PWM value on pin
last_interrupt_time = micros();if(digitalRead(CHANNEL_7_PIN) == HIGH) {timer_start = micros();}else
{if(timer_start != 0){pulse_time = ((volatile int)micros()-timer_start);timer_start = 0;}}
}
I am trying to create a trivial program for Teensy 4.0 that reads the SBUS output from two R/C receivers, and then routes one only of these to a single serial output, chosen according to the value on a PWM pin on the master receiver.
This is to support SBUS buddy boxing for training new model flyers. The very brief code is below. The part that reads a PWM value is working fine. The part that reads SBUS input seems to work too.
But so far it fails to produce any valid SBUS output, and I'm really hoping someone can tell me why!
(In this short bit of code I want only to read the SBUS input (on Serial1) and then simply output it (to Serial2). Once this much works, I can add another input port and the switch logic of course.)
volatile long int pulse_time;
byte incomingByte;
#define CHANNEL_7_PIN 2
volatile unsigned long timer_start;
volatile int last_interrupt_time;
void setup() {
timer_start = 0;
attachInterrupt(CHANNEL_7_PIN, ReadPWMvalue, CHANGE);
Serial.begin(115200);
Serial1.begin(100000);
Serial2.begin(100000);
}
void loop(){
while (Serial1.available()) {
incomingByte = Serial1.read();
Serial2.write(incomingByte);
}
}
void ReadPWMvalue(){ // Interrupt handler to read PWM value on pin
last_interrupt_time = micros();if(digitalRead(CHANNEL_7_PIN) == HIGH) {timer_start = micros();}else
{if(timer_start != 0){pulse_time = ((volatile int)micros()-timer_start);timer_start = 0;}}
}