Skip to content

Commit

Permalink
Added option for fast SBUS (200000 baud)
Browse files Browse the repository at this point in the history
  • Loading branch information
flybrianfly committed Sep 29, 2022
1 parent b457d85 commit 50b7fc9
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 20 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v8.1.0
- Added option for fast SBUS (200000 baud)

## v8.0.1
- Enabling ESP32 to use non-inverted SBUS

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (DEFINED MCU)
set(CMAKE_TOOLCHAIN_FILE "${mcu_support_SOURCE_DIR}/cmake/cortex.cmake")
# Project information
project(Sbus
VERSION 8.0.0
VERSION 8.1.0
DESCRIPTION "SBUS encoder and decoder"
LANGUAGES C CXX
)
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ The SBUS protocol uses an inverted serial logic with a baud rate of 100000, 8 da

Note that lost frame is indicated when a frame is lost between the transmitter and receiver. Failsafe activation typically requires that many frames are lost in a row and indicates that the receiver has moved into failsafe mode. Packets are sent approximately every 10 ms or 20 ms, depending on the system configuration.

A variation on SBUS called "Fast SBUS" has started to be used. This uses a baudrate of 200000 and a quicker update rate.

**Note on CH17 and CH18:** Channel 17 and channel 18 are digital on/off channels. These are not universally available on all SBUS receivers and servos.

FrSky receivers will output a range of 172 - 1811 with channels set to a range of -100% to +100%. Using extended limits of -150% to +150% outputs a range of 0 to 2047, which is the maximum range acheivable with 11 bits of data.
Expand Down Expand Up @@ -112,8 +114,12 @@ bfs::SbusRx sbus(&Serial1);
bfs::SbusRx sbus(&Serial1, false);
```

**SbusRx(HardwareSerial *bus, const bool inv, const bool fast)** Same as the constructor above, but enables selecting the fast SBUS baudrate (200000) if *fast* is true.

**(ESP32 ONLY) SbusRx(HardwareSerial *bus, const int8_t rxpin, const int8_t txpin, const bool inv)** Creates an *SbusRx* object. A pointer to the *Serial* object corresponding to the serial port used is passed along with the RX pin number (*rxpin*), TX pin number (*txpin*), and whether inverted serial is used (*inv*). If *inv* is true, the signal is the standard inverted SBUS, otherwise it is non-inverted SBUS.

**(ESP32 ONLY) SbusRx(HardwareSerial *bus, const int8_t rxpin, const int8_t txpin, const bool inv, const bool fast)** Same as the constructor above, but enables selecting the fast SBUS baudrate (200000) if *fast* is true.

**void Begin()** Initializes SBUS communication.

```C++
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Bolder Flight Systems SBUS
version=8.0.1
version=8.1.0
author=Brian Taylor <[email protected]>
maintainer=Brian Taylor <[email protected]>
sentence=Library for communicating with SBUS receivers and servos.
Expand Down
42 changes: 26 additions & 16 deletions src/sbus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@
namespace bfs {

void SbusRx::Begin() {
if (fast_) {
baud_ = 200000;
} else {
baud_ = 100000;
}
/* Start the bus */
/* Teensy 3.0 || Teensy 3.1/3.2 */
#if defined(__MK20DX128__) || defined(__MK20DX256__)
if (inv_) {
uart_->begin(BAUD_, SERIAL_8E1_RXINV_TXINV);
uart_->begin(baud_, SERIAL_8E1_RXINV_TXINV);
} else {
uart_->begin(BAUD_, SERIAL_8E1);
uart_->begin(baud_, SERIAL_8E1);
}
/*
* Teensy 3.5 || Teensy 3.6 ||
Expand All @@ -52,24 +57,24 @@ void SbusRx::Begin() {
defined(__MKL26Z64__) || defined(__IMXRT1062__) || \
defined(__IMXRT1052__)
if (inv_){
uart_->begin(BAUD_, SERIAL_8E2_RXINV_TXINV);
uart_->begin(baud_, SERIAL_8E2_RXINV_TXINV);
} else {
uart_->begin(BAUD_, SERIAL_8E2);
uart_->begin(baud_, SERIAL_8E2);
}
/* STM32L4 */
#elif defined(STM32L496xx) || defined(STM32L476xx) || \
defined(STM32L433xx) || defined(STM32L432xx)
if (inv_) {
uart_->begin(BAUD_, SERIAL_8E2 | 0xC000ul);
uart_->begin(baud_, SERIAL_8E2 | 0xC000ul);
} else {
uart_->begin(BAUD_, SERIAL_8E2);
uart_->begin(baud_, SERIAL_8E2);
}
/* ESP32 */
#elif defined(ESP32)
uart_->begin(BAUD_, SERIAL_8E2, rxpin_, txpin_, inv_);
uart_->begin(baud_, SERIAL_8E2, rxpin_, txpin_, inv_);
/* Everything else, with a hardware inverter */
#else
uart_->begin(BAUD_, SERIAL_8E2);
uart_->begin(baud_, SERIAL_8E2);
#endif
/* flush the bus */
uart_->flush();
Expand Down Expand Up @@ -174,13 +179,18 @@ namespace {
#endif

void SbusTx::Begin() {
if (fast_) {
baud_ = 200000;
} else {
baud_ = 100000;
}
/* Start the bus */
/* Teensy 3.0 || Teensy 3.1/3.2 */
#if defined(__MK20DX128__) || defined(__MK20DX256__)
if (inv_) {
uart_->begin(BAUD_, SERIAL_8E1_RXINV_TXINV);
uart_->begin(baud_, SERIAL_8E1_RXINV_TXINV);
} else {
uart_->begin(BAUD_, SERIAL_8E1);
uart_->begin(baud_, SERIAL_8E1);
}
/*
* Teensy 3.5 || Teensy 3.6 ||
Expand All @@ -191,24 +201,24 @@ void SbusTx::Begin() {
defined(__MKL26Z64__) || defined(__IMXRT1062__) || \
defined(__IMXRT1052__)
if (inv_){
uart_->begin(BAUD_, SERIAL_8E2_RXINV_TXINV);
uart_->begin(baud_, SERIAL_8E2_RXINV_TXINV);
} else {
uart_->begin(BAUD_, SERIAL_8E2);
uart_->begin(baud_, SERIAL_8E2);
}
/* STM32L4 */
#elif defined(STM32L496xx) || defined(STM32L476xx) || \
defined(STM32L433xx) || defined(STM32L432xx)
if (inv_) {
uart_->begin(BAUD_, SERIAL_8E2 | 0xC000ul);
uart_->begin(baud_, SERIAL_8E2 | 0xC000ul);
} else {
uart_->begin(BAUD_, SERIAL_8E2);
uart_->begin(baud_, SERIAL_8E2);
}
/* ESP32 */
#elif defined(ESP32)
uart_->begin(BAUD_, SERIAL_8E2, rxpin_, txpin_, inv_);
uart_->begin(baud_, SERIAL_8E2, rxpin_, txpin_, inv_);
/* Everything else, with a hardware inverter */
#else
uart_->begin(BAUD_, SERIAL_8E2);
uart_->begin(baud_, SERIAL_8E2);
#endif
}

Expand Down
20 changes: 18 additions & 2 deletions src/sbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ class SbusRx {
SbusRx(HardwareSerial *bus, const int8_t rxpin, const int8_t txpin,
const bool inv) : uart_(bus), inv_(inv), rxpin_(rxpin), txpin_(txpin)
{}
SbusRx(HardwareSerial *bus, const int8_t rxpin, const int8_t txpin,
const bool inv, const bool fast) : uart_(bus), inv_(inv),
rxpin_(rxpin), txpin_(txpin),
fast_(fast) {}
#else
explicit SbusRx(HardwareSerial *bus) : uart_(bus) {}
SbusRx(HardwareSerial *bus, const bool inv) : uart_(bus), inv_(inv) {}
SbusRx(HardwareSerial *bus, const bool inv, const bool fast) : uart_(bus),
inv_(inv),
fast_(fast) {}
#endif
void Begin();
bool Read();
Expand All @@ -62,10 +69,11 @@ class SbusRx {
/* Communication */
HardwareSerial *uart_;
bool inv_ = true;
bool fast_ = false;
#if defined(ESP32)
int8_t rxpin_, txpin_;
#endif
static constexpr uint32_t BAUD_ = 100000;
int32_t baud_ = 100000;
/* Message len */
static constexpr int8_t PAYLOAD_LEN_ = 23;
static constexpr int8_t HEADER_LEN_ = 1;
Expand Down Expand Up @@ -97,9 +105,16 @@ class SbusTx {
SbusTx(HardwareSerial *bus, const int8_t rxpin, const int8_t txpin,
const bool inv) : uart_(bus), inv_(inv), rxpin_(rxpin), txpin_(txpin)
{}
SbusTx(HardwareSerial *bus, const int8_t rxpin, const int8_t txpin,
const bool inv, const bool fast) : uart_(bus), inv_(inv),
rxpin_(rxpin), txpin_(txpin),
fast_(fast) {}
#else
explicit SbusTx(HardwareSerial *bus) : uart_(bus) {}
SbusTx(HardwareSerial *bus, const bool inv) : uart_(bus), inv_(inv) {}
SbusTx(HardwareSerial *bus, const bool inv, const bool fast) : uart_(bus),
inv_(inv),
fast_(fast) {}
#endif
void Begin();
void Write();
Expand All @@ -110,10 +125,11 @@ class SbusTx {
/* Communication */
HardwareSerial *uart_;
bool inv_ = true;
bool fast_ = false;
#if defined(ESP32)
int8_t rxpin_, txpin_;
#endif
static constexpr uint32_t BAUD_ = 100000;
int32_t baud_ = 100000;
/* Message len */
static constexpr int8_t BUF_LEN_ = 25;
/* SBUS message defs */
Expand Down

0 comments on commit 50b7fc9

Please sign in to comment.