Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 7 months ago.
printf before a __WFI() call
I'm using WFI to put the device to sleep for a fixed period of time, however any printf calls I make slightly before calling WFI() fail to be sent along serial.
printf("HELLO"); // Is there anything that can go here to guarantee the printf will actually run? __WFI();
2 Answers
8 years, 7 months ago.
Try adding \n after the "hello". By default printf is buttered, and nothing is sent until the buffer is full or \n is reached. If you let it enter deep sleep you Wi will have again other problems with this.
8 years, 7 months ago.
You should only lose uart tx characters if going to deep sleep mode where peripherals shut down. if youre not battery powered, maybe you could use regular sleep, where only cpu core shuts down. The correct method of preventing lost bytes when going to deep sleep is to wait until uart transmit complete flag before WFI, but that is platform specific.