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.
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...)