[RESOLVED] cannot set pin 13 mode when using while (!SerialUSB) in setup

Wondering if someone can help me understand what is going on with the code below??

void setup()
{
  // This seems to ignore the pinMode statement but commenting out the while statement below works fine.
  while (!SerialUSB);
  pinMode(13, OUTPUT);
}

void loop()
{
  digitalWrite(13, LOW);
}

When changing the line above to "while (!Serial);" it works just as if it was commented out entirely. I read somewhere that you should put while (!Serial); in your setup as a first step to ensure the serial port hardware is initialized before doing anything else with it. Wouldn't this also be the case for SerialUSB when using the native USB port??

If the while statement on SerialUSB is used at all the digitalWrite statement has no effect and LED always stays on.

exedor:
Wondering if someone can help me understand what is going on with the code below??

void setup()

{
 // This seems to ignore the pinMode statement but commenting out the while statement below works fine.
 while (!SerialUSB);
 pinMode(13, OUTPUT);
}

void loop()
{
 digitalWrite(13, LOW);
}




When changing the line above to "while (!Serial);" it works just as if it was commented out entirely. I read somewhere that you should put while (!Serial); in your setup as a first step to ensure the serial port hardware is initialized before doing anything else with it. Wouldn't this also be the case for SerialUSB when using the native USB port??

If the while statement on SerialUSB is used at all the digitalWrite statement has no effect and LED always stays on.

Yes thats right.

The code lines

while (!Serial);

and
while (!SerialUSB);
let the Due what until there is an USB connection between Due and PC. If you use the programming port and set this line

while (!Serial);

The Due will walk over this line while the USB is connected but if you connect after the programming the due with the nativ USB-Port nothing will happend the Due waits for an plugin in the programming port.

Vice versa for both ports.

Ahh, duh. That makes sense. I am using native USB in production and programming in development. I was under the impression it was waiting for initialization of the internal controller and not an actual connection to an end-point/host. Makes perfect sense. Thank you very much!