Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #6951
    peak
    Participant

    I understand that Serial.flush() is empty for Adafruit FONA. In Print.h:
    virtual void flush() { /* Empty implementation for backward compatibility */ }

    I need to make sure that all Serial.print() statements are completed before I enter sleep mode for the FONA, otherwise it will be subsequently woken up in Serial.print code (and crashes) instead of in loop().

    Is there any code that can accomplish this?

    #6957
    LIM PHANG MOH
    Keymaster

    Are you sure they are empty? flush() could be implemented in Stream class. I could be wrong because I rarely use 32U4.
    Try putting some characters into print() and call flush() before sleep. See whether all characters are sent before sleep.

    Else it is best to simply put a delay by comparing it to millis(). Just estimate the time by calculating how many bytes you are sending.

    #6963
    peak
    Participant

    LIM PHANG MOH,
    Again, thanks for your effort. Yes, I did call flush() before sleep and it crashed. Found this code:
    u16 flushOutput()
    {
    u16 count;
    while ((count = FifoByteCount()) != 0);
    return count; // Returns 0
    }
    u16 FifoByteCount()
    {
    return ((((u16)UEBCHX) << 8) | (UEBCLX));
    }

    It compiles ok but does not wait untill the output buffer is empty.

    Regarding delay() : I cannot estimate the number of characters waiting to be output. They come from various libraries with DEBUG_PRINT and the like.
    There must surely be a way to interrogate the output queue in the build-in UART in Atmel 32u4.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.