Teensy 3.2 Serial Initialization problem again

Status
Not open for further replies.

paynterf

Well-known member
I have a very simple program to test a FIFO class, as follows:

Code:
/*
    Name:       FIFO_Class_Test.ino
    Created:	12/28/2019 12:51:15 PM
    Author:     FRANKNEWXPS15\Frank
*/

#include "FIFO_Class.h"
FIFO myFIFO(64);

void setup()
{
    Serial.begin(115200);
    unsigned long now = millis();
    int idx = 0;
    while (!Serial && (millis() - now) < 3000)
    {
        delay(100);
        idx++;
    }

    //delay(3000);
    Serial.printf("Serial port available after %lu mSec with idx = %d\n", millis() - now, idx);
}

void loop()
{
}

but the Serial port won't initialize reliably. With the code as shown below, it only properly initialized 6 our of 8 trials, as shown in the following printout

HTML:
Opening port
Port failed to open
Port open
Serial port available after 1400 mSec with idx = 14
Port open
Serial port available after 1200 mSec with idx = 12
Port open
Serial port available after 2100 mSec with idx = 21
Port open
Port open
Serial port available after 700 mSec with idx = 7
Port open
Serial port available after 1600 mSec with idx = 16
Port open
Port open
Serial port available after 1500 mSec with idx = 15

The two failures are identified by the two instances of two 'Port open' lines back-to-back

What am I doing wrong here?

TIA,

Frank
 
If I change the delay value inside the while() loop from 100 to 500, then the loop will reliably terminate with idx = 3. However, for lower delay values, the reliability goes down, until with delay(10) it will always hang forever.
 
try with very long timeouts, say 30000.
most likely, your terminal program or PC may be unreliable with connecting to Serial.

Alternatively, does FIFO_Class uses Serial?
 
No, the FIFO class constructor does not use serial. Other member functions do use serial occasionally for debug, but only well after all of setup() has run.

Using a recent Win10 Dell XPS15 9750, and I don't have any problem with Arduino boards - just the Teensy.

Frank
 
Status
Not open for further replies.
Back
Top