这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 高校专区 » 漓东e学堂 » 【解决】定时器TIM8的中断怎么在库中没有定义【STM32F103RBT6 无T

共8条 1/1 1 跳转至

【解决】定时器TIM8的中断怎么在库中没有定义【STM32F103RBT6 无TIM8】

菜鸟
2014-11-25 23:58:24     打赏

在设置TIM8定时中断的时候

TIM8_CC_IRQn出错

 

可是在中是有定义的(更新了这个库,老师给的好像没有)

 

 

为什么会报错啊?还是不应该这样写TIM8的中断??

 

 代码如下

#include "stm32f10x.h"
#include "misc.h"


void RCC_Configuration(void);
void NVIC_Configuration(void);
void GPIO_Configuration(void);
void TIM2_Configuration(void);
void TIM3_Configuration(void);
void TIM8_Configuration(void);

void RCC_Configuration(void)
{
SystemInit();//24兆
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);//TIM3外设时钟打开,TIM3是挂在APB1上的,一
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);//TIM2外设时钟打开,TIM2是挂在APB1上的,一
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);//TIM8外设时钟打开,TIM8是挂在APB2上的,一
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);//GPIOC外设时钟打开
}

void NVIC_Configuration(void)//设置中断,二
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;//抢占优先级
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;//响应式优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
	
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;//抢占优先级
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;//响应式优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
	
NVIC_InitStructure.NVIC_IRQChannel =TIM8_CC_IRQn ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;//抢占优先级
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;//响应式优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}

void GPIO_Configuration(void)//三,LED配置
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6;//使用到PC1.2.3
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}

void TIM2_Configuration(void)//四,定时器配置
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period = 4999;//计4999个数就产生一次更新事件,4999+1=5000,5000*0.1ms=0.5s
TIM_TimeBaseStructure.TIM_Prescaler = 2399;//预分频系数为2399,则计数器的时钟为24MHZ/2399+1=10kHZ,1/10000=0,0001.即0.1ms
//预分频数取值范围为0~65535
TIM_TimeBaseStructure.TIM_ClockDivision = 0;//
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//向上计数模式,从0开始向上
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);//将配置应用到TIM3中
}

void TIM3_Configuration(void)//四,定时器配置
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period = 9999;//计9999个数就产生一次更新事件,9999+1=10000,10000*0.1ms=1s
TIM_TimeBaseStructure.TIM_Prescaler = 2399;//预分频系数为2399,则计数器的时钟为24MHZ/2399+1=10kHZ,1/10000=0,0001.即0.1ms
TIM_TimeBaseStructure.TIM_ClockDivision = 0;//
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//向上计数模式,从0开始向上
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);//将配置应用到TIM3中
}

void TIM1_Configuration(void)//四,定时器配置
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period = 9999;//计9999个数就产生一次更新事件,9999+1=10000,10000*0.1ms=1s
TIM_TimeBaseStructure.TIM_Prescaler = 2399;//预分频系数为2399,则计数器的时钟为24MHZ/2399+1=10kHZ,1/10000=0,0001.即0.1ms
TIM_TimeBaseStructure.TIM_ClockDivision = 0;//
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//向上计数模式,从0开始向上
TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);//将配置应用到TIM8中
}

int main(void)
{
RCC_Configuration();
NVIC_Configuration();
GPIO_Configuration();
TIM2_Configuration();
TIM3_Configuration();
TIM8_Configuration();

TIM_ClearFlag(TIM8, TIM_FLAG_Update);
TIM_ClearFlag(TIM2, TIM_FLAG_Update);
TIM_ClearFlag(TIM3, TIM_FLAG_Update);
TIM_ARRPreloadConfig(TIM8, DISABLE);
TIM_ARRPreloadConfig(TIM2, DISABLE);
TIM_ARRPreloadConfig(TIM3, DISABLE);

TIM_ITConfig(TIM8, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM1, ENABLE);//开启定时器TIM1
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM2, ENABLE);//开启定时器TIM2
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM3, ENABLE);//开启定时器TIM3

while (1) {
}
}

#include "stm32f10x_it.h"
void TIM8_IRQHandler(void)
{
if (TIM_GetITStatus(TIM8, TIM_IT_Update) != RESET) //检测是否发生溢出更新事件
	{
	TIM_ClearITPendingBit(TIM8, TIM_IT_Update);
	GPIO_WriteBit(GPIOC, GPIO_Pin_0|GPIO_Pin_4, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_0|GPIO_Pin_4)));//取反库函数
	}
}

void TIM2_IRQHandler(void)
{
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) //检测是否发生溢出更新事件
	{
	TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
	GPIO_WriteBit(GPIOC, GPIO_Pin_2|GPIO_Pin_6, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_2|GPIO_Pin_6)));//取反库函数
	}
}

void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //检测是否发生溢出更新事件
	{
	TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
	GPIO_WriteBit(GPIOC, GPIO_Pin_1|GPIO_Pin_5, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_1|GPIO_Pin_5)));//取反库函数
	}
}


 

 


高工
2014-11-26 09:59:08     打赏
2楼
楼主用的是哪个型号的STM32.....

高工
2014-11-26 10:04:05     打赏
3楼
可以查看stm32f10x.h的第167行,根据你所用芯片的类型去看看是否有这个东东

高工
2014-11-26 10:05:41     打赏
4楼

hi there

仔细看看库函数和MCU的数据手册

库函数:

#ifdef STM32F10X_HD_VL
  ADC1_IRQn                   = 18,     /*!< ADC1 global Interrupt                                */
  EXTI9_5_IRQn                = 23,     /*!< External Line[9:5] Interrupts                        */
  TIM1_BRK_TIM15_IRQn         = 24,     /*!< TIM1 Break and TIM15 Interrupts                      */
  TIM1_UP_TIM16_IRQn          = 25,     /*!< TIM1 Update and TIM16 Interrupts                     */
  TIM1_TRG_COM_TIM17_IRQn     = 26,     /*!< TIM1 Trigger and Commutation and TIM17 Interrupt     */
  TIM1_CC_IRQn                = 27,     /*!< TIM1 Capture Compare Interrupt                       */
  TIM2_IRQn                   = 28,     /*!< TIM2 global Interrupt                                */
  TIM3_IRQn                   = 29,     /*!< TIM3 global Interrupt                                */
  TIM4_IRQn                   = 30,     /*!< TIM4 global Interrupt                                */
  I2C1_EV_IRQn                = 31,     /*!< I2C1 Event Interrupt                                 */
  I2C1_ER_IRQn                = 32,     /*!< I2C1 Error Interrupt                                 */
  I2C2_EV_IRQn                = 33,     /*!< I2C2 Event Interrupt                                 */
  I2C2_ER_IRQn                = 34,     /*!< I2C2 Error Interrupt                                 */
  SPI1_IRQn                   = 35,     /*!< SPI1 global Interrupt                                */
  SPI2_IRQn                   = 36,     /*!< SPI2 global Interrupt                                */
  USART1_IRQn                 = 37,     /*!< USART1 global Interrupt                              */
  USART2_IRQn                 = 38,     /*!< USART2 global Interrupt                              */
  USART3_IRQn                 = 39,     /*!< USART3 global Interrupt                              */
  EXTI15_10_IRQn              = 40,     /*!< External Line[15:10] Interrupts                      */
  RTCAlarm_IRQn               = 41,     /*!< RTC Alarm through EXTI Line Interrupt                */
  CEC_IRQn                    = 42,     /*!< HDMI-CEC Interrupt                                   */
  TIM12_IRQn                  = 43,     /*!< TIM12 global Interrupt                               */
  TIM13_IRQn                  = 44,     /*!< TIM13 global Interrupt                               */
  TIM14_IRQn                  = 45,     /*!< TIM14 global Interrupt                               */
  TIM5_IRQn                   = 50,     /*!< TIM5 global Interrupt                                */
  SPI3_IRQn                   = 51,     /*!< SPI3 global Interrupt                                */
  UART4_IRQn                  = 52,     /*!< UART4 global Interrupt                               */
  UART5_IRQn                  = 53,     /*!< UART5 global Interrupt                               */  
  TIM6_DAC_IRQn               = 54,     /*!< TIM6 and DAC underrun Interrupt                      */
  TIM7_IRQn                   = 55,     /*!< TIM7 Interrupt                                       */  
  DMA2_Channel1_IRQn          = 56,     /*!< DMA2 Channel 1 global Interrupt                      */
  DMA2_Channel2_IRQn          = 57,     /*!< DMA2 Channel 2 global Interrupt                      */
  DMA2_Channel3_IRQn          = 58,     /*!< DMA2 Channel 3 global Interrupt                      */
  DMA2_Channel4_5_IRQn        = 59,     /*!< DMA2 Channel 4 and Channel 5 global Interrupt        */
  DMA2_Channel5_IRQn          = 60      /*!< DMA2 Channel 5 global Interrupt (DMA2 Channel 5 is 
                                             mapped at position 60 only if the MISC_REMAP bit in 
                                             the AFIO_MAPR2 register is set)                      */       
#endif /* STM32F10X_HD_VL */

 

TIM8是定义在STM32F10X_HD_XX 系列的

STM32F103RBT8是属于STM32F10X_MD_XX系列

数据手册:



get?


高工
2014-11-26 10:06:48     打赏
5楼
建议了解一下预编译指令

菜鸟
2014-11-26 12:48:17     打赏
6楼
STM32F103RBT6没有TIM8,get,原来不是所有的芯片都有TIM8和其他的什么的==

菜鸟
2014-11-26 12:48:56     打赏
7楼
get

菜鸟
2015-12-06 23:19:47     打赏
8楼
说一句,我是应为进入不了定时器中断,才网上爬文的,找了半天看到你这个,没有啥帮助,看到了你的错误,说一句,v3.5的库以及启动文件的话,你的tim8的中断服务函数名字是错的,请你仔细查查

共8条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]