Skip to content

Serial.available() only returns 0 or 1 when sending multiple single bytes to atmega32u4 #267

Open
@teliot

Description

@teliot

Serial.available() never returns anything other then 0 or 1 when sending single bytes to the software serial of a mega32u4.

test code

void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println(Serial.available());
delay(100);
}

i can reproduce this on the client by using putty to send individual bytes.

while(Serial.available() < 4) ;
will lockup the program.

while(Serial.available() < 4) {
if (serialEventRun)
serialEventRun();
}
will not lockup the program but gets stuck in an infinite loop with single bytes being sent in. if i use the built in serial monitor sending a string of multiple bytes will exit the loop.

Example:
Serial.available() == 0
send one byte
Serial.available() == 1
send one byte
Serial.available() == 1

Restart device
Serial.available() == 0
send 4 bytes in one packet
Serial.available() == 4
send 1 byte
Serial.available() == 4

this behavior is different then a hardware serial of an uno

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions