EasyManua.ls Logo

AZ-Delivery D1 Mini - Sharing CPU Time with the RF Part

AZ-Delivery D1 Mini
27 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
- 13 -
Sharing CPU time with the RF part
One thing to keep in mind while writing programs for the D1 Mini module
(ESP8266) is that the sketch has to share resources (CPU time and memory)
with the wifi and TCP-stacks (the software that runs in the background and
handles all wifi and IP connections). If the code takes too long to execute, and
do not let the TCP stacks do their thing, the program might crash, or the data
could be lost. It is best to keep the execution time of the loop under a couple of
hundreds of milliseconds. Every time the main loop is repeated, a sketch yields
to the wifi and TCP to handle all wifi and TCP requests. If the loop takes longer
than this, the CPU time have to explicitly be given to the wifi/TCP stacks, by
using including delay(0) or yield(). If this is not done, network communication will
not work as expected, and if it is longer than 3 seconds, the soft WDT
(Watchdog Timer) resets the ESP. If the soft WDT is disabled, after a little over
8 seconds, the hardware WDT resets the chip. From the perspective of
microcontroller however, 3 seconds is a very long time (240 million clock
cycles), so unless some extremely heavy number crunching is done, or sending
extremely long strings over serial, the sketch will not be affected by this. Just
keep in mind to add the yield() inside the for or while loops that could take longer
than, say 100ms.