Build started: Project: 111 *** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\keil5\ARM\ARMCC\Bin' Build target 'Target 1' compiling stm32f10x_it.c... user\stm32f10x_it.c(16): error: #70: incomplete type is not allowed if(rx_index < sizeof(USART_RxBuffer)-1) { user\stm32f10x_it.c: 0 warnings, 1 error compiling main.c... user\main.c(44): error: #165: too few arguments in function call OLED_ShowChar(0, 0, 'T'); // 浣跨敤ASCII瀛楃 user\main.c(45): error: #165: too few arguments in function call OLED_ShowChar(0, 16, 'H'); user\main.c(46): error: #165: too few arguments in function call OLED_ShowChar(64, 16, '%'); user\main.c(47): error: #165: too few arguments in function call OLED_ShowChar(64, 0, 'C'); user\main.c(75): warning: #223-D: function "delay_ms" declared implicitly delay_ms(5000); // 姣?5绉掓洿鏂? user\main.c(56): warning: #177-D: variable "lastSendTime" was declared but never referenced uint32_t lastSendTime = 0; user\main.c: 2 warnings, 4 errors compiling esp8266.c... user\esp8266.c(21): warning: #223-D: function "HAL_GetTick" declared implicitly uint32_t start = HAL_GetTick(); user\esp8266.c(27): warning: #223-D: function "delay_ms" declared implicitly delay_ms(50); user\esp8266.c(82): warning: #223-D: function "sprintf" declared implicitly sprintf(cmd, "AT+CIPSEND=0,%d\r\n", strlen(data)); user\esp8266.c: 3 warnings, 0 errors ".\Objects\project.axf" - 5 Error(s), 5 Warning(s). Target not created. Build Time Elapsed: 00:00:01解决这些程序报错
时间: 2025-07-25 12:31:59 浏览: 33
<think>好的,用户现在遇到了编译错误,需要我帮忙解决。首先,我需要仔细看看这些错误信息。
第一个错误是在stm32f10x_it.c的第16行,提示“incomplete type is not allowed”,这个错误通常是因为结构体或类型没有被正确声明。可能是在某个头文件中缺少了定义,或者USART_RxBuffer的声明有问题。用户可能在某个地方声明了USART_RxBuffer但没有定义,或者定义的位置不对。
接下来是main.c的四个错误,都是关于OLED_ShowChar函数参数太少的问题。这说明OLED_ShowChar的原型可能需要更多的参数,比如字体大小或其他设置,但用户调用时只传了三个参数。用户可能修改了代码中的显示函数,但没有更新对应的函数声明。
还有两个警告,一个是delay_ms未声明,另一个是变量lastSendTime未使用。另外,esp8266.c中的HAL_GetTick、delay_ms和sprintf也被隐式声明,这可能是因为缺少头文件包含,比如stdio.h或者delay.h。
我需要逐一分析这些错误:
1. **USART_RxBuffer的不完整类型错误**:检查头文件是否正确包含了USART_RxBuffer的定义。用户可能在stm32f10x_it.c中引用了extern uint8_t USART_RxBuffer[];,但在定义的地方可能没有正确声明,或者没有包含对应的头文件。需要确保在使用前正确声明了这个数组。
2. **OLED_ShowChar参数不足**:查看OLED的驱动代码,确认OLED_ShowChar的函数原型需要哪些参数。可能原来的函数需要更多的参数,比如字体类型或大小,而用户调用时遗漏了。例如,可能需要OLED_ShowChar(x, y, c, size)这样的形式,但用户只传了三个参数。
3. **隐式声明的警告**:delay_ms和HAL_GetTick可能没有正确的函数声明。需要检查是否包含了对应的头文件,比如delay.h中是否声明了delay_ms函数,以及是否在main.c中包含了必要的头文件。
4. **未使用的变量lastSendTime**:这个警告可以暂时忽略,或者删除未使用的变量。
接下来,我需要给出具体的修改建议,包括调整函数调用参数、包含必要的头文件、修正变量声明等。同时,要确保所有函数在使用前都有正确的声明,避免隐式声明的问题。对于USART_RxBuffer的问题,需要检查其定义位置,并确保在所有使用的地方都有正确的外部声明。
</think>以下是针对编译错误的详细解决方案:
---
### **1. 错误 `#70: incomplete type is not allowed`**
**错误位置**:`stm32f10x_it.c` 第16行
**原因**:`USART_RxBuffer` 未正确定义或声明。
**修复方法**:
```c
// 在 stm32f10x_it.c 文件顶部添加 USART_RxBuffer 的定义
#include "esp8266.h" // 确保包含定义 USART_RxBuffer 的头文件
```
---
### **2. 错误 `#165: too few arguments in function call`**
**错误位置**:`main.c` 中 `OLED_ShowChar` 调用参数不足
**原因**:`OLED_ShowChar` 函数原型与调用参数不匹配。
**修复方法**:
```c
// 修改 main.c 中的 OLED 显示调用,匹配函数原型
// 假设 OLED_ShowChar 需要第4个参数(字体大小)
OLED_ShowChar(0, 0, 'T', OLED_8X16); // 添加字体参数
OLED_ShowChar(0, 16, 'H', OLED_8X16);
OLED_ShowChar(64, 16, '%', OLED_8X16);
OLED_ShowChar(64, 0, 'C', OLED_8X16);
```
---
### **3. 警告 `#223-D: function "delay_ms" declared implicitly`**
**原因**:未包含 `delay.h` 或 `delay_ms` 未声明。
**修复方法**:
```c
// 在 main.c 和 esp8266.c 顶部添加 delay.h 头文件
#include "delay.h" // 确保 delay_ms 函数已声明
```
---
### **4. 警告 `#223-D: function "HAL_GetTick" declared implicitly`**
**原因**:未包含 `stm32f10x_it.h` 或 `HAL_GetTick` 未声明。
**修复方法**:
```c
// 在 esp8266.c 顶部添加头文件
#include "stm32f10x_it.h" // 包含 HAL_GetTick 的声明
```
---
### **5. 警告 `#223-D: function "sprintf" declared implicitly`**
**原因**:未包含标准库头文件 `stdio.h`。
**修复方法**:
```c
// 在 esp8266.c 顶部添加
#include <stdio.h> // 提供 sprintf 函数声明
```
---
### **完整修复后的代码片段**
#### **stm32f10x_it.c**
```c
#include "stm32f10x_it.h"
#include "esp8266.h" // 确保 USART_RxBuffer 定义在此头文件中
volatile uint32_t sysTickUptime = 0;
// SysTick 中断处理
void SysTick_Handler(void) {
sysTickUptime++;
}
// USART2 中断处理
void USART2_IRQHandler(void) {
static uint8_t rx_index = 0;
if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) {
uint8_t data = USART_ReceiveData(USART2);
if (rx_index < sizeof(USART_RxBuffer)-1) {
USART_RxBuffer[rx_index++] = data;
USART_RxBuffer[rx_index] = '\0'; // 确保字符串结束
}
}
}
// 获取系统时间戳
uint32_t HAL_GetTick(void) {
return sysTickUptime;
}
```
#### **main.c**
```c
#include "stm32f10x.h"
#include "delay.h" // delay_ms 声明
#include "OLED.h" // OLED_ShowChar 声明
#include "dht11.h"
#include "FMQ.h"
#include "Serial.h"
#include "esp8266.h"
#include "stm32f10x_it.h"
// 全局变量
u8 temp, humi;
char wifi_data[64];
int main(void) {
SystemClock_Config();
Delay_Init();
OLED_Init();
DHT11_Init();
mfq_Init();
Serial_Init();
// OLED 初始化显示(注意字体参数)
OLED_ShowChar(0, 0, 'T', OLED_8X16); // 添加字体参数
OLED_ShowChar(0, 16, 'H', OLED_8X16);
OLED_ShowChar(64, 16, '%', OLED_8X16);
OLED_ShowChar(64, 0, 'C', OLED_8X16);
OLED_Update();
// ESP8266 初始化
ESP8266_Init();
printf("ESP8266 AP Mode Ready\r\n");
while (1) {
if (DHT11_Read_Data(&temp, &humi)) {
OLED_ShowNum(47, 0, temp, 2, OLED_8X16);
OLED_ShowNum(47, 16, humi, 2, OLED_8X16);
OLED_Update();
fmq(temp, humi);
sprintf(wifi_data, "Temp:%d,Humi:%d\r\n", temp, humi);
ESP8266_SendData(wifi_data);
}
delay_ms(5000); // 5秒间隔
}
}
```
#### **esp8266.c**
```c
#include "esp8266.h"
#include <stdio.h> // sprintf 声明
#include <string.h>
#include "stm32f10x_usart.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_it.h" // HAL_GetTick 声明
// 发送 AT 指令
void ESP8266_SendCmd(char* cmd, char* resp, uint16_t timeout) {
memset(USART_RxBuffer, 0, sizeof(USART_RxBuffer));
while(*cmd) {
USART_SendData(ESP8266_USARTx, *cmd++);
while(!USART_GetFlagStatus(ESP8266_USARTx, USART_FLAG_TXE));
}
uint32_t start = HAL_GetTick();
while(strstr((char*)USART_RxBuffer, resp) == NULL) {
if(HAL_GetTick() - start > timeout) break;
}
delay_ms(50);
}
// 发送数据到 TCP 客户端
u8 ESP8266_SendData(char* data) {
char cmd[64];
sprintf(cmd, "AT+CIPSEND=0,%d\r\n", strlen(data));
ESP8266_SendCmd(cmd, "OK", 1000);
ESP8266_SendCmd(data, ">", 1000);
USART_SendData(ESP8266_USARTx, 0x1A); // 发送 Ctrl+Z
return 0;
}
```
---
### **其他注意事项**
1. **确保所有头文件路径正确**:检查 Keil 项目中是否包含所有源文件的目录。
2. **函数声明一致性**:检查 `OLED_ShowChar` 和 `delay_ms` 的原型是否与调用参数一致。
3. **未使用变量警告**:删除未使用的 `lastSendTime` 变量以消除警告。
---
### **最终验证步骤**
1. **编译项目**:确保所有错误已修复。
2. **硬件测试**:连接调试器,验证串口输出和 OLED 显示是否正常。
3. **ESP8266 连通性**:通过手机连接 AP 热点,测试 TCP 服务器通信。
阅读全文
相关推荐




















