error: #136: struct "" has no field "XXXX"

下面这个是高级定时器的时基的结构体初始化

void ADVANCE_TIM_Mode_Config()
{
	// 开启定时器时钟,即内部时钟CK_INT=72M
	ADVANCE_TIM_APBxClock_FUN(ADVANCE_TIM_CLK,ENABLE);

/*--------------------时基结构体初始化-------------------------*/	
	TIM_ICInitTypeDef TIM_TimeBaseStructure;
	// 自动重装载寄存器的值,累计TIM_Period+1个频率后产生一个更新或者中断
	TIM_TimeBaseStructure.TIM_Period=ADVANCE_TIM_PERIOD;	
	// 驱动CNT计数器的时钟 = Fck_int/(psc+1)
	TIM_TimeBaseStructure.TIM_Prescaler= ADVANCE_TIM_PSC;	
	// 时钟分频因子 ,配置死区时间时需要用到
	TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;		
	// 计数器计数模式,设置为向上计数
	TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;		
	// 重复计数器的值,没用到不用管
	TIM_TimeBaseStructure.TIM_RepetitionCounter=0;	
}

…\User\advancetime\bsp_advancetime.c(43): error: #136: struct “” has no field “TIM_Period”
TIM_TimeBaseStructure.TIM_Period=ADVANCE_TIM_PERIOD;
…\User\advancetime\bsp_advancetime.c(45): error: #136: struct “” has no field “TIM_Prescaler”
TIM_TimeBaseStructure.TIM_Prescaler= ADVANCE_TIM_PSC;
…\User\advancetime\bsp_advancetime.c(47): error: #136: struct “” has no field “TIM_ClockDivision”
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
…\User\advancetime\bsp_advancetime.c(49): error: #136: struct “” has no field “TIM_CounterMode”
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
…\User\advancetime\bsp_advancetime.c(51): error: #136: struct “” has no field “TIM_RepetitionCounter”
TIM_TimeBaseStructure.TIM_RepetitionCounter=0;

问题:结构体中没有这个成员。
判断方法:进入TIM_ICInitTypeDef,查看其中有无TIM_PeriodTIM_Prescaler等成员。
结果没有,问题就在这里,最后发现用错了结构体,正确的结构体的名字应该是TIM_TimeBaseInitTypeDef

正确的程序是

static void ADVANCE_TIM_Mode_Config(void)
{
  // 开启定时器时钟,即内部时钟CK_INT=72M
	ADVANCE_TIM_APBxClock_FUN(ADVANCE_TIM_CLK,ENABLE);

/*--------------------时基结构体初始化-------------------------*/
	TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
	// 自动重装载寄存器的值,累计TIM_Period+1个频率后产生一个更新或者中断
	TIM_TimeBaseStructure.TIM_Period=ADVANCE_TIM_PERIOD;	
	// 驱动CNT计数器的时钟 = Fck_int/(psc+1)
	TIM_TimeBaseStructure.TIM_Prescaler= ADVANCE_TIM_PSC;	
	// 时钟分频因子 ,配置死区时间时需要用到
	TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;		
	// 计数器计数模式,设置为向上计数
	TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;		
	// 重复计数器的值,没用到不用管
	TIM_TimeBaseStructure.TIM_RepetitionCounter=0;	
	// 初始化定时器
	TIM_TimeBaseInit(ADVANCE_TIM, &TIM_TimeBaseStructure);

你可能感兴趣的:(stm32)