初级会员

- 积分
- 90
- 金钱
- 90
- 注册时间
- 2014-5-17
- 在线时间
- 0 小时
|
5金钱
usart.h文件:
#ifndef __USART_H
#define __USART_H
//#include "stm32f10x_lib.h"
// #include "stm32f10x.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_usart.h"
#include "stm32f10x_nvic.h"
#include "stm32f10x_rcc.h"
//////////////////////////////////////////////////////////////////////////////////
//注释................
//////////////////////////////////////////////////////////////////////////////////
//如果想串口中断接收,请不要注释以下宏定义
// #define GPIO_Pin_9 ((uint16_t)0x0200) /*!< Pin 9 selected */
// #define GPIO_Pin_10 ((uint16_t)0x0400) /*!< Pin 10 selected */
//typedef unsigned long u32;
void USART1_Configuration(u32 bound);
#endif
usart.c
void USART1_Configuration(u32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure; //#include "stm32f10x_gpio.h"
USART_InitTypeDef USART_InitStructure; // #include "stm32f10x_usart.h"
USART_ClockInitTypeDef USART_ClockInitStructure;
NVIC_InitTypeDef NVIC_InitStructure; //#include "stm32f10x_nvic.h"
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 |RCC_APB2Periph_USART1, ENABLE ); //#include "stm32f10x_rcc.h"
USART_DeInit(USART1); //复位串口1
//USART1_TX PA.9
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化PA9
//USART1_RX   A.10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化PA10
//Usart1 NVIC 配置
// NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
// NVIC_InitStructure.NVIC_IRQChannel = 37;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//抢占优先级3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable; // 时钟低电平活动
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low; // 时钟低电平
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge; // 时钟第二个边沿进行数据捕获
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable; // 最后一位数据的时钟脉冲不从SCLK输出
/* Configure the USART1 synchronous paramters */
USART_ClockInit(USART1, &USART_ClockInitStructure); // 时钟参数初始化设置
USART_InitStructure.USART_BaudRate = bound; // 波特率为:115200
USART_InitStructure.USART_WordLength = USART_WordLength_8b; // 8位数据
USART_InitStructure.USART_StopBits = USART_StopBits_1; // 在帧结尾传输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; // 发送使能+接收使能
/* Configure USART1 basic and asynchronous paramters */
USART_Init(USART1, &USART_InitStructure);
/* Enable USART1 */
USART_ClearFlag(USART1, USART_IT_RXNE); //清中断,以免一启用中断后立即产生中断
USART_ITConfig(USART1,USART_IT_RXNE, ENABLE); //使能USART1中断源
USART_Cmd(USART1, ENABLE); //USART1总开关:开启
}
compiling usart.c...
linking...
..\OBJ\Navigation.axf: Error: L6218E: Undefined symbol g_IMURaw_Data (referred from imu_calculation.o).
..\OBJ\Navigation.axf: Error: L6218E: Undefined symbol GPIO_Init (referred from iic.o).
..\OBJ\Navigation.axf: Error: L6218E: Undefined symbol NVIC_Init (referred from usart.o).
..\OBJ\Navigation.axf: Error: L6218E: Undefined symbol RCC_APB2PeriphClockCmd (referred from usart.o).
..\OBJ\Navigation.axf: Error: L6218E: Undefined symbol USART_ClearFlag (referred from usart.o).
..\OBJ\Navigation.axf: Error: L6218E: Undefined symbol USART_ClockInit (referred from usart.o).
..\OBJ\Navigation.axf: Error: L6218E: Undefined symbol USART_Cmd (referred from usart.o).
..\OBJ\Navigation.axf: Error: L6218E: Undefined symbol USART_DeInit (referred from usart.o).
..\OBJ\Navigation.axf: Error: L6218E: Undefined symbol USART_ITConfig (referred from usart.o).
..\OBJ\Navigation.axf: Error: L6218E: Undefined symbol USART_Init (referred from usart.o).
..\OBJ\Navigation.axf: Error: L6218E: Undefined symbol RCC_APB1PeriphClockCmd (referred from timer.o).
..\OBJ\Navigation.axf: Error: L6218E: Undefined symbol TIM_Cmd (referred from timer.o).
..\OBJ\Navigation.axf: Error: L6218E: Undefined symbol TIM_TimeBaseInit (referred from timer.o).
Target not created
如上错误怎么改? 注明不能使用stm32f10x.h这个库, 因为使用这个库我的工程里头好多函数都要改
|
最佳答案
查看完整内容[请看2#楼]
回复【4楼】augustedward:
---------------------------------
改成這样子就可以了:
#include "stm32f10x_gpio.h"
#include "stm32f10x_usart.h"
#include "misc.h"
#include "stm32f10x_rcc.h"
#include "stdio.h"
因为3.50以上的nvic不在有专门 stm32f10x_nvic.h来写了,而是放在了misc.h中,所以包含 misc.h就可以了
|