LeananKite
Member
I have a model car and I receive information from remote control by Serial1 (RX1) on Teensy 4.1.
When I first connect my Teensy with USB on Serial and turn on the battery everything works fine. I see my wheels moving accordingly.
When I just turn on my battery without USB, no wheel turns. That means, I receive no signal from Serial1. When I connect my USB after the battery, the wheels start turning.
Does the Serial USB somehow interfere with the Serial1? I tried Serial8 with the same results. What do I miss?
This is the short version of my code:
When I first connect my Teensy with USB on Serial and turn on the battery everything works fine. I see my wheels moving accordingly.
When I just turn on my battery without USB, no wheel turns. That means, I receive no signal from Serial1. When I connect my USB after the battery, the wheels start turning.
Does the Serial USB somehow interfere with the Serial1? I tried Serial8 with the same results. What do I miss?
This is the short version of my code:
Code:
#define HWSERIAL1 Serial1
unsigned long now;
#define USB_TIMEOUT 1000
byte c;
/****************************************************/
void setup()
{
now= millis();
Serial.begin(115200);
while (!Serial)
{
if (millis() > (now + USB_TIMEOUT))
break;
}
HWSERIAL1.begin(115200);
while (!HWSERIAL1)
{
if (millis() > (now + USB_TIMEOUT))
break;
}
if (HWSERIAL1) HWSERIAL1.addMemoryForRead(&bigserialbuffer, sizeof(bigserialbuffer));
}
void loop()
{
now = millis();
if (!Serial) Serial.begin(115200);
if (!HWSERIAL1)
{
HWSERIAL1.begin(115200);
if (HWSERIAL1) HWSERIAL1.addMemoryForRead(&bigserialbuffer, sizeof(bigserialbuffer));
}
if (HWSERIAL1.available() > 0)
c= HWSERIAL1.read();
}