Pages: [1]   Go Down
Author Topic: [RESOLVED] cannot set pin 13 mode when using while (!SerialUSB) in setup  (Read 619 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 2
Posts: 59
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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.
« Last Edit: May 08, 2013, 08:54:04 am by exedor » Logged

Germany
Offline Offline
Full Member
***
Karma: 10
Posts: 230
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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
Code:
while (!Serial);
and
Code:
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
Code:
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.
Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 59
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Pages: [1]   Go Up
Jump to: