Go Down

Topic: serial.write() in setup()? (Read 865 times) previous topic - next topic


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?



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!


Sep 02, 2009, 07:23 am Last Edit: Sep 02, 2009, 07:24 am by thoed Reason: 1
The Arduino gods shun you! Especially for answering your own question. :D


just for info (from main.cxx):
Code: [Select]
int main(void)

     for (;;)
     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...)

Go Up