Xinyuan-LilyGO / T-Display-S3

MIT License
729 stars 172 forks source link

Display turns off when calling tone() #248

Closed wichjan closed 1 month ago

wichjan commented 1 month ago

With my T-Display-S3 Touch (using the TFT_eSPI-library) I encounter the same issue previously described in the closed and unsolved issue #95: When using the tone()-functionality (for example to run a buzzer) the display turns off and the board is rebooting. For this to happen not even a real buzzer has to be connected to some i/o-port, just calling tone(params) or oven just calling noTone(some Pin-Nr) immediately turns kicks oof the board..

Does anyone have an idea how to solve this issue or where to look for the reason of this peculiar behavior? Regards, Jan

The details:


#include <TFT_eSPI.h> 
#include "TFT_eSPI.h"

TFT_eSPI tft = TFT_eSPI(); 
TFT_eSprite scr = TFT_eSprite(&tft);

void setup() {

  pinMode(15,OUTPUT);
  digitalWrite(15,1);

  ledcSetup(0, 2000, 8);  // Backlight
  ledcAttachPin(38, 0);
  ledcWrite(0, 200);

  tft.init();
  scr.createSprite(170, 320);
  scr.fillSprite(tft.color565(180,180,180));
  scr.pushSprite(0,0);

} // end setup()

void loop() {

  static uint32_t t_interval=millis();
  if (millis()-t_interval > 5000) {
    noTone(1); // kicks off display, same happens with any other pin
  }

} // end loop()

19:52:16.153 -> E (21280) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
19:52:16.153 -> E (21280) task_wdt:  - IDLE (CPU 0)
19:52:16.153 -> E (21280) task_wdt: Tasks currently running:
19:52:16.159 -> E (21280) task_wdt: CPU 0: toneTask
19:52:16.159 -> E (21280) task_wdt: CPU 1: IDLE
19:52:16.159 -> E (21280) task_wdt: Aborting.
19:52:16.159 -> 
19:52:16.159 -> abort() was called at PC 0x4200f1d8 on core 0
19:52:16.159 -> 
19:52:16.159 -> 
19:52:16.159 -> Backtrace: 0x403777b6:0x3fc92cd0 0x4037a879:0x3fc92cf0 0x4037ffc9:0x3fc92d10 0x4200f1d8:0x3fc92d90 0x40378765:0x3fc92db0 0x40001a9d:0x3fced8f0 0x42007940:0x3fced910 0x420071d3:0x3fced930
19:52:16.159 -> 
19:52:16.159 -> 
19:52:16.159 -> 
19:52:16.159 -> 
19:52:16.159 -> ELF file SHA256: db3a77ee569c8784
19:52:16.379 -> 
19:52:16.379 -> Rebooting...
19:52:16.379 -> ESP-ROM:esp32s3-20210327
19:52:16.379 -> Build:Mar 27 2021
19:52:16.379 -> rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
19:52:16.412 -> Saved PC:0x403773c4
19:52:16.412 -> SPIWP:0xee
19:52:16.412 -> mode:DIO, clock div:1
19:52:16.412 -> load:0x3fce3808,len:0x44c
19:52:16.412 -> load:0x403c9700,len:0xbe4
19:52:16.412 -> load:0x403cc700,len:0x2a68
19:52:16.412 -> entry 0x403c98d4
lewisxhe commented 1 month ago

Tone calls channel 0 by default. Just change the following to channel 1.

   ledcSetup(1, 2000, 8); // Backlight
   ledcAttachPin(38, 1);
   ledcWrite(1, 200);
wichjan commented 1 month ago

Thanks for the quick support! I changed the pwm_channel to '1' in the backlight setup, but unfortunately it did not change the strange behavior …

lewisxhe commented 1 month ago

There is a problem with your loop. It does not enter every 5 seconds at all, but continuously executes noTone, which causes the watchdog to trigger. The following is the repair procedure.


// https://github.com/Xinyuan-LilyGO/T-Display-S3/issues/248

#include <TFT_eSPI.h>
#include "TFT_eSPI.h"

TFT_eSPI tft = TFT_eSPI();
TFT_eSprite scr = TFT_eSprite(&tft);

void setup()
{
    Serial.begin(115200);
    pinMode(15, OUTPUT);
    digitalWrite(15, 1);

    ledcSetup(0, 2000, 8);  // Backlight
    ledcAttachPin(38, 0);
    ledcWrite(0, 200);

    tft.init();
    scr.createSprite(170, 320);
    scr.fillSprite(tft.color565(180, 180, 180));
    scr.pushSprite(0, 0);

} // end setup()

uint32_t t_interval ;
void loop()
{

    if (millis() > t_interval ) {
        Serial.println("noTone");
        t_interval = millis() + 5000;
        noTone(1); // kicks off display, same happens with any other pin
    }

} // end loop()
wichjan commented 1 month ago

Yeah, I kept the Demo-Code a little too clean and forgot to reset the time-stamp t_intervall inside the if-block, so that after the first 5 seconds after booting, tone()is called in each loop()-pass. But why this should cause the board to reboot I really don’t understand. And this does not change with your code either.

But: if I call (like in a more realistic example) tone(...) before calling noTone() everthing works fine! Also in the actual project-code, after changing the PWM-channel for the backlight to '1', as you suggested in your first answer! (I should have tried this earlier, but I focused on the example-code). So, the case is solved :–) (although I did not understand what really happens). Thanks again, Jan