1

Using the .init function for the ST7789 TFT screen prevents my WDT ISR from firing. What explains this behaviour, and is there something I can do? Any other timer ISR I could use instead?

#include <Adafruit_ST7789.h>    // Includes Adafruit_GFX.h

#define TFT_CS 10 // define chip select pin
#define TFT_DC 9  // define data/command pin
#define TFT_RST 8 // define reset pin, or set to -1 and connect to Arduino RESET pin

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

void setup()
{
    //Serial.begin(9600);
    pinMode(13, OUTPUT);

    WDTCSR = (24); // Change enable and WDE - also resets
    //prescalers only - get rid of the WDE and WDCE bit.
    WDTCSR = (6); // 1 sec
    WDTCSR |= (1 << 6); //enable interrupt mode - WDT as an interrupt is useful to wake up from sleep
    sei();

    tft.init(240, 240, SPI_MODE2); // comment this out and WDT works fine
    tft.setRotation(0);
    tft.setTextWrap(true);
}


void loop()
{
    
}


ISR(WDT_vect)
{
  digitalWrite(13, (digitalRead(13) ^ 1));   // toggle LED pin    
}

Thanks!

timemage
  • 4,690
  • 1
  • 10
  • 24
JCSB
  • 111
  • 1

1 Answers1

2

You can't use the LED on pin 13 on Uno, Nano or Nano Every, if you use SPI . It is the clock pin of the SPI.

The init function of the display initializes SPI which dedicates the pin to SPI peripheral and disconnects it from pin IO peripheral.

Juraj
  • 17,050
  • 4
  • 27
  • 43
  • 1
    Good point. Maybe I'd notice that if he mentioned about used pins like "using freaking 8 - RST; 9 - DC; 10 - CS; 11 - MOSI; 12 - MISO; 13 - SCLK; 13 - LED_BUILTIN" – KIIV Mar 21 '21 at 06:50