bill,
no - i tried different clock speeds already ( actually without any effect..)
i assume a bug in the library where both signals are not coordinated well:
as you see on img both signals going down on "appending file"
and appending file is working well
i propose a clean reset/free of SPI after dealing with TFT and after dealing with SD
rgds
rudi
ILI9341 2.2"TFT & SD writing to SD card
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- nanomax
- Posts: 18
- Joined: Wed Dec 13, 2017 8:38 am
Re: ILI9341 2.2"TFT & SD writing to SD card
- Attachments
-
- tft_cs sd_cs.jpg (96.23 KiB) Viewed 161 times
- adafruit_support_bill
- Posts: 88089
- Joined: Sat Feb 07, 2009 10:11 am
Re: ILI9341 2.2"TFT & SD writing to SD card
I've never seen issues like that with multiple SPI devices. Might be something specific to the ESP32 implementation of SPI support.
- nanomax
- Posts: 18
- Joined: Wed Dec 13, 2017 8:38 am
Re: ILI9341 2.2"TFT & SD writing to SD card
you are saying its a esp32 error ?
and the adfruit lib is not able to handle ESP32 ?
pls setup a simple demo code on your side.
thanks
rudi
and the adfruit lib is not able to handle ESP32 ?
pls setup a simple demo code on your side.
thanks
rudi
- nanomax
- Posts: 18
- Joined: Wed Dec 13, 2017 8:38 am
Re: ILI9341 2.2"TFT & SD writing to SD card
mosi signal only starting
when in loop tft.begin() is called
when in loop tft.begin() is called
- Attachments
-
- mosi.jpg (252.43 KiB) Viewed 156 times
- adafruit_support_bill
- Posts: 88089
- Joined: Sat Feb 07, 2009 10:11 am
Re: ILI9341 2.2"TFT & SD writing to SD card
The ILI9341 and SD libraries both utilize the Arduino SPI library for access to SPI functionality. Processor-specific code for this is implemented in the board-support package for that processor. In the case of the ESP32, this code is supplied by Espressif.
https://github.com/espressif/arduino-esp32
https://github.com/espressif/arduino-esp32
- adafruit_support_bill
- Posts: 88089
- Joined: Sat Feb 07, 2009 10:11 am
Re: ILI9341 2.2"TFT & SD writing to SD card
Have you tested it with the bitmap example described in the guide?
https://learn.adafruit.com/2-2-tft-display/bitmaps
https://learn.adafruit.com/2-2-tft-display/bitmaps
- adafruit_support_bill
- Posts: 88089
- Joined: Sat Feb 07, 2009 10:11 am
Re: ILI9341 2.2"TFT & SD writing to SD card
Actually, it looks like you are using the 'bitbang' software SPI option for the ILI9341 constructor. That bypasses the hardware SPI implementation and toggles all the pins explicitly in software.
Have you tried using hardware SPI for the display?
Code: Select all
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
Code: Select all
/*!
@brief Instantiate Adafruit ILI9341 driver with hardware SPI using the
default SPI peripheral.
@param cs Chip select pin # (OK to pass -1 if CS tied to GND).
@param dc Data/Command pin # (required).
@param rst Reset pin # (optional, pass -1 if unused).
*/
/**************************************************************************/
Adafruit_ILI9341::Adafruit_ILI9341(int8_t cs, int8_t dc, int8_t rst)
- nanomax
- Posts: 18
- Joined: Wed Dec 13, 2017 8:38 am
Re: ILI9341 2.2"TFT & SD writing to SD card
hi bill, yes
hard SPI is working very fast!
but tft_hard
is only working when uncommented in setup.... ??
and recalling in loop
tft_soft
SD append and list dir working well
thanks & regards
rudi
hard SPI is working very fast!
but tft_hard
is only working when uncommented in setup.... ??
and recalling in loop
tft_soft
SD append and list dir working well
thanks & regards
rudi
Code: Select all
#include <Arduino.h>
#include "FS.h"
#include "SD.h"
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
// s o f t
#define TFT_MOSI 23
#define TFT_MISO 19
#define TFT_CLK 18
#define TFT_CS 17
#define TFT_DC 16
#define TFT_RST 5
// h a r d
#define _mosi 23
#define _miso 19
#define _sclk 18
#define _cs 17
#define _dc 16
#define _rst 5
#define SD_CS 4
uint16_t loop_counter = 0;
String dataMessage;
Adafruit_ILI9341 tft_s = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
Adafruit_ILI9341 tft_h = Adafruit_ILI9341( _cs, _dc, _rst);
//---------------------------------------------- SD ----------------------------------------
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
Serial.printf("Listing directory: %s\n", dirname);
File root = fs.open(dirname);
if(!root){
Serial.println("Failed to open directory");
return;
}
if(!root.isDirectory()){
Serial.println("Not a directory");
return;
}
File file = root.openNextFile();
while(file){
if(file.isDirectory()){
Serial.print(" DIR : ");
Serial.println(file.name());
if(levels){
listDir(fs, file.name(), levels -1);
}
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.println(file.size());
}
file = root.openNextFile();
}
}
void createDir(fs::FS &fs, const char * path){
Serial.printf("Creating Dir: %s\n", path);
if(fs.mkdir(path)){
Serial.println("Dir created");
} else {
Serial.println("mkdir failed");
}
}
void removeDir(fs::FS &fs, const char * path){
Serial.printf("Removing Dir: %s\n", path);
if(fs.rmdir(path)){
Serial.println("Dir removed");
} else {
Serial.println("rmdir failed");
}
}
void readFile(fs::FS &fs, const char * path){
Serial.printf("Reading file: %s\n", path);
File file = fs.open(path);
if(!file){
Serial.println("Failed to open file for reading");
return;
}
Serial.print("Read from file: ");
while(file.available()){
Serial.write(file.read());
}
file.close();
}
void writeFile(fs::FS &fs, const char * path, const char * message){
Serial.printf("Writing file: %s\n", path);
File file = fs.open(path, FILE_WRITE);
if(!file){
Serial.println("Failed to open file for writing");
return;
}
if(file.print(message)){
Serial.println("File written");
} else {
Serial.println("Write failed");
}
file.close();
}
void appendFile(fs::FS &fs, const char * path, const char * message){
Serial.printf("Appending to file: %s\n", path);
File file = fs.open(path, FILE_APPEND);
if(!file){
Serial.println("Failed to open file for appending");
return;
}
if(file.print(message)){
Serial.println("Message appended");
} else {
Serial.println("Append failed");
}
file.close();
spiEndTransaction;
}
void renameFile(fs::FS &fs, const char * path1, const char * path2){
Serial.printf("Renaming file %s to %s\n", path1, path2);
if (fs.rename(path1, path2)) {
Serial.println("File renamed");
} else {
Serial.println("Rename failed");
}
}
void deleteFile(fs::FS &fs, const char * path){
Serial.printf("Deleting file: %s\n", path);
if(fs.remove(path)){
Serial.println("File deleted");
} else {
Serial.println("Delete failed");
}
}
void testFileIO(fs::FS &fs, const char * path){
File file = fs.open(path);
static uint8_t buf[512];
size_t len = 0;
uint32_t start = millis();
uint32_t end = start;
if(file){
len = file.size();
size_t flen = len;
start = millis();
while(len){
size_t toRead = len;
if(toRead > 512){
toRead = 512;
}
file.read(buf, toRead);
len -= toRead;
}
end = millis() - start;
Serial.printf("%u bytes read for %u ms\n", flen, end);
file.close();
} else {
Serial.println("Failed to open file for reading");
}
file = fs.open(path, FILE_WRITE);
if(!file){
Serial.println("Failed to open file for writing");
return;
}
size_t i;
start = millis();
for(i=0; i<2048; i++){
file.write(buf, 512);
}
end = millis() - start;
Serial.printf("%u bytes written for %u ms\n", 2048 * 512, end);
file.close();
}
//-----------------------------------------------------------------------------------------------------------------
void setup() {
Serial.begin(115200);
/*
Serial.println("ILI9341 Test!");
tft_h.begin();
// read diagnostics (optional but can help debug problems)
uint8_t x = tft_h.readcommand8(ILI9341_RDMODE);
Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
x = tft_h.readcommand8(ILI9341_RDMADCTL);
Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
x = tft_h.readcommand8(ILI9341_RDPIXFMT);
Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
x = tft_h.readcommand8(ILI9341_RDIMGFMT);
Serial.print("Image Format: 0x"); Serial.println(x, HEX);
x = tft_h.readcommand8(ILI9341_RDSELFDIAG);
Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
tft_h.fillScreen(ILI9341_RED);
delay(555);
tft_h.fillScreen(ILI9341_GREEN);
delay(555);
tft_h.fillScreen(ILI9341_BLUE);
delay(555);
tft_h.fillScreen(ILI9341_BLACK);
delay(555);
*/
//---------------------------------------------------- SD ---------------------------------------------
tft_s.begin();
if(!SD.begin(4)){
Serial.println("Card Mount Failed");
return;
}
uint8_t cardType = SD.cardType();
delay(3333);
if(cardType == CARD_NONE){
Serial.println("No SD card attached");
return;
}
Serial.print("SD Card Type: ");
if(cardType == CARD_MMC){
Serial.println("MMC");
} else if(cardType == CARD_SD){
Serial.println("SDSC");
} else if(cardType == CARD_SDHC){
Serial.println("SDHC");
} else {
Serial.println("UNKNOWN");
}
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
Serial.printf("SD Card Size: %lluMB\n", cardSize);
}
void loop(void)
{
Serial.print("MOSI: ");
Serial.println(MOSI);
Serial.print("MISO: ");
Serial.println(MISO);
Serial.print("SCK: ");
Serial.println(SCK);
Serial.print("SS: ");
Serial.println(SS);
delay(3333);
loop_counter = loop_counter +1;
Serial.print( " ......... loop TFT ...........");
Serial.println(loop_counter);
tft_h.begin();
tft_h.fillScreen(ILI9341_BLACK);
delay(555);
tft_h.fillCircle(100, 100, 100, ILI9341_RED);
delay(555);
tft_h.fillScreen(ILI9341_MAGENTA);
delay(555);
Serial.print( " ......... loop SD ...........");
listDir(SD, "/", 0);
delay(999);
dataMessage = String(loop_counter) + "\r\n";
Serial.print(dataMessage);
appendFile(SD, "/hello.txt", dataMessage.c_str());
appendFile(SD, "/hello.txt", "loops : ");
delay(999);
}
- adafruit_support_bill
- Posts: 88089
- Joined: Sat Feb 07, 2009 10:11 am
Re: ILI9341 2.2"TFT & SD writing to SD card
Looks like you still have a "tft_s.begin();" in your setup. Not sure what happens if you try to use both software and hardware SPI on the same set of pins with that processor.
SPI does not have a rigorous formal spec like i2c. And implementation does vary a bit between devices from different manufacturers. Most drivers/libraries take care of differences such as clock polarity & phase. But initialization order is sometimes important too.
Espressif recommends initializing the SD card first:
https://docs.espressif.com/projects/esp ... share.html
SPI does not have a rigorous formal spec like i2c. And implementation does vary a bit between devices from different manufacturers. Most drivers/libraries take care of differences such as clock polarity & phase. But initialization order is sometimes important too.
Espressif recommends initializing the SD card first:
https://docs.espressif.com/projects/esp ... share.html
This step will put the SD card into the SPI mode, which SHOULD be done before all other SPI communications on the same bus. Otherwise the card will stay in the SD mode, in which mode it may randomly respond to any SPI communications on the bus, even when its CS line is not addressed.
- nanomax
- Posts: 18
- Joined: Wed Dec 13, 2017 8:38 am
Re: ILI9341 2.2"TFT & SD writing to SD card
ja,
seems tricky all together...
but still now, -- satisfied
thank you bill
rudi
seems tricky all together...
but still now, -- satisfied
thank you bill
rudi
Please be positive and constructive with your questions and comments.