cancel
Showing results for 
Search instead for 
Did you mean: 

how to interface stm32F302r8 and SD card and tft display and i want to display image on the display using Ard ide

Sharan
Associate III

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);
}
18 REPLIES 18

did you try this suggestion?

If you feel a post has answered your question, please click "Accept as Solution".

try single stepping, first find which functions you are above to step-over.. and pin point where it gets terminated. Then step into the function and identify the illegal instruction... do code read to that area of code.. initially try only to write characters to the screen, then try other advance features. Did you abandon the idea of displaying image from SD card?

To start with the Arduino path may be easier since the libraries are well tested in most of the cases!!!

If you feel a post has answered your question, please click "Accept as Solution".

sure i will try ,i want to make some user interface so i thought of using stm32ide as  it has touch gfx

https://controllerstech.com/st7735-1-8-tft-display-with-stm32/#info_box

If you feel a post has answered your question, please click "Accept as Solution".
https://github.com/timagr615/TFT_ILI9488/blob/master/Core/Src/ili9488.c using this code i am able to display text but not able to display the bmp image could u please look into that void drawImage(const uint8_t* img, uint16_t x, uint16_t y, uint16_t w, uint16_t h) { if ((x >= width) || (y >= height)) return; if ((x + w - 1) >= width) w = width - x; if ((y + h - 1) >= height) h = height - y; setAddrWindow(x, y, x + w - 1, y + h - 1); HAL_GPIO_WritePin(tftDC_GPIO, tftDC_PIN, GPIO_PIN_SET); HAL_GPIO_WritePin(tftCS_GPIO, tftCS_PIN, GPIO_PIN_RESET); uint8_t linebuff[w * 3]; uint32_t count = 0; for (uint16_t i = 0; i < h; i++) { uint16_t pixcount = 0; for (uint16_t o = 0; o < w; o++) { uint8_t b1 = img[count++]; uint8_t b2 = img[count++]; uint16_t color = (b1 << | b2; linebuff[pixcount++] = (((color & 0xF800) >> 11) * 255) / 31; // Red linebuff[pixcount++] = (((color & 0x07E0) >> 5) * 255) / 63; // Green linebuff[pixcount++] = ((color & 0x001F) * 255) / 31; // Blue } HAL_SPI_Transmit(&lcdSPIhandle, linebuff, w * 3, 100); } HAL_GPIO_WritePin(tftCS_GPIO, tftCS_PIN, GPIO_PIN_SET); }
Techn
Senior III

you can create a .h file with uint16_t array of pixels corresponding R5G6B5 or the needed format for your display(refer to datasheet). There are software such as lcd-image-converter.

 

void ST7735_DrawImage(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint16_t* data) {

if((x >= _width) || (y >= _height)) return;

if((x + w - 1) >= _width) return;

if((y + h - 1) >= _height) return;

 

ST7735_Select();

ST7735_SetAddressWindow(x, y, x+w-1, y+h-1);

ST7735_WriteData((uint8_t*)data, sizeof(uint16_t)*w*h);

ST7735_Unselect();

}

If you feel a post has answered your question, please click "Accept as Solution".

hi i am able to display the image ,now i am working on the touch part and i was referring to a youtube video https://youtu.be/g1siKaPox88?si=GkSLNO9t5GLuSTK5  from this video they had given a code and i was able to display but it is showing in gray scale but the touch is working ,in the video they have made a number increment and decrement using buttons in touchgfx designer

GitHub - maudeve-it/ILI9XXX-XPT2046-STM32: A set of function handling SPI, TFT LED 480x320 or 320x240 touch display controlled by an ILI9488 or ILI9341+XPT2046                                                                                                       this is the github link for the code