-->
Page 1 of 2

repeatly reboot of the ESP8266

PostPosted: Sat Apr 13, 2019 11:54 am
by HEck
Hi Connunity,

I created a ISR-controlled I2C-slave. It is working fine so far. The recieved data are collected in a buffer and when the stop-condition is detected, a final-flag "TransferFin" is set.

The main program is waiting for that flag in a infinitely "while" loop. I made this:

Code: Select allvoid ICACHE_FLASH_ATTR
main_loop (void)
{
      uint8_t LV;
   
   
   
   TransferFin = 0;
   os_printf("TransferFin: %x\n", TransferFin);
   
   while (1)
   {
      // os_printf("Transfer: %x\n", TransferFin); //for debug
      if (TransferFin == 1)
      {
         os_printf("TransferFin: %x\n", TransferFin);//for debug
         for (LV=0; LV < DatLen; LV++)
         {
            os_printf("%x\n", DatBuf[LV] );
         }
         
         TransferFin = 0;
         os_printf("\n");
      }
      LV++;// for debug
   }
   
   
}


I`m starting this main_loop at last in the "user_init()". But after that, the ESP8266 is rebooting about each 2 secundes.

What could be the reason?

Thank you for your support.
Greetings
Henry

Re: repeatly reboot of the ESP8266

PostPosted: Sun Apr 14, 2019 5:02 am
by btidey
The ESP8266 has a watchdog timer which if not regularly serviced will reboot.

Normally it is serviced each time round the loop.

As you have a while loop inside the loop that doesn't happen and the watchdog gets activated.

You could service the watchdog within your loop (yield) but that is still not good practice. Much better is to ensure the main loop is running all the time and use a state variable to determine what code gets executed on each iteration of the main loop.

In your case the while is effectively redundant. You should remove that and let the main loop do the work. Any code you want just executed once can either be put in setup or moved to a function that only gets executed once by the main loop.

Re: repeatly reboot of the ESP8266

PostPosted: Sun Apr 14, 2019 6:43 am
by HEck
Hi btidey,

thank you for your respond. Yes, something like such rules as a permanent WDT was in my head. But I cannot understand, why it is running in a function which is called "user_init()". As I can see in the SDK-demos, there is a function "user_pre_init()", where the "system_partition_table_regist" is executed. Should here take place also the initialisation of the user_tasks?

Or if not, how I can define to the "internal-loop" which function is to handle as a single and which is a part of the internal main-loop. Because for my initialisation-functions I can see, that these are executed only one time per system-boot:

Code: Select allvoid ICACHE_FLASH_ATTR
user_init(void)
{
   he_init_timer();
        he_init_gpio();
   he_init_slave();
   main_loop ();
}


As you remember, in the "main_loop()" is the redundent while(1).

I could nothing find such description in the Espressif-docs. It would be nice, if you can give me a code-example or a pointer to a documentation where it is described.

Thank you
Henry

Re: repeatly reboot of the ESP8266

PostPosted: Sun Apr 14, 2019 4:19 pm
by btidey
My comment was based on code running in an Arduino environment but looking at your code I think you are using a non-OS environment.

The need to allow time for other processes to run still apply here and to avoid timeouts but the methods to achieve this are different.

If you want to use non-OS then you need to research the techniques to achieve this.