SD Card stops touch working
Hi All,
Thanks for the great tutorials. I am using your DIS06043H 4.3” Crow Panel.
Basically I have lesson 6 (with my own Square Line screens) running and everything works as it should.
My problem is that when I install the SD Card initialization code (from lesson 3) the touch stops working. If I write to the SD Card the system crashes. The SD Card initializes with out an error message.
I modified the initialization for the SD Card as follows with same problem:
#include <Wire.h>
#include <SPI.h>
#include <FS.h?
#include <lvgl.h>
#include "ui.h"
#include <SD.h>
#include "gfx_conf.h"
// for esp_now
#include <esp_now.h>
#include <WiFi.h>
#include <EEPROM.h>
SPIClass * sd_spi = NULL;
// Define custom SPI pins
#define SD_CS 10 // Chip Select (CS) pin
#define SD_MISO 13 // Master In Slave Out pin
#define SD_MOSI 11 // Master Out Slave In pin
#define SD_SCK 12 // Serial Clock pin
Code in SETUP to start SD_Card:
sd_spi = new SPIClass(HSPI);
sd_spi->begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS);
pinMode(sd_spi->pinSS(), OUTPUT);
if (!SD.begin(SD_CS, *sd_spi, 80000000))
{Serial.println("SD card initialization failed!"); return; }
Thanks
Matt
Comments
I fixed the code, SD.begin works without interference with touch.
The system still crashes when opening SD card. The touch is on an interrupt, I verified that the touch chip select is not going low during a write to SD. I suspect but can't prove the lovyanGFX is still listening to the SPI bus.
touch_cfg.bus_shared = true; // 画面と共通のバスを使用している場合 trueを設定
It is possible that Lovyangfx is still actively listening to the SPI bus, still when you are trying to reach the SD card. The library cannot release the SPI bus properly, which may intervene. SD cards and touch screens can fight for access to SPI bus. Even with proper chip selection, the SPI simply cannot be completely inactive when a device is trying to use it.Null's Brawl