Teensy 4.1 Serial1

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:

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(); 
}
 
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:

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();
}
I would use something like this.
Code:
#define HWSERIAL1                Serial1
unsigned long                         now;
#define                                   USB_TIMEOUT                  1000
byte                                        c;

/****************************************************/

void setup()
{
    now = millis();
    Serial.begin(115200);
    while (!Serial & millis() < 3500) {}

    HWSERIAL1.begin(115200);

    HWSERIAL1.addMemoryForRead(&bigserialbuffer, sizeof(bigserialbuffer));

}

void loop()
{
    if (HWSERIAL1.available() > 0)
        c = HWSERIAL1.read();
}
 
Not really, just simplified things. Just remember KISS. It makes things work and more easily maintained.
 
I think the problem is the Serial.begin in the setup() function.
This creates unexpected side effects.
I don't think so. The problem may be related to your bigserialbuffer. You don't show the variable definition in the code you posted. If you post a complete program that builds, runs, and shows the problem, we might be able to tell you what's wrong.
 
This my original code with the definition of the serialbuf:


Code:
#define HWSERIAL1                 Serial1
unsigned long                     now;
#define                           USB_TIMEOUT                  1000
byte                              c;
uint8_t                          bigserialbuffer[1023];

/****************************************************/
 
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(); 
}
 
Back
Top