arduino / arduino/ArduinoCore-samd

Serial1.available() returns wrong value

Open
#139 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
502
Forks
740
PR merge metrics
No merged PRs in 30d

Description

In a tight timing loop (without delays, such as Serial.print()), Serial1.available() returns a lower value than is correct.

For example Serial1.readBytes(buf, Serial1.available())); does not read the whole buffer.

If you use int a=Serial.readBytes(buf, SERIAL_BUFFER_SIZE); then a will report correctly how many bytes were read, this is a different value than Serial1.available(); - usually Serial1.available(); is one byte less.

This leads to the bytes in buf being truncated.

If there is a slight delay in the loop, the problem goes away, so it is hard to debug.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue with Serial1.available() in a tight timing loop, comparing its result with Serial1.readBytes(buf, Serial1.available()) and the reported read count from Serial.readBytes(buf, SERIAL_BUFFER_SIZE). Done means Serial1.available() reports the expected available byte count without requiring an incidental delay, and the full buffer is read.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.