From b69ffed6d48276d7b86a35b1824b493d3d8955b9 Mon Sep 17 00:00:00 2001 From: Grinzzz <73146520+Grinzzz@users.noreply.github.com> Date: Thu, 27 Mar 2025 09:37:01 +1000 Subject: [PATCH] Fix start frame detection for fast refresh (1 mS between frames) When pause between frames less than frame length (e.g. 3 mS frame, 1 mS pause), connection is established in the middle of the frame, and start byte 0x0F is present in other part of frame (not only in start), a problem occured: frame's start shifting to the next (not first) position of byte 0x0F and frame will become invalid after 3500 uS. Current byte position and time from start of the frame check was added. --- src/main/rx/sbus.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/rx/sbus.c b/src/main/rx/sbus.c index 626c6586b4..1252bffede 100644 --- a/src/main/rx/sbus.c +++ b/src/main/rx/sbus.c @@ -70,6 +70,8 @@ #define SBUS_FRAME_BEGIN_BYTE 0x0F +#define SBUS_TIME_NEEDED_PER_BYTE SBUS_TIME_NEEDED_PER_FRAME / SBUS_FRAME_SIZE + #if !defined(SBUS_PORT_OPTIONS) #define SBUS_PORT_OPTIONS (SERIAL_STOPBITS_2 | SERIAL_PARITY_EVEN) #endif @@ -117,7 +119,7 @@ static void sbusDataReceive(uint16_t c, void *data) const timeDelta_t sbusFrameTime = cmpTimeUs(nowUs, sbusFrameData->startAtUs); - if (sbusFrameTime > (long)(SBUS_TIME_NEEDED_PER_FRAME + 500)) { + if (sbusFrameTime > (long)(SBUS_TIME_NEEDED_PER_FRAME + 500) || sbusFrameTime > (long)(sbusFrameData->position * SBUS_TIME_NEEDED_PER_BYTE + 240)) { sbusFrameData->position = 0; }