久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4406|回復: 3
打印 上一主題 下一主題
收起左側

STM32L053R8T6 HAL庫ESP8266 TCP一對多通訊例程

[復制鏈接]
跳轉到指定樓層
樓主
ID:371798 發表于 2018-8-13 10:28 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
    STM32新手根據標準庫改的HAL庫例程,需要的大家可以看看

單片機源程序如下:
  1. //USART2用來ESP8266的收發,實驗時暫時用USART1與電腦相連查看數據
  2. /* Includes ------------------------------------------------------------------*/
  3. #include "main.h"
  4. #include "stm32l0xx_hal.h"
  5. #include "dma.h"
  6. #include "usart.h"
  7. #include "gpio.h"
  8. #include "esp8266/bsp_esp8266.h"


  9. #define User_ESP8266_ApSsid                       "ESP8266test02"               //要創建的熱點的名稱
  10. #define User_ESP8266_ApPwd                        "123456789"           //要創建的熱點的密鑰

  11. #define User_ESP8266_TcpServer_IP                 "192.168.31.230"       //要連接的服務器的 IP
  12. #define User_ESP8266_TcpServer_Port               "8000"                 //要連接的服務器的端口
  13. extern __IO uint8_t ucTcpClosedFlag;
  14. void SystemClock_Config(void);

  15. char APIP[20];
  16. /* USER CODE END 0 */

  17. /**
  18.   * @brief  The application entry point.
  19.   *
  20.   * @retval None
  21.   */
  22. int main(void)
  23. {

  24.   HAL_Init();

  25.   SystemClock_Config();
  26.   MX_GPIO_Init();
  27.   MX_DMA_Init();
  28.   MX_USART2_UART_Init();
  29.   MX_USART1_UART_Init();

  30.          printf("正在配置 ESP8266 ......\n" );
  31.   
  32.   if(ESP8266_AT_Test())
  33.   {
  34.     printf("AT test OK\n");
  35.   }
  36.          printf("\n< 1 >\n");
  37.         if(ESP8266_Net_Mode_Choose(AP))
  38.   {
  39.     printf("ESP8266_Net_Mode_Choose OK\n");
  40.   }  
  41.         printf("\n< 2 >\n");
  42.   if(ESP8266_BuildAP(User_ESP8266_ApSsid,User_ESP8266_ApPwd,WPA2_PSK))
  43.         {
  44.                 printf("ESP8266_BuildAP_OK\n");
  45.         }
  46.         printf("\n< 3 >\n");
  47.         ESP8266_Rst();
  48.         printf("\n< 4 >\n");
  49.         if(ESP8266_Enable_MultipleId(ENABLE))
  50.         {
  51.                 printf("ESP8266_Enable_MultipleId_OK\n");
  52.         }               
  53.         printf("\n< 5 >\n");
  54.         if(ESP8266_StartOrShutServer(ENABLE,"8080","180"))
  55.         {
  56.                 printf("ESP8266_StartOrShutServer_OK\n");
  57.         }
  58.         printf("\n< 6 >\n");
  59.         if(ESP8266_Inquire_ApIp(APIP,20))
  60.         {
  61.                 PC_Usart("%s\n",APIP);
  62.         }
  63.                 printf("\n< 7 >\n");
  64.         
  65.          //HAL_UART_Receive_IT(&huart2,(uint8_t *)ESP8266_ReceiveString(DISABLE),sizeof(ESP8266_ReceiveString(DISABLE)));
  66.   /* Infinite loop */
  67.   /* USER CODE BEGIN WHILE */
  68.   while (1)
  69.   {
  70. //        strEsp8266_Fram_Record.InfBit.FramLength = 0;               //從新開始接收新的數據包
  71. //                        
  72. //        HAL_Delay( 2000 );                 //延時
  73. //        
  74. //        strEsp8266_Fram_Record.Data_RX_BUF[ strEsp8266_Fram_Record.InfBit.FramLength ]  = '\0';
  75. //  /* USER CODE END WHILE */
  76. //  printf("%s\n",strEsp8266_Fram_Record.Data_RX_BUF);
  77. //  /* USER CODE BEGIN 3 */

  78.   }
  79.   /* USER CODE END 3 */

  80. }

  81. /**
  82.   * @brief System Clock Configuration
  83.   * @retval None
  84.   */
  85. void SystemClock_Config(void)
  86. {

  87.   RCC_OscInitTypeDef RCC_OscInitStruct;
  88.   RCC_ClkInitTypeDef RCC_ClkInitStruct;
  89.   RCC_PeriphCLKInitTypeDef PeriphClkInit;

  90.     /**Configure the main internal regulator output voltage
  91.     */
  92.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  93.     /**Initializes the CPU, AHB and APB busses clocks
  94.     */
  95.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  96.   RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
  97.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  98.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  99.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_4;
  100.   RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_2;
  101.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  102.   {
  103.     _Error_Handler(__FILE__, __LINE__);
  104.   }

  105.     /**Initializes the CPU, AHB and APB busses clocks
  106.     */
  107.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  108.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  109.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  110.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  111.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  112.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  113.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  114.   {
  115.     _Error_Handler(__FILE__, __LINE__);
  116.   }

  117.   PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_USART2;
  118.   PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
  119.   PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
  120.   if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  121.   {
  122.     _Error_Handler(__FILE__, __LINE__);
  123.   }

  124.     /**Configure the Systick interrupt time
  125.     */
  126.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  127.     /**Configure the Systick
  128.     */
  129.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

  130.   /* SysTick_IRQn interrupt configuration */
  131.   HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  132. }

  133. /**
  134.   * 函數功能: 串口接收完成回調函數
  135.   * 輸入參數: 無
  136.   * 返 回 值: 無
  137.   * 說    明:無
  138.   */
  139. void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
  140. {
  141.   if(strEsp8266_Fram_Record.InfBit.FramLength<(RX_BUF_MAX_LEN-1))                       //預留1個字節寫結束符
  142.     strEsp8266_Fram_Record.Data_RX_BUF[strEsp8266_Fram_Record.InfBit.FramLength++]=esp8266_rxdata;
  143.   HAL_UART_Receive_IT(&huart2,&esp8266_rxdata,1);
  144. }


  145. /**
  146.   * @brief  This function is executed in case of error occurrence.
  147.   * @param  file: The file name as string.
  148.   * @param  line: The line in file as a number.
  149.   * @retval None
  150.   */
  151. void _Error_Handler(char *file, int line)
  152. {
  153.   /* USER CODE BEGIN Error_Handler_Debug */
  154.   /* User can add his own implementation to report the HAL error return state */
  155.   while(1)
  156.   {
  157.   }
  158.   /* USER CODE END Error_Handler_Debug */
  159. }

  160. #ifdef  USE_FULL_ASSERT
  161. /**
  162.   * @brief  Reports the name of the source file and the source line number
  163. ……………………

  164. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼

所有資料51hei提供下載:
esp8266主機配置.7z (2.7 MB, 下載次數: 100)



分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏6 分享淘帖 頂1 踩
回復

使用道具 舉報

沙發
ID:365724 發表于 2019-3-5 16:33 | 只看該作者
有用,謝謝分享
回復

使用道具 舉報

板凳
ID:484995 發表于 2019-3-5 16:47 | 只看該作者
多謝收下
回復

使用道具 舉報

地板
ID:513084 發表于 2019-4-15 21:04 | 只看該作者
參考一下
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产乱码精品1区2区3区 | zzzwww在线看片免费 | 亚洲一区二区电影网 | 国产美女在线观看 | www.4虎影院 国产999精品久久久影片官网 | 日日草夜夜草 | 亚洲国产精品久久久久久 | 99精品网站 | 在线中文视频 | 95国产精品 | 精品99久久久久久 | 久久99精品久久久久蜜桃tv | 一区二区免费视频 | 亚洲综合天堂 | aaa一区 | 久久久成人精品 | 亚洲国产精品99久久久久久久久 | 蜜臀网站 | 精品久久久久久国产 | 亚洲综合久久久 | 久久久91 | 日本午夜视频 | 91精品久久久久久久久久入口 | 欧美三区视频 | www中文字幕 | 欧美高清视频一区 | 日韩有码一区 | 四虎影院免费在线播放 | 黄a免费网络 | 九九成人| 黑人性hd| 天天爱爱网 | 欧美在线视频a | 日本不卡一区 | 亚洲一区欧美一区 | 羞羞视频在线观看 | 欧美精品一区二区三区蜜桃视频 | 久久久99国产精品免费 | 亚洲国产精久久久久久久 | 国产成人在线播放 | 九色国产 |