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!

2
  • To be clear, you're saying pin 13 blinks if and only if the call to tft.init is commented out?
    – timemage
    Mar 20 at 22:01
  • @timemage yes, exactly
    – JCSB
    Mar 20 at 22:34
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.

1
  • 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 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.