Pages: [1]   Go Down
Author Topic: serial.write() in setup()?  (Read 443 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've got a 0017 sketch that outputs to the UART (connected to a radio transceiver).  I just need a one-shot thing that reacts to a button press, and the last thing the sketch needs to do is serial.write().  So I'm thinking put the whole sketch in setup() and leave loop() empty.  But the serial.write doesn't work when it's coded in setup().  If I move the serial.write inside the loop() function it works.  Of course it loops too, so it gets written forever.

My question is, are there any constraints on what code can run in setup().  Like, are global interrupts turned off for that section?  

Is it normal that Serial.write() only works from loop() section?

Regards
Scott


Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My bad... turns out the radio transceiver was taking a little time to recover from sleeping to its awake state... and was not ready to receive the serial.write().  It shrugged it off...

Having the serial.write() in the loop() section meant when the radio finally woke up, the writes were happening.

Sorry Arduino for doubting yoU!
Logged

Spokane, Washington
Offline Offline
God Member
*****
Karma: 1
Posts: 686
My name is Bob, and I'm an addict.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The Arduino gods shun you! Especially for answering your own question. smiley-grin
« Last Edit: September 02, 2009, 12:24:16 am by thoed » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

just for info (from main.cxx):
Code:
int main(void)
{
      init();

      setup();
    
      for (;;)
            loop();
        
      return 0;
}

that is where the loop and setup are called from, as you can see there is no reason why something would work in loop, but not in setup (except timing constraint like the one you got...)
Logged

Pages: [1]   Go Up
Jump to: