logo elektroda
logo elektroda
X
logo elektroda

ESP8266 - AT response termination specification (CR, LF, CR CR LF?)

robiw 2514 13
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 16272988
    robiw
    Level 26  
    Hello Colleagues,
    My question concerns the specification of the ESP8266 modem responses sent to the microcontroller (USART, 115200bps). Does each modem response end with a pair of CR and LF characters, or could it be CR CR and LF or something else? I have written a simple function based on the USART receiver's ISR that stores each incoming byte in a C-string until it encounters an LF character. When it encounters it, it returns the C-string as the module's response (it rewrites the ISR function's C-string to another C-string for the main function - a sort of caching)...and that's just it, it doesn't always work well. E.g. the module response "CONNECT" only returns as "CO"..., it doesn't return, for example, the ">" character that the modem sends while waiting for TCP data...etc. Does anyone have any experience in this matter? Many thanks in advance.... robiw

    PS.
    I'm not posting the code, which is trivial, as I'm away from home without access to the computer where I have it.
  • ADVERTISEMENT
  • #2 16273387
    Anonymous
    Anonymous  
  • ADVERTISEMENT
  • #3 16273734
    robiw
    Level 26  
    ;-) . I will attach the code tomorrow...robiw
  • #4 16274819
    robiw
    Level 26  
    Variables:

    Code: C / C++
    Log in, to see the code
    .

    Function:

    Code: C / C++
    Log in, to see the code
    .

    Well it doesn't work properly, as I wrote earlier.... robiw
  • #5 16275038
    grko
    Level 33  
    @robiw Maybe just subsequent data from the ESP8266 overwrites your data in modemReply before you can display it on the serial port.
  • #6 16275057
    robiw
    Level 26  
    No, because they come infrequently. I've reduced the speed from the standard 115200 to 9600 and it works sort of better, i.e. the whole "CONNECT" response already comes in, not just "CO". The question is, does each line of the modem response end with a sequence of CR+LF bytes? robiw
  • ADVERTISEMENT
  • #7 16275081
    Anonymous
    Anonymous  
  • #8 16275135
    Anonymous
    Anonymous  
  • #9 16275224
    grko
    Level 33  
    @Piotrus_999 Using a for loop instead of the standard memcpy/strcpy functions. Great idea to replace a specially optimised for AVR function in favour of a dull for loop.

    @robiw You can avoid this copying by making yourself 2 buffers. You fill one in the interrupt and use the other in the main thread. When you receive an end-of-line character, you simply change the pointer to the active buffer.
  • ADVERTISEMENT
  • #10 16275328
    Anonymous
    Anonymous  
  • #11 16275348
    Anonymous
    Anonymous  
  • #12 16275361
    Anonymous
    Anonymous  
  • #13 16275455
    robiw
    Level 26  
    I'll check carefully tomorrow, but it seems that after reducing the speed to 9600 bps everything "laughs" better. The processor is clocked at 11.059MHz, so that 115200 bps wasn't too bad for it, especially as the target interrupt is to parse data into multiple variables gathered into a structure. In Realterm I previewed and the lines are terminated with either a CR+LF sequence or, much more often, LF alone. The exception is OK, which occurs, as a sequence of CR+LF OK CR+LF. Sometimes LF alone also appears in the responses.... robiw
  • #14 16282252
    dondu
    Moderator on vacation ...
    robiw wrote:
    In Realterm I previewed and the lines end with either a CR+LF sequence or much more often with LF alone. The exception is OK, which occurs, as the sequence CR+LF OK CR+LF. Sometimes LF alone also appears in the answers.... robiw
    .
    And what display mode did you select Ansi? Ascii? ... Both are wrong, because Realterm does not display all received bytes.

    Always preview in Hex mode, preferably Hex+Ascii.

Topic summary

The discussion addresses the termination characters of ESP8266 modem responses sent via USART at 115200 bps. The original question concerns whether each response ends with a CR+LF sequence, CR CR LF, or other variations. It was found that responses often end with either CR+LF or LF alone, with some exceptions like the "OK" response appearing as CR+LF OK CR+LF. Reducing the baud rate to 9600 bps improved reception reliability. The use of an interrupt service routine (ISR) to capture incoming bytes until an LF character was detected proved unreliable, partly due to the use of functions like strcpy within the ISR, which can increase interrupt execution time and stack usage. Suggestions include using double buffering to avoid data overwriting and analyzing responses with tools like Realterm in hex mode to accurately observe termination characters. It is also recommended to parse expected responses with timeouts rather than relying solely on line-ending characters, as the ESP8266 may send binary data on startup and responses can vary. Overall, the ESP8266 responses do not consistently end with a fixed CR+LF sequence, and careful handling of USART data reception and parsing is necessary for reliable communication.
Summary generated by the language model.
ADVERTISEMENT