bolderflight / sbus

Arduino and CMake library for communicating with SBUS receivers and servos.
MIT License
373 stars 132 forks source link

Problems with Teensy 4.1 but not with Teensy 3.2 #59

Closed Embring closed 1 year ago

Embring commented 1 year ago

Hi! Thanks for this great lib! I have noticed that sbus_rx.Read() lags a lot in Teensy 4.1 but works great with Teensy 3.2. I am currently using a receiver with already inverted signal Oversky XR602T-A2 running at 3.3V. No problems at all with Teensy 3.2 as said. I'm wondering if the Teensy 4.1 expects an non-already reversed input? Can I define this Option for Teensy 4.1?

image

Embring commented 1 year ago

I guess I found a work around or error in the sbus.cpp file:

/ Start the bus / / Teensy 3.0 || Teensy 3.1/3.2 /

if defined(MK20DX128) || defined(MK20DX256)

uart_->begin(BAUD_, SERIAL_8E1_RXINV_TXINV);

/*

I changed the stop bit to 1 as in the / Teensy 3.0 || Teensy 3.1/3.2 / for
also Teensy 3.5 || Teensy 3.6 || Teensy LC || Teensy 4.0/4.1 | * Teensy 4.0 Beta Last line: uart->begin(BAUD, SERIAL_8E1_RXINV_TXINV);

And now its working!

flybrianfly commented 1 year ago

Also, please look at the newest version on GitHub, which supports Teensy 4.1. I'm not sure what's up with the Arduino Library manager, but it doesn't always grab the newest versions.

flybrianfly commented 1 year ago

EDIT: Nevermind, I see you changed the stop bit. Still early for me and I need coffee apparently. I'll look into it further, but haven't had issues with the Teensy 4.1 and SBUS and I fly that often; although, almost exclusively with FrSky receivers.

Embring commented 1 year ago

Great! Yes, it works very good now, when the stop bit is set to 1 like in Teensy 3.2 etc. I don't understand why there can be difference with the number of stop bits. But I notice the difference in the code. The Oversky XR602T-A2 only have one stop bit in a Oscilloscope. Attached the data for this receiver. XR600T series RX manual.pdf

flybrianfly commented 1 year ago

It's interesting, in the manual, the figures are pretty fuzzy, but it looks like the non-inverted SBUS has two stop bits whereas the inverted SBUS only has one. SBUS is supposed to be inverted with two stop bits. Teensy 3.0, 3.1, and 3.2 only support a single stop bit, which is fine for receiving and we use a workaround to use two stop bits when transmitting. I don't really want to switch to only using one stop bit, since who knows how that would affect servo compatibility. I'm chalking this up to an issue with the receiver firmware for now. I think a potential improvement for this library would be to make it easier to use non-inverted signals, either for microcontrollers that don't support inverted serial or to bypass some issues like this.