STM32F429 ESP8266 ile ALINAN VERİYİ EKRANA BASMAK !!!!

Başlatan KingSlayyer, 12 Şubat 2020, 16:47:00

KingSlayyer

Cümleten Selamın Aleyküm. Konuda da belirttiğim gibi bir türlü esp8266dan aldığım veriyi ekrana basamıyorum. Web server üzerinden LEDleri yakabiliyorum Ekranda bazı değişiklikler yapabiliyorum fakat web serverdan gönderdiğim renk kodlarını ekrana basamıyorum. Bu konuda lütfen yardımcı olur musunuz ?





#include "stm32f4xx.h"                  
#include "stdio.h"
#include "string.h"
#include "stm32f429i_discovery.h"
#include "stm32f429i_discovery_lcd.h"
#include "defines.h"
#include "tm_stm32f4_ili9341.h"
#include "tm_stm32f4_fonts.h"
#include "tm_stm32f4_delay.h"
#include <stdio.h>
#include "a111.h"

#define BOYUT 76800

void USART_Initialize(void);
void USART1_IRQHandler(void);
void USART_Puts(USART_TypeDef* USARTx, volatile char *s);
void LED_Initialize(void);
static void ESP8266_Init(void);
static void Clear_ESPBuffer(void);
void delay(uint32_t x);
void ResetPin_ESP8266(void);
void LCD_Yaz(uint8_t Color);


char ESP8266Buf[BOYUT];
static uint16_t ESPWriteIndex = 0;
static uint8_t receive_data;
char htmlcode[10000];
char str[10000];
char str2[1000];
char str3[5000];
int uzunluk;


int main()
{
         
  //LCD_Init(); 
  
  LCD_LayerInit();
 
  /* Reload configuration of Layer1 */
  //LTDC_ReloadConfig(LTDC_IMReload);
  
  //LTDC_Cmd(ENABLE);  
  
 // LCD_SetLayer(LCD_FOREGROUND_LAYER); 
  
  //LCD_DisplayOn();
  
  //LCD_Clear(0xFFFF);
  
  //LCD_SetFont(&Font8x8);
  
  /* Initialize system */
	SystemInit();
	
	/* Initialize delay */
	TM_DELAY_Init();
		
	/* Initialize ILI9341 */
	TM_ILI9341_Init();
        
        TM_ILI9341_Rotate(TM_ILI9341_Orientation_Portrait_2);
        
        TM_ILI9341_Fill(ILI9341_COLOR_MAGENTA);
  
  
  
	USART_Initialize();
	LED_Initialize();
	ResetPin_ESP8266();
	Clear_ESPBuffer();
	
	while(1)
	{
        
		ESP8266_Init();
	}
}

static void ESP8266_Init(void)
{
	
	static uint8_t ESPInitCase = 0;
	
	switch(ESPInitCase)
	{
		case 0 :
			
		   USART_Puts(USART1, "AT\r\n");
		   delay(1500000);
		   ESPInitCase = 1;
		   break;
		
		case 1 :
			
		   if(strstr(ESP8266Buf,"OK") != NULL)
			 {
				 Clear_ESPBuffer();
				 USART_Puts(USART3, "Module Erisildi\n");
                                 LCD_SetTextColor(LCD_COLOR_BLACK); 
                                 LCD_DisplayStringLine(LCD_LINE_2, (uint8_t*)" Module Erisildi ");
                                 TM_ILI9341_Puts(5, 20, "Module Erisildi", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_BLUE2);
				 ESPInitCase = 2;
			 }
			 else
			 {
				 Clear_ESPBuffer();
				 USART_Puts(USART3, "Module Erisilemedi, Tekrar Deneniyor\n");
                                 LCD_SetTextColor(LCD_COLOR_BLACK); 
                                 LCD_DisplayStringLine(LCD_LINE_2, (uint8_t*)" Module Erisilemedi, Tekrar Deneniyor ");
				 ESPInitCase = 0;
			 }
			 break;
			 
		case 2 :
			
		   USART_Puts(USART1, "AT+CWMODE?\r\n");
		   delay(1500000);
	     ESPInitCase = 3;
		   break;
		
		case 3 :
			
		   if(strstr(ESP8266Buf, "+CWMODE:1") != NULL)
			 {
				 Clear_ESPBuffer();
				 USART_Puts(USART3, "STA Modunda, Ayar Dogru\n");
                                 LCD_SetTextColor(LCD_COLOR_BLACK); 
                                 LCD_DisplayStringLine(LCD_LINE_8, (uint8_t*)" STA Modunda, Ayar Dogru ");
                                 TM_ILI9341_Puts(5, 80, "STA Modunda, Ayar Dogru", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_BLUE2);
				 ESPInitCase = 4;
			 }
			 else
			 {
				 USART_Puts(USART1, "AT+CWMODE=1\r\n");
				 delay(1500000);
				 Clear_ESPBuffer();
				 USART_Puts(USART3, "Mode Degistirildi\n");
                                 LCD_SetTextColor(LCD_COLOR_BLACK); 
                                 LCD_DisplayStringLine(LCD_LINE_8, (uint8_t*)" Mode Degistirildi ");
				 ESPInitCase = 2;
			 }
			 break;
			 
		case 4 :
		   
	           USART_Puts(USART1, "AT+CWJAP=\"TurkTelekom_TA1C5\",\"11111111\"\r\n");
		   delay(6000000);
		   ESPInitCase = 5;
		   break;
		
		case 5 :
			
		   if(strstr(ESP8266Buf, "OK") != NULL)
			 {
				 Clear_ESPBuffer();
				 USART_Puts(USART3, "Modeme Baglanildi\n");
                                 LCD_SetTextColor(LCD_COLOR_BLACK); 
                                 LCD_DisplayStringLine(LCD_LINE_14, (uint8_t*)" Modeme Baglanildi ");
                                 TM_ILI9341_Puts(5, 140, "Modeme Baglanildi", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_BLUE2);
				 ESPInitCase = 6;
			 }
			 else
			 {
				 USART_Puts(USART3, "Modeme Baglanti Bekleniyor...\n");
                                 LCD_SetTextColor(LCD_COLOR_BLACK); 
                                 LCD_DisplayStringLine(LCD_LINE_14, (uint8_t*)" Modeme Baglanti Bekleniyor ");
				 delay(15000000); 
			 } 
			 break;
			 
		case 6 :
			  
		   USART_Puts(USART1, "AT+CIPMUX=1\r\n");
		   delay(1500000);
                   USART_Puts(USART1,"AT+CIFSR\r\n");
            // 1 saniye gecikme koyuyoruz.
            delay(1500000);
            
		   ESPInitCase = 7;
		   break;
		
		case 7 :
			
		   if(strstr(ESP8266Buf, "OK") != NULL)
			 {
                                 
				 Clear_ESPBuffer();
				 USART_Puts(USART3, "CIPMUX=1 Yapildi\n");
                                 LCD_SetTextColor(LCD_COLOR_BLACK); 
                                 LCD_DisplayStringLine(LCD_LINE_20, (uint8_t*)" CIPMUX=1 Yapildi ");  
                                 TM_ILI9341_Puts(5, 200, "CIPMUX=1 Yapildi", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_BLUE2);
				 ESPInitCase = 8;
			 }
			 else
			 {
				 USART_Puts(USART3, "CIPMUX Ayari Yapilamadi, Tekrar Deneniyor...\n");
                                 LCD_SetTextColor(LCD_COLOR_BLACK); 
                                 LCD_DisplayStringLine(LCD_LINE_20, (uint8_t*)"CIPMUX Ayari Yapilamadi, Tekrar Deneniyor...");
				 delay(6000000);
			 }
			 break;
			 
		case 8 :
			
		   USART_Puts(USART1, "AT+CIPSERVER=1,80\r\n");
		   delay(1500000);
		   ESPInitCase = 9;
		   break;
		
		case 9 :
			
		   if(strstr(ESP8266Buf, "OK") != NULL)
			 {
				 Clear_ESPBuffer();
				 USART_Puts(USART3, "Sunucu 80 Portunda Acildi\n");
                                 LCD_SetTextColor(LCD_COLOR_BLACK); 
                                 LCD_DisplayStringLine(LCD_LINE_26, (uint8_t*)"Sunucu 80 Portunda Acildi");
                                 TM_ILI9341_Puts(5, 260, "Sunucu 80 Portunda Acildi", &TM_Font_7x10, ILI9341_COLOR_BLACK, ILI9341_COLOR_BLUE2);
				 ESPInitCase = 10;
			 }
			 else
			 {
				 USART_Puts(USART3, "Sunucu Acilamadi, Tekrar Deneniyor...\n");
                                 LCD_SetTextColor(LCD_COLOR_BLACK); 
                                 //LCD_DisplayStringLine(LCD_LINE_28, (uint8_t*)"Sunucu Acilamadi, Tekrar Deneniyor...");
				 delay(3000000);
			 }
			 break;
			 
		case 10 :
			
		  if(*ESP8266Buf != 0)
			{
		   if(strstr(ESP8266Buf, "+IPD,") != NULL)
			 {
				 strcpy(htmlcode, "<head><h2> MAHMUT KOCAMAN 140208033</h2> </head><br><head> LED1 </head><a href=\" ?pin=on\"><button type='button' >ON</button></a> <a href=\" ?pin=off\"><button type='button'>OFF</button></a><br><br><head> LED2 </head><a href=\" ?pin2=on\"><button type='button' >ON</button></a> <a href=\" ?pin2=off\"><button type='button'>OFF</button></a><br><br> <!DOCTYPE html><html><body><form action='/action_page.php'>Renk Giriniz:<br><input type='text' name='Color'><br><input type='submit'></form></body></html><html> <body><form action='upload.php' method='post' enctype='multipart/form-data'>Select image to upload:<input type='file' name='fileToUpload' id='fileToUpload'><input type='submit' value='Upload Image' name='submit'></form></body></html><html><body><?phpecho readfile(webdictionary.txt);?></body></html>\r\n");
				 uzunluk = strlen(htmlcode);
				 uzunluk += 2;
				 sprintf(str, "AT+CIPSEND=0,%d\r\n", uzunluk);
				 USART_Puts(USART1, str);
				 delay(6000000);
				 USART_Puts(USART1, htmlcode);
				 delay(6000000);

				 if(strstr(ESP8266Buf, ":GET /?pin=on") != NULL)
				 {
					 GPIO_SetBits(GPIOG, GPIO_Pin_13);
				 }
				 if(strstr(ESP8266Buf, ":GET /?pin=off") != NULL)
				 {
					 GPIO_ResetBits(GPIOG, GPIO_Pin_13);
				 }
                                 if(strstr(ESP8266Buf, ":GET /?pin2=on") != NULL)
				 {
					 GPIO_SetBits(GPIOG, GPIO_Pin_14);
				 }
				 if(strstr(ESP8266Buf, ":GET /?pin2=off") != NULL)
				 {
					 GPIO_ResetBits(GPIOG, GPIO_Pin_14);
				 }
				 if(strstr(ESP8266Buf, ":GET /action_page.php?Color=Daire") != NULL)
				 {
                                   
                                   TM_ILI9341_Fill(ILI9341_COLOR_MAGENTA);
					  
                                   TM_ILI9341_DrawFilledCircle(60, 60, 35, ILI9341_COLOR_RED);
                                          
				 }
                                 if(strstr(ESP8266Buf, ":GET /action_page.php?Color=Dikdortgen") != NULL)
				 {
                                   TM_ILI9341_Fill(ILI9341_COLOR_MAGENTA);
					  TM_ILI9341_DrawFilledRectangle(130, 30, 210, 90, ILI9341_COLOR_BLACK);
				 }
                                 if(strstr(ESP8266Buf, ":GET /action_page.php?Color=Cizgi") != NULL)
				 {
                                   TM_ILI9341_Fill(ILI9341_COLOR_MAGENTA);
					  TM_ILI9341_DrawLine(60, 120, 310, 120, 0x0005);
				 }
                                 if(strstr(ESP8266Buf, "unsigned short") != NULL)
				 {
					int k=0;
		                        for(int x=0;x<320;x++)
		                          {
			                     for(int y=0;y<240;y++)
			                       {
                                                 
				                 TM_ILI9341_DrawPixel(y,x,ESP8266Buf[k]);
				                 k++;
				                 Delay(25);
			                       }
		                          }
				 }
                                 
				 USART_Puts(USART1, "AT+CIPCLOSE=0\r\n");
				 Clear_ESPBuffer();
				 ESPInitCase = 8;
			 }
			 
			 break;
		 } 
	}
}

void USART_Initialize(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	USART_InitTypeDef USART_InitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
	
	GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_9 | GPIO_Pin_10;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; 
	GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP; // AF --> UP Olmali
	GPIO_Init(GPIOA, &GPIO_InitStructure);
	
	GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_10;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; 
	GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP; // AF --> UP Olmali
	GPIO_Init(GPIOB, &GPIO_InitStructure);
	
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource9,  GPIO_AF_USART1);
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource10,  GPIO_AF_USART1);
	GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART3);
	
	USART_InitStructure.USART_BaudRate            = 115200;
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
	USART_InitStructure.USART_Mode                = USART_Mode_Tx | USART_Mode_Rx;
	USART_InitStructure.USART_Parity              = USART_Parity_No;
	USART_InitStructure.USART_StopBits            = USART_StopBits_1;
	USART_InitStructure.USART_WordLength          = USART_WordLength_8b; //Gönderilen Veri 8-Bitlik
	USART_Init(USART1, &USART_InitStructure);
	
	USART_Cmd(USART1, ENABLE);
	
	USART_InitStructure.USART_BaudRate            = 115200;
	USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
	USART_InitStructure.USART_Mode                = USART_Mode_Tx;
	USART_InitStructure.USART_Parity              = USART_Parity_No;
	USART_InitStructure.USART_StopBits            = USART_StopBits_1;
	USART_InitStructure.USART_WordLength          = USART_WordLength_8b; //Gönderilen Veri 8-Bitlik
	USART_Init(USART3, &USART_InitStructure);
	
	USART_Cmd(USART3, ENABLE);
	
	USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

  NVIC_InitStructure.NVIC_IRQChannel                   = USART1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority        = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd                = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}

void USART_Puts(USART_TypeDef* USARTx, volatile char *s)
{
	while(*s)
	{
		while(USART_GetFlagStatus(USARTx, USART_FLAG_TXE) == RESET);
		USART_SendData(USARTx, *s);
		*s++;
	}
}

void USART1_IRQHandler(void)
{
	
	if(USART_GetITStatus(USART1, USART_IT_RXNE))
	{
		USART_ClearITPendingBit(USART1, USART_IT_RXNE);
		
		//uint8_t receive_data;
		
		receive_data = USART1 ->DR;
		USART3 ->DR  = receive_data;
                
		
		if(receive_data != 0)
		{
			ESP8266Buf[ESPWriteIndex] = receive_data;
			ESPWriteIndex++;	
		}			 
	}
}

void LED_Initialize(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE);
	
	GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_13 | GPIO_Pin_14;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOG, &GPIO_InitStructure);	
}

void delay(uint32_t x)
{
	while(x--);
}

static void Clear_ESPBuffer(void)
{
  uint32_t i;
	
   for(i = 0; i < BOYUT; i++)
	 {
     ESP8266Buf[i] = 0;
	 }
		
   ESPWriteIndex = 0;
}

void ResetPin_ESP8266(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
	
	GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_13; 
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
	
  GPIO_ResetBits(GPIOB, GPIO_Pin_13);
}



if(strstr(ESP8266Buf, "unsigned short") != NULL)
				 {
					int k=0;
		                        for(int x=0;x<320;x++)
		                          {
			                     for(int y=0;y<240;y++)
			                       {
                                                 
				                 TM_ILI9341_DrawPixel(y,x,ESP8266Buf[k]);
				                 k++;
				                 Delay(25);
			                       }
		                          }
				 }
                                 

Kodumun bu kısmında ekrana basma işlemini yapmak istiyorum.

KingSlayyer