analogdevicesinc / arduino-max326xx

Arduino core for Maxim's MAX326xx series boards
Other
0 stars 0 forks source link

Serial misses first two seconds of output #4

Closed technoblogy closed 5 years ago

technoblogy commented 5 years ago

The following simple test using the Arduino IDE Serial Monitor demonstrates this:

void setup() {
  Serial.begin(9600);
}

void loop() {
  for (int x=1; x<1000; x++) {
    Serial.println(x);
    delay(1000);
  }
}

It prints: 3, 4, etc.

I uploaded the program by exporting it with Export compiled Binary and pasted it onto the BOOTLOADER disk.

technoblogy commented 5 years ago

The same thing happens on the Adafruit ItsyBitsy M4; the solution on that platform is to add a while (!Serial); statement which waits for the serial to initialise:

void setup() {
  Serial.begin(9600);
  while (!Serial);
}

void loop() {
  for (int x=1; x<1000; x++) {
    Serial.println(x);
    delay(1000);
  }
}

Unfortunately this has no effect on the MAX32620FTHR.

khariya commented 5 years ago

Call Serial.availableForWrite() to get the number of bytes (characters) available for writing.

khariya commented 5 years ago

As an example:

void setup() {
  Serial.begin(9600);
  while(!Serial.availableForWrite());
}
technoblogy commented 5 years ago

I think you should still support while (!Serial) because this is what most people use. See:

https://www.arduino.cc/reference/en/language/functions/communication/serial/ifserial/

Otherwise my program, which is designed to run on several Arduino boards, will have to have special code and preprocessor directives to handle the MAX32620FTHR board.

khariya commented 5 years ago

Thanks for your suggestion! We will include this in our next update, once we resolve the issue #5.