|
买的是MPU6050模块的程序
1、其中我自己编写了一个PWM的程序放在文件中,为什么老是报错,检查了很久,不知道问题出在哪里,PWM.C文件:
#include "pwm.h"
/***************pwm.c***************/
//arr:自动重装值
//psc:时钟预分频数
//arr取14399,实际为14400,psc取99,实际为100
//设置舵机的周期为20ms的方法:72000000HZ/14400/100=50HZ,即20ms.
//14400表示20ms,1ms为720
void pwm_init(u16 arr,u16 psc)
{
GPIO_InitTypeDef GPIO_InitStructure;//声明一个结构体变量,用来初始化GPIO
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;//声明一个结构体变量,用来初始化定时器
TIM_OCInitTypeDef TIM_OCInitStructure;//根据 TIM_OCInitStruct 中指定的参数初始化外设 TIMx
/* 开启时钟 */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
/* 配置 GPIO 的模式和 IO 口 */
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;//复用推挽输出
GPIO_Init(GPIOA,&GPIO_InitStructure);
//TIM3 定时器初始化
TIM_TimeBaseInitStructure.TIM_Period = arr; //设置自动重装载寄存器周期的值
TIM_TimeBaseInitStructure.TIM_Prescaler = psc;//设置用来作为 TIMx 时钟频率预分频值
TIM_TimeBaseInitStructure.TIM_ClockDivision = 0;//设置时钟分割:TDTS = Tck_tim
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;//TIM 向上计数模式
TIM_TimeBaseInit(TIM3, & TIM_TimeBaseInitStructure);
//PWM 初始化 //根据 TIM_OCInitStruct 中指定的参数初始化外设 TIMx
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;//PWM输出使能
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;
TIM_OC2Init(TIM3,&TIM_OCInitStructure);
//注意此处初始化时 TIM_OC2Init 而不是 TIM_OCInit,否则会出错。因为固件库的版本不一样。
TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable);//使能或者失能TIMx 在 CCR2 上的预装载寄存器
TIM_ARRPreloadConfig(TIM3,ENABLE);//使能TIMx在ARR上的预装载寄存器,普中里没有
TIM_CtrlPWMOutputs(TIM3, ENABLE); //使能PWM模式,普中里没有
TIM_Cmd(TIM3,ENABLE);//使能或者失能 TIMx 外设
}
//------------------End of File----------------------------
2、PWM.H文件
#ifndef _pwm_H
#define _pwm_H
#include "stm32f10x.h"
void pwm_init(u16 arr,u16 psc);
#endif
3、报错的地方是:
..\HARDWARE\PWM\pwm.c(11): error: #20: identifier "GPIO_InitTypeDef" is undefined
..\HARDWARE\PWM\pwm.c(13): error: #20: identifier "TIM_TimeBaseInitTypeDef" is undefined
..\HARDWARE\PWM\pwm.c(16): error: #20: identifier "TIM_OCInitTypeDef" is undefined
..\HARDWARE\PWM\pwm.c(19): warning: #223-D: function "RCC_APB2PeriphClockCmd" declared implicitly
..\HARDWARE\PWM\pwm.c(19): error: #20: identifier "RCC_APB2Periph_GPIOA" is undefined
..\HARDWARE\PWM\pwm.c(20): warning: #223-D: function "RCC_APB1PeriphClockCmd" declared implicitly
..\HARDWARE\PWM\pwm.c(20): error: #20: identifier "RCC_APB1Periph_TIM3" is undefined
..\HARDWARE\PWM\pwm.c(21): error: #20: identifier "RCC_APB2Periph_AFIO" is undefined
..\HARDWARE\PWM\pwm.c(24): error: #20: identifier "GPIO_Pin_7" is undefined
..\HARDWARE\PWM\pwm.c(25): error: #20: identifier "GPIO_Speed_50MHz" is undefined
..\HARDWARE\PWM\pwm.c(26): error: #20: identifier "GPIO_Mode_AF_PP" is undefined
..\HARDWARE\PWM\pwm.c(27): warning: #223-D: function "GPIO_Init" declared implicitly
..\HARDWARE\PWM\pwm.c(33): error: #20: identifier "TIM_CounterMode_Up" is undefined
..\HARDWARE\PWM\pwm.c(35): warning: #223-D: function "TIM_TimeBaseInit" declared implicitly
..\HARDWARE\PWM\pwm.c(38): error: #20: identifier "TIM_OCMode_PWM1" is undefined
..\HARDWARE\PWM\pwm.c(39): error: #20: identifier "TIM_OutputState_Enable" is undefined
..\HARDWARE\PWM\pwm.c(40): error: #20: identifier "TIM_OCPolarity_High" is undefined
..\HARDWARE\PWM\pwm.c(41): warning: #223-D: function "TIM_OC2Init" declared implicitly
..\HARDWARE\PWM\pwm.c(43): warning: #223-D: function "TIM_OC2PreloadConfig" declared implicitly
..\HARDWARE\PWM\pwm.c(43): error: #20: identifier "TIM_OCPreload_Enable" is undefined
..\HARDWARE\PWM\pwm.c(44): warning: #223-D: function "TIM_ARRPreloadConfig" declared implicitly
..\HARDWARE\PWM\pwm.c(45): warning: #223-D: function "TIM_CtrlPWMOutputs" declared implicitly
..\HARDWARE\PWM\pwm.c(46): warning: #223-D: function "TIM_Cmd" declared implicitly
好像是没有进行相关的配置,请程序猿大大帮忙看看,是不是还要在程序中配置其他的东西。搞了一天了,还是弄不明白啊,好煎熬。。。。。
|
-
|