I’m using a TTGO T3 board with LoRa, OLED and SD card interfaces.
I’m trying to switch OLED display ON or OFF with a touch pin. A pin touch should toggle it ON or OFF and, after elapsed time, it should be turned off.
The touch pin triggers an interrupt that simply notifies a task. The task is supposed to handle the pin touch, which so far takes care of the OLED only.
But, for some reason, the device resets and I wonder why. I think about two possibilities:
- touch sensing keeps bouncing during too long.
- SPI cross interference, since touch and VSPI (SD card) use the same port.
The code is:
...
void Toque_BOTAO1 () // touch interrupt procedure
{
digitalWrite(LED, true); // visual indication
xTaskNotifyGive(vT_OLED_ON_OFF_hdl); // triggers ON / OFF switching
}
...
void vT_OLED_ON_OFF(void *pvParameters)
{
TickType_t xDelayOLED = 60000 / portTICK_PERIOD_MS; // max OLED ON interval
uint32_t reason; // reason for running task (time / touch)
bool OLED_ON_OFF = true; // OLED display switch
while (true) // infinite loop
{
reason = ulTaskNotifyTake(pdTRUE, xDelayOLED); // waits for touch button or time lapse
Serial.printf("\nTouch Btn 1: %x\n", reason); // serial prints reason
if (reason) { // if touch button interrupt
OLED_ON_OFF = !OLED_ON_OFF; // > toggles OLED display
}
else
{ // if elapsed time
OLED_ON_OFF = false; // > switches OLED display OFF
}
if (OLED_ON_OFF) { // switches display according to flag
OLED.ssd1306_command(SSD1306_DISPLAYON); // > ON
} else {
OLED.ssd1306_command(SSD1306_DISPLAYOFF); // > OFF
}
vTaskDelay(200 / portTICK_PERIOD_MS); // debounce delay
ulTaskNotifyTake(pdTRUE, 0); // releases bounce
}
}
...
void setup ()
{
...
xTaskCreatePinnedToCore(vT_OLED_ON_OFF, "OLED ON/OFF", 1000, NULL, 1, &vT_OLED_ON_OFF_hdl, 1);
touchAttachInterrupt(BOTAO1, &Toque_BOTAO1, 20);
...
}
After the first time the button is touched, the code runs its interrupt and task, then keeps running a few seconds and ends like:
ets Jun 8 2016 00:22:57
rst:0x8 (TG1WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8
What might be going on?
Thank you.
Regards