2024-06-24 05:34 AM - last edited on 2024-06-24 07:07 AM by SofLit
i have interfaced stm32 and Sd card performed different operations separately and i have interfaced stm32 and tft wave share(ili9486) display and able to display some graphics separately ,now i am trying to fetch a image from sd card and display it on the LCD but i am able to communicate with only one slave and if Sd card works display does not work and vice -versa and i am using Arduino ide for coding. Please help me to solve this
#include <spi.h>
#include <SD.h>
#include <Adafruit_GFX.h>
#include <Waveshare_ILI9486.h>
#define SD_MOSI_PIN PC12 // MOSI Pin
#define SD_MISO_PIN PC11 // MISO Pin
#define SD_SCLK_PIN PC10 // Clock Pin
#define SD_SS_PIN PB0 // Chip Select or Slave Select Pin
#define TFT_CS_PIN PB6
#define TFT_DC_PIN PA8
#define TFT_RST_PIN PA9
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define BUFFER_SIZE 50
char textBuffer[BUFFER_SIZE];
// Assuming the constructor in your library takes no arguments
Waveshare_ILI9486 tft;
uint16_t color565(uint8_t r, uint8_t g, uint8_t b) {
return ((r & 0xF8) << | ((g & 0xFC) << 3) | (b >> 3);
}
static int bufferIndex = 0;
File myFile;
void setup() {
Serial.begin(115200);
Serial.println("Initializing SD card...");
SPI.setMISO(SD_MISO_PIN);
SPI.setMOSI(SD_MOSI_PIN);
SPI.setSCLK(SD_SCLK_PIN);
if (!SD.begin(SD_SS_PIN)) {
Serial.println("SD card initialization failed!");
while (1);
}
Serial.println("SD card initialization done.");
myFile = SD.open("test6.txt");
if (myFile) {
while (myFile.available() && bufferIndex < BUFFER_SIZE - 1) {
char nextChar = myFile.read();
textBuffer[bufferIndex++] = nextChar;
}
textBuffer[bufferIndex] = '\0'; // Null-terminate the string
myFile.close();
} else {
Serial.println("Error opening test6.txt");
}
tft.begin();
}
void loop() {
tft.fillScreen(GREEN);
tft.setTextSize(2);
// Print the content of the buffer on the display
tft.print(textBuffer);
delay(1200);
}
2024-06-26 09:25 AM
Do you use the same SPI port for both SD card and TFT? Do they agree to the same SPI type? There may be conflict. May be if possible use different SPI ports
2024-06-27 09:57 PM - last edited on 2024-07-15 03:22 AM by SofLit
No they use different spi port ,for tft i am using spi2 and for sd card i am using spi3 and i got the output i am able to read a text and store it in a array and the display it but the thing it is not possible to store image in a array as it is huge bytes of data
so i am thinking of using daisy chain configuration so that i can send data from my sd card to display, but i am getting sd card not initialized
#include <Arduino.h>
#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h>
#include <Waveshare_ILI9486.h>
#define SD_MOSI_PIN PC12 // MOSI Pin
#define SD_MISO_PIN PC11 // MISO Pin
#define SD_SCLK_PIN PC10 // Clock Pin
#define SD_SS_PIN PB0 // Chip Select or Slave Select Pin
#define TFT_MOSI_PIN PB15 // MOSI Pin for TFT display
#define TFT_MISO_PIN PB14 // MISO Pin for TFT display
#define TFT_SCLK_PIN PB13 // Clock Pin for TFT display
#define TFT_CS_PIN PB6 // Chip Select for TFT display
#define TFT_DC_PIN PA8 // Data/Command Pin for TFT display
#define TFT_RST_PIN PA9 // Reset Pin for TFT display
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define BUFFER_SIZE 50
char textBuffer[BUFFER_SIZE];
// Assuming the constructor in your library takes no arguments
Waveshare_ILI9486 Waveshield;
Adafruit_GFX &tft = Waveshield;
uint16_t color565(uint8_t r, uint8_t g, uint8_t b) {
return ((r & 0xF8) << | ((g & 0xFC) << 3) | (b >> 3);
}
static int bufferIndex = 0;
File myFile;
void setup()
{
Serial.begin(115200);
Serial.println("Initializing SD card...");
// Set SPI pin modes for SD card
SPI.setMISO(SD_MISO_PIN);
SPI.setMOSI(SD_MOSI_PIN);
SPI.setSCLK(SD_SCLK_PIN);
// Initialize SD card
if (!SD.begin(SD_SS_PIN)) {
Serial.println("SD card initialization failed!");
while (1);
}
Serial.println("SD card initialization done.");
// Open the file on the SD card
myFile = SD.open("test6.txt");
if (myFile) {
while (myFile.available() && bufferIndex < BUFFER_SIZE) {
char nextChar = myFile.read();
textBuffer[bufferIndex++] = nextChar;
}
myFile.close();
} else {
Serial.println("Failed to open file.");
}
// Set SPI pin modes for TFT display
SPI.setMISO(TFT_MISO_PIN);
SPI.setMOSI(TFT_MOSI_PIN);
SPI.setSCLK(TFT_SCLK_PIN);
// Initialize the display
Waveshield.begin();
tft.fillScreen(BLACK);
tft.setTextSize(2);
tft.setRotation(2);
tft.print(textBuffer);
//delay(1200);
}
void loop()
{
// Fill the screen with green color
}
2024-06-30 11:04 PM
you can try to set this pin( SD_SS_PIN) as output in the setup and enable it before calling the SD.begin() , since this is not the hardware SS pin for the specified SPI bus. It may work straight out if you use spi1 pins for sd.
2024-07-01 06:27 AM
like this?
// Set SPI pin modes for SD card
pinMode(SD_SS_PIN, OUTPUT); // Set SD_SS_PIN as output
pinMode(TFT_CS_PIN, OUTPUT); // Set SD_SS_PIN as output
digitalWrite(SD_SS_PIN, LOW); //Disable SD card
digitalWrite(TFT_CS_PIN, LOW); //Disable SD card
2024-07-01 08:54 AM
Yes, did you try?
2024-07-02 03:56 AM
From the schematics and code examples of the waveshare display, it looks like they are using shared spi, means same spi MISO, MOSI,SCLK, only separate chip select for SD card and display. From your problem description also that is the inference..
2024-07-15 03:53 AM
2024-07-15 03:55 AM
could u please help me with this code,
it is compiling but while debugging when i try to press on resume button it will terminate from debug session
2024-07-15 04:15 AM