OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 2607|回复: 3

STM32mini版,写了一个串口的事例,提示Undefined symbol Receive1Byte (referred from main.o).具体如下图所示:

[复制链接]

12

主题

21

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
234
金钱
234
注册时间
2017-7-15
在线时间
16 小时
发表于 2018-6-15 14:20:23 | 显示全部楼层 |阅读模式
main程式如下所示:#include <stm32f10x.h>
#include <string.h>
#include  <stdio.h>
#define USARTmy USART2
#define D2_ON GPIO_ResetBits(GPIOC,GPIO_Pin_8)
#define D2_OFF GPIO_SetBits(GPIOC,GPIO_Pin_8)
#define Max 100
u8 RxBuffer[Max];
u8 TxBuffer[Max];
u8 RxCount=0;
u8 TxCount=0;
typedef enum {ERR=0,OK=!ERR}TXRXstat;
void GPIO_Led_Config(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOC,&GPIO_InitStructure);
        GPIO_SetBits(GPIOC,GPIO_Pin_8);

}

void GPIO_USARTX_Config(USART_TypeDef* USARTx)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        if(USARTx==USART1)
        {
                RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_USART1,ENABLE);
                GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;
                GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
                GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
                GPIO_Init(GPIOA,&GPIO_InitStructure);
               
                GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;
                GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
                GPIO_Init(GPIOA,&GPIO_InitStructure);
  }
        if(USARTx==USART2)
        {
                RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
                RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
               
                GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2;
                GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
                GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
                GPIO_Init(GPIOA,&GPIO_InitStructure);
               
                GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3;
                GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
                GPIO_Init(GPIOA,&GPIO_InitStructure);       
  }
        if(USARTx==USART3)
        {
                RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
                RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
                GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;
                GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
                GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
                GPIO_Init(GPIOB,&GPIO_InitStructure);
               
                GPIO_InitStructure.GPIO_Pin=GPIO_Pin_11;
                GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
                GPIO_Init(GPIOB,&GPIO_InitStructure);
  }
}

void USART_Configuration(USART_TypeDef* USARTx)
{
        USART_InitTypeDef USART_InitStructure;
        USART_InitStructure.USART_BaudRate=115200;
        USART_InitStructure.USART_WordLength=USART_WordLength_8b;
        USART_InitStructure.USART_StopBits=USART_StopBits_1;
        USART_InitStructure.USART_Parity=USART_Parity_No;
        USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
        USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
        USART_Init(USARTx,&USART_InitStructure);
        USART_Cmd(USARTx,ENABLE);
}

void delay_nms(u16 time)
{
        u16 i=0;
        while(time--)
        {
                i=12000;
                while(i--);
  }

}


TXRXstat Send1Byte(USART_TypeDef*USARTx,u8 dat)
{
        vu32 cnt=0;
        USART_SendData(USARTx,dat);
        while(USART_GetFlagStatus(USARTx,USART_FLAG_TXE)==RESET)
        {
                cnt++;
                if(cnt>100000)
                        return ERR;
  }
    return OK;
}


u8 ReceivelByte(USART_TypeDef* USARTx)
{
        while(USART_GetFlagStatus(USARTx,USART_FLAG_RXNE)==RESET)
        {}
                return (USART_ReceiveData(USARTx));
}

u8 ReceiveOk(USART_TypeDef* USARTx)
{
        vu32 cnt=0;
        while(1)
        {
                RxBuffer[RxCount++]=Receive1Byte(USARTx);
                if(strstr((char *)RxBuffer,"ON")!=NULL)
                {
                        RxCount=0;
                        return 1;
    }
                else
                        if(strstr((char*)RxBuffer,"OFF")!=NULL)
                        {
                                RxCount=0;
                                return 2;
      }
                        else
                                if(RxCount>3)
                                        RxCount=0;
                                cnt++;
                                if(cnt>100000)
                                        return 0;
  }
}

void SendString(USART_TypeDef*USARTx,u8*Message)
{
        while(*Message!='\0')
                Send1Byte(USARTx,*Message++);

}

void EmptyRxBuffer(u8 len)
{
        u8 i;
        for(i=0;i<len;i++)
        RxBuffer[i]=0;

}

int main(void)
{
//        u8 kcnt=0;
        SystemInit();
        GPIO_Led_Config();
        GPIO_USARTX_Config(USARTmy);
        USART_Configuration(USARTmy);
        while(1)
        {
                SendString(USARTmy,(u8 *)("Welcome to mycontroller V1.0!\n"));
                switch(ReceiveOk(USARTmy))
                {
                        case 1:
                                if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_8)==RESET)
                                        SendString(USARTmy,(u8*)("D2 in STM32 has been on!\n"));
                                else
                                {
                                        D2_ON;
                                        SendString(USARTmy,(u8*)("D2 in STM32 has been turn on!\n"));
        }
                                        break;
                                case 2:
                                        if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_8)!=RESET)
                                                SendString(USARTmy,(u8*)("D2 in STM32 has been off!\n"));
                                        else
                                        {
                                                D2_OFF;
                                                SendString(USARTmy,(u8*)("D2 in STM32 has been turn off\n"));
          }
                                        break;
                                        case 0:
                                                SendString(USARTmy,(u8*)("Command is error!\n"));
                                        break;
    }
                EmptyRxBuffer(Max);

  }

}
报错代码如下:

..\Output\Template.axf: Error: L6218E: Undefined symbol Receive1Byte (referred from main.o).
..\Output\Template.axf: Error: L6218E: Undefined symbol cnt1 (referred from stm32f10x_it.o).




正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

15

主题

96

帖子

0

精华

高级会员

Rank: 4

积分
650
金钱
650
注册时间
2017-4-21
在线时间
151 小时
发表于 2018-6-15 16:49:05 | 显示全部楼层
回复 支持 反对

使用道具 举报

31

主题

1954

帖子

3

精华

论坛元老

Rank: 8Rank: 8

积分
4510
金钱
4510
注册时间
2018-5-11
在线时间
944 小时
发表于 2018-6-15 23:10:49 | 显示全部楼层
楼上眼神真好.
我的开源链接 https://github.com/ShuifaHe/STM32.git  请关注,点赞支持哦。
回复 支持 反对

使用道具 举报

12

主题

21

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
234
金钱
234
注册时间
2017-7-15
在线时间
16 小时
 楼主| 发表于 2018-6-19 08:35:49 | 显示全部楼层
嗯嗯,非常感谢!!!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-5-26 05:58

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表