当前位置:   article > 正文

STM32+ESP8266+7脚oled屏幕连接心知天气_esp8266 oled

esp8266 oled

一、硬件准备

我这里用到了stm32f103c8t6、esp8266、7脚0.96寸oled屏幕。

二、stm32连接oled屏幕

我这里借鉴了大神得stm32连接oled屏幕0.96寸 OLED 驱动,HAL库+SPI,集合了网上所有好用的函数,测试过。解决花屏问题。_c51 oled0.96 spi驱动-CSDN博客

我这里用得是7脚得oled、他们得引脚有(需要了解更多看数据手册):

GND电源地
VCC3.3v电源
D0时钟总线
D1数据总线
RES复位
DC数据/命令选项
CS片选

我使用的是通过硬件spi来控制oled屏幕,使用时先配置HAL库,我使用的SPI1,板子上学显示3个绿色引脚,分别是SCK、MISO、MOSI,他们的作用是SCK控制时钟线、MISO是在主机这边是输入,在从机那边是输出、MOSI是在主机这边是输出,在从机那边是输入。使用D0连接SCK、D1连接MOSI。其他的RES、DC、CS都随便连接、配置成GPIO推挽输出。以下是HAL库配置。

后面就是配置时钟这些简单,随便就能找到。上面有大神的链接,可以用它的代码、将他的引脚号改成自己的引脚号就能正常的驱动oled屏幕了,其实很简单的,多少也会遇到坑。

三、esp8266连接wifi发送AT指令

这个我上个文章写了就不说了我吧连接发出来esp8266连接心知天气_esp8266天气-CSDN博客、写的不是很好,请谅解我还是一个萌新。

四、通过stm32通过串口给esp8266发送AT指令

最先需要打开2个串口、一个串口是负责给esp8266发送AT指令、另一个串口是来打印esp8266返回的数据。先配置hal库、需要打开2个串口,还有启动串口中断、这个都很简单我就懒得贴图了,接线也很简单也不想说了返回的数据是json格式需要解析一下,在网上找json的包,。现在到了最激动的时候了写代码了。

main.c

  1. #include "main.h"
  2. #include "dma.h"
  3. #include "rtc.h"
  4. #include "spi.h"
  5. #include "usart.h"
  6. #include "gpio.h"
  7. #include "stdio.h"
  8. #include "oled.h"
  9. #include "string.h"
  10. #include "stdlib.h"
  11. #include "time_data.h"
  12. #include "cJSON.h"
  13. #include "bmp.h"
  14. /* Private includes ----------------------------------------------------------*/
  15. /* USER CODE BEGIN Includes */
  16. /* USER CODE END Includes */
  17. /* Private typedef -----------------------------------------------------------*/
  18. /* USER CODE BEGIN PTD */
  19. /* USER CODE END PTD */
  20. /* Private define ------------------------------------------------------------*/
  21. /* USER CODE BEGIN PD */
  22. /* USER CODE END PD */
  23. /* Private macro -------------------------------------------------------------*/
  24. /* USER CODE BEGIN PM */
  25. /* USER CODE END PM */
  26. /* Private variables ---------------------------------------------------------*/
  27. /* USER CODE BEGIN PV */
  28. /* USER CODE END PV */
  29. /* Private function prototypes -----------------------------------------------*/
  30. void SystemClock_Config(void);
  31. uint8_t Weather_analysis(uint8_t* buff,uint8_t *Weather_stat,uint8_t *datas);
  32. /* USER CODE BEGIN PFP */
  33. uint8_t WIFI_Connect[64];
  34. uint8_t Know_Customer_Service[64];
  35. uint8_t Transparent_Transmission[64];
  36. uint8_t get[254];
  37. uint8_t Number;
  38. uint8_t rxBuffers[1];
  39. uint8_t rxBuffer[MAX_RX_BUFFER_SIZE];
  40. uint32_t rxBufferIndex = 0;
  41. uint8_t rxflang=0;
  42. char buffs[64];
  43. uint8_t buff_data[1024];
  44. uint8_t buff_data_cp[562];
  45. /* USER CODE END PFP */
  46. uint16_t My_Time[] = {0, 0, 0, 0, 0, 0}; //年月日时分秒
  47. int week; //温度
  48. char celsius_symbol[] = {0xE2, 0x84, 0x83, '\0'}; // 摄氏度符号的UTF-8编码
  49. char* temperature;
  50. /* USER CODE END PFP */
  51. /* Private user code ---------------------------------------------------------*/
  52. /* USER CODE BEGIN 0 */
  53. /* USER CODE END 0 */
  54. /**
  55. * @brief The application entry point.
  56. * @retval int
  57. */
  58. int main(void)
  59. {
  60. /* USER CODE BEGIN 1 */
  61. /* USER CODE END 1 */
  62. /* MCU Configuration--------------------------------------------------------*/
  63. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  64. HAL_Init();
  65. /* USER CODE BEGIN Init */
  66. /* USER CODE END Init */
  67. /* Configure the system clock */
  68. SystemClock_Config();
  69. /* USER CODE BEGIN SysInit */
  70. /* USER CODE END SysInit */
  71. /* Initialize all configured peripherals */
  72. MX_GPIO_Init();
  73. MX_DMA_Init();
  74. MX_SPI1_Init();
  75. MX_USART1_UART_Init();
  76. MX_USART3_UART_Init();
  77. MX_RTC_Init();
  78. /* USER CODE BEGIN 2 */
  79. OLED_Init();
  80. OLED_ColorTurn(1);
  81. OLED_Refresh();
  82. OLED_ShowChinese(0,0,16,(uint8_t *)"楷体测试",1);
  83. //OLED_ShowString(0,24,16,"Load...");
  84. OLED_Refresh();
  85. HAL_Delay(200);
  86. OLED_Clear(1);
  87. HAL_UART_Receive_IT(&huart1, (uint8_t*)&rxBuffers, 1); //打开串口3的串口中断
  88. Number=0;
  89. HAL_UART_Transmit(&huart1,(uint8_t*)AT,strlen(AT),HAL_MAX_DELAY); //发送AT测试
  90. HAL_Delay(200);
  91. HAL_UART_Transmit(&huart1,(uint8_t*)WiFi_Mode,strlen(WiFi_Mode),HAL_MAX_DELAY); //配置STA模式
  92. HAL_Delay(200);
  93. sprintf(WIFI_Connect,"AT+CWJAP=\"%s\",\"%s\"\r\n",ssid,pass); //连接wifi
  94. HAL_UART_Transmit(&huart1,(uint8_t*)WIFI_Connect,strlen(WIFI_Connect),HAL_MAX_DELAY);
  95. HAL_Delay(1500);
  96. HAL_UART_Transmit(&huart1,(uint8_t*)SET_TIME,strlen(SET_TIME),HAL_MAX_DELAY); //设置时区
  97. HAL_Delay(200);
  98. HAL_UART_Transmit(&huart1,(uint8_t*)GET_TIME,strlen(GET_TIME),HAL_MAX_DELAY); //获取时间
  99. HAL_Delay(200);
  100. sprintf(Know_Customer_Service,"AT+CIPSTART=\"%s\",\"%s\",\%d\r\n",tcp,site,port); //连接心知天气服务端
  101. HAL_UART_Transmit(&huart1,(uint8_t*)Know_Customer_Service,strlen(Know_Customer_Service),HAL_MAX_DELAY);
  102. HAL_Delay(1000);
  103. sprintf(Transparent_Transmission,"AT+CIPMODE=\%d\r\n",1); //开启透传模式
  104. HAL_UART_Transmit(&huart1,(uint8_t*)Transparent_Transmission,strlen(Transparent_Transmission),HAL_MAX_DELAY);
  105. HAL_Delay(200);
  106. HAL_UART_Transmit(&huart1,(uint8_t*)Start_Data,strlen(Start_Data),HAL_MAX_DELAY); //开始发送数据
  107. HAL_Delay(200);
  108. //https://api.seniverse.com/v3/weather/daily.json?key=%s&&location=chengdu&language=en&unit=c&start=-1&days=2
  109. //https://api.seniverse.com/v3/weather/now.json?key=%s&location=chengdu&language=en&unit=c
  110. sprintf(get,"GET https://api.seniverse.com/v3/weather/now.json?key=%s&location=chengdu&language=en&unit=c\r\n",Keys); //获取json数据
  111. HAL_UART_Transmit(&huart1,(uint8_t*)get,strlen(get),HAL_MAX_DELAY);
  112. HAL_Delay(1000);
  113. HAL_UART_Transmit(&huart1,(uint8_t*)quit,strlen(quit),HAL_MAX_DELAY); //退出发送模式
  114. HAL_Delay(200);
  115. //HAL_UART_Transmit(&huart3,(uint8_t*)&rxBuffer,strlen(rxBuffer)* sizeof(char),HAL_MAX_DELAY);
  116. int length = sizeof(rxBuffer) / sizeof(rxBuffer[0]);
  117. int nuber;
  118. //获取时间
  119. for(int i=0;i<length;i++){
  120. if(rxBuffer[i]=='?'){
  121. nuber=i+16;
  122. for(int j=0;j<24;j++){
  123. buffs[j]=rxBuffer[nuber++];
  124. }
  125. }
  126. }
  127. //HAL_UART_Transmit(&huart3,(uint8_t*)&buffs,strlen(buffs)* sizeof(char),HAL_MAX_DELAY);
  128. HAL_Delay(10);
  129. //***********************************************提取JSON数据
  130. int number_cp;
  131. int num;
  132. int f;
  133. for(int z=0;z<strlen(rxBuffer) * sizeof(char);z++){
  134. if(rxBuffer[z]=='{'){
  135. number_cp=strlen(rxBuffer) * sizeof(char)-z;
  136. num=z;
  137. for(int f=0;f<number_cp;f++){
  138. buff_data[f]=rxBuffer[num];
  139. num++;
  140. }
  141. break;
  142. }
  143. //buff_data[z]=rxBuffer[z];
  144. }
  145. //printf("复制:%s\r\n",rxBuffer);
  146. //printf("数据:%s\r\n",buff_data);
  147. //************************************************获取年月日时分秒
  148. My_Time[0]=Year_Init(buffs,20,24); //年
  149. My_Time[1]=Month_Init(buffs,4,6); //月
  150. My_Time[2]=Day_Time_Init(buffs,8,9); //日
  151. My_Time[3]=Day_Time_Init(buffs,11,12); //时
  152. My_Time[4]=Day_Time_Init(buffs,14,15); //分
  153. My_Time[5]=Day_Time_Init(buffs,17,18); //秒
  154. week=calculateWeekday(My_Time[0],My_Time[1],My_Time[2]); //星期
  155. //HAL_UART_Transmit(&huart3,(uint8_t*)&My_Time,strlen(My_Time)* sizeof(char),HAL_MAX_DELAY);
  156. /*printf("年:%d\r\n",My_Time[0]);
  157. printf("月:%d\r\n",My_Time[1]);
  158. printf("日:%d\r\n",My_Time[2]);
  159. printf("时:%d\r\n",My_Time[3]);
  160. printf("分:%d\r\n",My_Time[4]);
  161. printf("秒:%d\r\n",My_Time[5]);
  162. printf("星期%d\r\n",My_Time[6]);
  163. printf("第一次:%s\r\n",buffs);*/
  164. //HAL_UART_Transmit(&huart1,(uint8_t*)at_cmd,strlen(at_cmd),HAL_MAX_DELAY);
  165. //HAL_Delay(200);
  166. cJSON *json;
  167. /* USER CODE END 2 */
  168. /* Infinite loop */
  169. /* USER CODE BEGIN WHILE */
  170. while (1)
  171. {
  172. //***********************************JSON解析数 据
  173. cJSON *root =cJSON_Parse((char*)buff_data);//读取心知天气回调包
  174. printf("数据1:%s\r\n",buff_data);
  175. //printf("数据2:%s\r\n",text);
  176. if (root == NULL) {
  177. const char *error_ptr = cJSON_GetErrorPtr();
  178. if (error_ptr != NULL) {
  179. printf("错误: %s\n", error_ptr);
  180. } else {
  181. printf("解析JSON出现未知错误.\n");
  182. }
  183. } else {
  184. printf("JSON 解析成功.\n");
  185. }
  186. cJSON *array =cJSON_GetObjectItem(root,"results");//读取关键字
  187. cJSON *results0=cJSON_GetArrayItem(array,0);//判断位置
  188. cJSON *location =cJSON_GetObjectItem(results0,"location");//读取关键字
  189. cJSON *now =cJSON_GetObjectItem(results0,"now");//读取关键字
  190. cJSON *name_item= cJSON_GetObjectItem(now, "text");//状态
  191. cJSON *tem_item=cJSON_GetObjectItem(now,"temperature"); //温度
  192. temperature=tem_item->valuestring;
  193. HAL_Delay(1000);
  194. if(My_Time[5]==59){ //秒
  195. My_Time[5]=0;
  196. My_Time[4]+=1;
  197. if(My_Time[4]==60){ //分
  198. My_Time[4]=0;
  199. My_Time[3]+=1;
  200. if(My_Time[3]==24){ //时
  201. My_Time[3]=0;
  202. //启动看门狗让硬件复位
  203. }
  204. }
  205. } else{
  206. My_Time[5]+=1;
  207. }
  208. printf("时间:%d\r\n",My_Time[3]);
  209. if(My_Time[3]>=0&&My_Time[3]<2){
  210. OLED_ShowChinese(94,28,16,"凌晨",0);
  211. }else if(My_Time[3]>=2&&My_Time[3]<6){
  212. OLED_ShowChinese(94,28,16,"深夜",0);
  213. }else if(My_Time[3]>=6&&My_Time[3]<10){
  214. OLED_ShowChinese(94,28,16,"早晨",0);
  215. }else if(My_Time[3]>=10&&My_Time[3]<13){
  216. OLED_ShowChinese(94,28,16,"中午",0);
  217. }else if(My_Time[3]>=13&&My_Time[3]<17){
  218. OLED_ShowChinese(94,28,16,"下午",0);
  219. }else if(My_Time[3]>=17&&My_Time[3]<19){
  220. OLED_ShowChinese(94,28,16,"傍晚",0);
  221. }else if(My_Time[3]>=19&&My_Time[3]<0){
  222. OLED_ShowChinese(94,28,16,"晚上",0);
  223. }
  224. //年月日
  225. OLED_ShowNum01(1,0,16,My_Time[0],4);
  226. OLED_ShowChar(35,0,16,'.',1);
  227. OLED_ShowNum01(41,0,16,My_Time[1],2);
  228. OLED_ShowChar(57,0,16,'.',1);
  229. OLED_ShowNum01(61,0,16,My_Time[2],2);
  230. OLED_ShowChinese(94,0,16,"成都",0);
  231. //时钟
  232. //printf("%d:%d:%d\r\n",My_Time[3],My_Time[4],My_Time[5]);
  233. OLED_ShowChar(23,24,16,':',1);
  234. OLED_ShowChar(50,24,16,':',1);
  235. OLED_ShowNum01(3,21,24,My_Time[3],2);
  236. OLED_ShowNum01(31,21,24,My_Time[4],2);
  237. OLED_ShowNum01(58,21,24,My_Time[5],2);
  238. //星期
  239. OLED_ShowChinese(80,48,16,"星期",0);
  240. if(week==1){
  241. OLED_ShowChinese(108,48,16,"一",0);
  242. }else if(week==2){
  243. OLED_ShowChinese(112,48,16,"二",0);
  244. }else if(week==3){
  245. OLED_ShowChinese(112,48,16,"三",0);
  246. }else if(week==4){
  247. OLED_ShowChinese(112,48,16,"四",0);
  248. }else if(week==5){
  249. OLED_ShowChinese(112,48,16,"五",0);
  250. }else if(week==6){
  251. OLED_ShowChinese(112,48,16,"六",0);
  252. }else if(week==0){
  253. OLED_ShowChinese(112,48,16,"天",0);
  254. }
  255. if(name_item != NULL && strcmp(name_item->valuestring, "Cloudy") == 0){
  256. OLED_ShowChinese(42,48,16,"多云",0);
  257. }else if(name_item != NULL && strcmp(name_item->valuestring, "Foggy") == 0){
  258. OLED_ShowChinese(42,48,16,"多雾",0);
  259. }
  260. OLED_ShowNum01(3,48,16,atoi(temperature),2);
  261. OLED_ShowChinese(19,48,16,"°",0);
  262. OLED_ShowChar(26,48,16,'C',1);
  263. OLED_Refresh();
  264. cJSON_Delete(root);//释放json
  265. //获取心知天气
  266. //char *buff_datajson = "{\"results\":[{\"location\":{\"id\":\"WM6N2PM3WY2K\",\"name\":\"Chengdu\",\"country\":\"CN\",\"path\":\"Chengdu,Chengdu,Sichuan,China\",\"timezone\":\"Asia/Shanghai\",\"timezone_offset\":\"08:00\"},\"now\":{\"text\":\"Cloudy\",\"code\":\"4\",\"temperature\":\"18\"},\"last_update\":\"2024-03-25T22:32:49+08:00\"}]}";
  267. //char *json_data = "{\"results\":[{\"location\":{\"id\":\"WM7V66VSE5DV\",\"name\":\"Guangan\",\"country\":\"CN\",\"path\":\"Guangan,Guangan,Sichuan,China\",\"timezone\":\"Asia/Shanghai\",\"timezone_offset\":\"+08:00\"},\"daily\":[{\"date\":\"2022-07-28\",\"text_day\":\"Sunny\",\"code_day\":\"0\",\"text_night\":\"Clear\",\"code_night\":\"1\",\"high\":\"34\",\"low\":\"24\",\"rainfall\":\"0.00\",\"precip\":\"0.00\",\"wind_direction\":\"SW\",\"wind_direction_degree\":\"225\",\"wind_speed\":\"8.4\",\"wind_scale\":\"2\",\"humidity\":\"87\"},{\"date\":\"2022-07-29\",\"text_day\":\"Sunny\",\"code_day\":\"0\",\"text_night\":\"Cloudy\",\"code_night\":\"4\",\"high\":\"38\",\"low\":\"25\",\"rainfall\":\"0.00\",\"precip\":\"0.00\",\"wind_direction\":\"CLM\",\"wind_direction_degree\":\"\",\"wind_speed\":\"8.4\",\"wind_scale\":\"2\",\"humidity\":\"81\"},{\"date\":\"2022-07-30\",\"text_day\":\"Cloudy\",\"code_day\":\"4\",\"text_night\":\"Cloudy\",\"code_night\":\"4\",\"high\":\"37\",\"low\":\"25\",\"rainfall\":\"0.00\",\"precip\":\"0.00\",\"wind_direction\":\"CLM\",\"wind_direction_degree\":\"\",\"wind_speed\":\"3.0\",\"wind_scale\":\"1\",\"humidity\":\"78\"}],\"last_update\":\"2022-07-28T08:00:00+08:00\"}]}";
  268. //printf("%s\r\n",text);
  269. //printf("数据:%s\r\n",buff_data);
  270. /* USER CODE END WHILE */
  271. /* USER CODE BEGIN 3 */
  272. }
  273. /* USER CODE END 3 */
  274. }
  275. /**
  276. * @brief System Clock Configuration
  277. * @retval None
  278. */
  279. void SystemClock_Config(void)
  280. {
  281. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  282. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  283. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  284. /** Initializes the RCC Oscillators according to the specified parameters
  285. * in the RCC_OscInitTypeDef structure.
  286. */
  287. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  288. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  289. RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  290. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  291. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  292. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  293. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  294. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  295. {
  296. Error_Handler();
  297. }
  298. /** Initializes the CPU, AHB and APB buses clocks
  299. */
  300. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  301. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  302. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  303. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  304. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  305. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  306. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  307. {
  308. Error_Handler();
  309. }
  310. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
  311. PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV128;
  312. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  313. {
  314. Error_Handler();
  315. }
  316. }
  317. /* USER CODE BEGIN 4 */
  318. void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
  319. //HAL_UART_Transmit(&huart2,&rdata,1,0xffff);
  320. if (huart->Instance == USART1) {
  321. // 接收到一个字节的数据
  322. rxBuffer[rxBufferIndex++] = rxBuffers[0];
  323. if(rxflang==0){
  324. if(rxBuffers[0]=='\n'){
  325. rxBufferIndex=0;
  326. //HAL_UART_Transmit(&huart3,(uint8_t*)&rxBuffer,strlen(rxBuffer)* sizeof(char),HAL_MAX_DELAY);
  327. rxflang=1;
  328. }
  329. }
  330. // 处理接收到的数据,例如打印或解析数据
  331. // ...
  332. //printf("%s\r\n",rxBuffer);
  333. //printf("%d\r\n",rxBufferIndex);
  334. // 继续接收数据
  335. HAL_UART_Receive_IT(&huart1,(uint8_t*)&rxBuffers, 1);
  336. }
  337. }
  338. /* USER CODE END 4 */
  339. /**
  340. * @brief This function is executed in case of error occurrence.
  341. * @retval None
  342. */
  343. void Error_Handler(void)
  344. {
  345. /* USER CODE BEGIN Error_Handler_Debug */
  346. /* User can add his own implementation to report the HAL error return state */
  347. __disable_irq();
  348. while (1)
  349. {
  350. }
  351. /* USER CODE END Error_Handler_Debug */
  352. }
  353. #ifdef USE_FULL_ASSERT
  354. /**
  355. * @brief Reports the name of the source file and the source line number
  356. * where the assert_param error has occurred.
  357. * @param file: pointer to the source file name
  358. * @param line: assert_param error line source number
  359. * @retval None
  360. */
  361. void assert_failed(uint8_t *file, uint32_t line)
  362. {
  363. /* USER CODE BEGIN 6 */
  364. /* User can add his own implementation to report the file name and line number,
  365. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  366. /* USER CODE END 6 */
  367. }
  368. #endif /* USE_FULL_ASSERT */

main.h

  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.h
  5. * @brief : Header for main.c file.
  6. * This file contains the common defines of the application.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * Copyright (c) 2024 STMicroelectronics.
  11. * All rights reserved.
  12. *
  13. * This software is licensed under terms that can be found in the LICENSE file
  14. * in the root directory of this software component.
  15. * If no LICENSE file comes with this software, it is provided AS-IS.
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Define to prevent recursive inclusion -------------------------------------*/
  21. #ifndef __MAIN_H
  22. #define __MAIN_H
  23. #define AT "AT\r\n"
  24. #define WiFi_Mode "AT+CWMODE=1\r\n"
  25. #define ssid "wifi账号"
  26. #define pass "wifi密码"
  27. #define SET_TIME "AT+CIPSNTPCFG=1,8\r\n"
  28. #define GET_TIME "AT+CIPSNTPTIME?\r\n"
  29. #define MAX_RX_BUFFER_SIZE 6553
  30. #define tcp "TCP"
  31. #define site "api.seniverse.com"
  32. #define port 80
  33. #define Start_Data "AT+CIPSEND\r\n"
  34. #define Keys "私钥"
  35. #define quit "+++"
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. /* Includes ------------------------------------------------------------------*/
  40. #include "stm32f1xx_hal.h"
  41. /* Private includes ----------------------------------------------------------*/
  42. /* USER CODE BEGIN Includes */
  43. /* USER CODE END Includes */
  44. /* Exported types ------------------------------------------------------------*/
  45. /* USER CODE BEGIN ET */
  46. /* USER CODE END ET */
  47. /* Exported constants --------------------------------------------------------*/
  48. /* USER CODE BEGIN EC */
  49. /* USER CODE END EC */
  50. /* Exported macro ------------------------------------------------------------*/
  51. /* USER CODE BEGIN EM */
  52. /* USER CODE END EM */
  53. /* Exported functions prototypes ---------------------------------------------*/
  54. void Error_Handler(void);
  55. /* USER CODE BEGIN EFP */
  56. /* USER CODE END EFP */
  57. /* Private defines -----------------------------------------------------------*/
  58. #define OLED_CS_Pin GPIO_PIN_4
  59. #define OLED_CS_GPIO_Port GPIOA
  60. #define OLED_RES_Pin GPIO_PIN_0
  61. #define OLED_RES_GPIO_Port GPIOB
  62. #define OLED_DC_Pin GPIO_PIN_1
  63. #define OLED_DC_GPIO_Port GPIOB
  64. /* USER CODE BEGIN Private defines */
  65. /* USER CODE END Private defines */
  66. #ifdef __cplusplus
  67. }
  68. #endif
  69. #endif /* __MAIN_H */

usart.c添加代码

  1. int fputc(int ch,FILE *f)
  2. {
  3. HAL_UART_Transmit(&huart3 , (uint8_t *)&ch , 1 , 0xffff);
  4. return ch;
  5. }

五、成果展示

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/687883
推荐阅读
相关标签
  

闽ICP备14008679号