正点原子例程里面用的是通用定时器TIM3,我想要将其换成高级定时器TIM1,那么有哪些区别呢
1.时钟使能:
如下可以看到,高级定时器TIM1挂载在APB2总线,通用定时器TIM3挂载在APB2总线。
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //TIM3时钟使能RCC_APB2PeriphClockCmd(RCC_APB1Periph_TIM1, ENABLE); //TIM1时钟使能 //APB1下的外设,包含TIM3#define RCC_APB1Periph_TIM2 ((uint32_t)0x00000001)#define RCC_APB1Periph_TIM3 ((uint32_t)0x00000002)#define RCC_APB1Periph_TIM4 ((uint32_t)0x00000004)#define RCC_APB1Periph_TIM5 ((uint32_t)0x00000008)#define RCC_APB1Periph_TIM6 ((uint32_t)0x00000010)#define RCC_APB1Periph_TIM7 ((uint32_t)0x00000020)#define RCC_APB1Periph_TIM12 ((uint32_t)0x00000040)#define RCC_APB1Periph_TIM13 ((uint32_t)0x00000080)#define RCC_APB1Periph_TIM14 ((uint32_t)0x00000100)#define RCC_APB1Periph_WWDG ((uint32_t)0x00000800)#define RCC_APB1Periph_SPI2 ((uint32_t)0x00004000)#define RCC_APB1Periph_SPI3 ((uint32_t)0x00008000)#define RCC_APB1Periph_USART2 ((uint32_t)0x00020000)#define RCC_APB1Periph_USART3 ((uint32_t)0x00040000)#define RCC_APB1Periph_UART4 ((uint32_t)0x00080000)#define RCC_APB1Periph_UART5 ((uint32_t)0x00100000)#define RCC_APB1Periph_I2C1 ((uint32_t)0x00200000)#define RCC_APB1Periph_I2C2 ((uint32_t)0x00400000)#define RCC_APB1Periph_USB ((uint32_t)0x00800000)#define RCC_APB1Periph_CAN1 ((uint32_t)0x02000000)#define RCC_APB1Periph_CAN2 ((uint32_t)0x04000000)#define RCC_APB1Periph_BKP ((uint32_t)0x08000000)#define RCC_APB1Periph_PWR ((uint32_t)0x10000000)#define RCC_APB1Periph_DAC ((uint32_t)0x20000000)#define RCC_APB1Periph_CEC ((uint32_t)0x40000000)#define IS_RCC_APB1_PERIPH(PERIPH) ((((PERIPH) & 0x81013600) == 0x00) && ((PERIPH) != 0x00))//APB1下的外设,包含TIM1#define RCC_APB2Periph_AFIO ((uint32_t)0x00000001)#define RCC_APB2Periph_GPIOA ((uint32_t)0x00000004)#define RCC_APB2Periph_GPIOB ((uint32_t)0x00000008)#define RCC_APB2Periph_GPIOC ((uint32_t)0x00000010)#define RCC_APB2Periph_GPIOD ((uint32_t)0x00000020)#define RCC_APB2Periph_GPIOE ((uint32_t)0x00000040)#define RCC_APB2Periph_GPIOF ((uint32_t)0x00000080)#define RCC_APB2Periph_GPIOG ((uint32_t)0x00000100)#define RCC_APB2Periph_ADC1 ((uint32_t)0x00000200)#define RCC_APB2Periph_ADC2 ((uint32_t)0x00000400)#define RCC_APB2Periph_TIM1 ((uint32_t)0x00000800)#define RCC_APB2Periph_SPI1 ((uint32_t)0x00001000)#define RCC_APB2Periph_TIM8 ((uint32_t)0x00002000)#define RCC_APB2Periph_USART1 ((uint32_t)0x00004000)#define RCC_APB2Periph_ADC3 ((uint32_t)0x00008000)#define RCC_APB2Periph_TIM15 ((uint32_t)0x00010000)#define RCC_APB2Periph_TIM16 ((uint32_t)0x00020000)#define RCC_APB2Periph_TIM17 ((uint32_t)0x00040000)#define RCC_APB2Periph_TIM9 ((uint32_t)0x00080000)#define RCC_APB2Periph_TIM10 ((uint32_t)0x00100000)#define RCC_APB2Periph_TIM11 ((uint32_t)0x00200000)#define IS_RCC_APB2_PERIPH(PERIPH) ((((PERIPH) & 0xFFC00002) == 0x00) && ((PERIPH) != 0x00)) 2.中断配置
通用定时器中断配置一个: TIM3_IRQ
高级定时器中断配置四个: TIM1_BRK_IRQn、 TIM1_UP_IRQn、 TIM1_TRG_COM_IRQn、 TIM1_CC_IRQn
正点原子例程里面用的是通用定时器TIM3,我想要将其换成高级定时器TIM1,那么有哪些区别呢
1.时钟使能:
如下可以看到,高级定时器TIM1挂载在APB2总线,通用定时器TIM3挂载在APB2总线。
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //TIM3时钟使能RCC_APB2PeriphClockCmd(RCC_APB1Periph_TIM1, ENABLE); //TIM1时钟使能 //APB1下的外设,包含TIM3#define RCC_APB1Periph_TIM2 ((uint32_t)0x00000001)#define RCC_APB1Periph_TIM3 ((uint32_t)0x00000002)#define RCC_APB1Periph_TIM4 ((uint32_t)0x00000004)#define RCC_APB1Periph_TIM5 ((uint32_t)0x00000008)#define RCC_APB1Periph_TIM6 ((uint32_t)0x00000010)#define RCC_APB1Periph_TIM7 ((uint32_t)0x00000020)#define RCC_APB1Periph_TIM12 ((uint32_t)0x00000040)#define RCC_APB1Periph_TIM13 ((uint32_t)0x00000080)#define RCC_APB1Periph_TIM14 ((uint32_t)0x00000100)#define RCC_APB1Periph_WWDG ((uint32_t)0x00000800)#define RCC_APB1Periph_SPI2 ((uint32_t)0x00004000)#define RCC_APB1Periph_SPI3 ((uint32_t)0x00008000)#define RCC_APB1Periph_USART2 ((uint32_t)0x00020000)#define RCC_APB1Periph_USART3 ((uint32_t)0x00040000)#define RCC_APB1Periph_UART4 ((uint32_t)0x00080000)#define RCC_APB1Periph_UART5 ((uint32_t)0x00100000)#define RCC_APB1Periph_I2C1 ((uint32_t)0x00200000)#define RCC_APB1Periph_I2C2 ((uint32_t)0x00400000)#define RCC_APB1Periph_USB ((uint32_t)0x00800000)#define RCC_APB1Periph_CAN1 ((uint32_t)0x02000000)#define RCC_APB1Periph_CAN2 ((uint32_t)0x04000000)#define RCC_APB1Periph_BKP ((uint32_t)0x08000000)#define RCC_APB1Periph_PWR ((uint32_t)0x10000000)#define RCC_APB1Periph_DAC ((uint32_t)0x20000000)#define RCC_APB1Periph_CEC ((uint32_t)0x40000000)#define IS_RCC_APB1_PERIPH(PERIPH) ((((PERIPH) & 0x81013600) == 0x00) && ((PERIPH) != 0x00))//APB1下的外设,包含TIM1#define RCC_APB2Periph_AFIO ((uint32_t)0x00000001)#define RCC_APB2Periph_GPIOA ((uint32_t)0x00000004)#define RCC_APB2Periph_GPIOB ((uint32_t)0x00000008)#define RCC_APB2Periph_GPIOC ((uint32_t)0x00000010)#define RCC_APB2Periph_GPIOD ((uint32_t)0x00000020)#define RCC_APB2Periph_GPIOE ((uint32_t)0x00000040)#define RCC_APB2Periph_GPIOF ((uint32_t)0x00000080)#define RCC_APB2Periph_GPIOG ((uint32_t)0x00000100)#define RCC_APB2Periph_ADC1 ((uint32_t)0x00000200)#define RCC_APB2Periph_ADC2 ((uint32_t)0x00000400)#define RCC_APB2Periph_TIM1 ((uint32_t)0x00000800)#define RCC_APB2Periph_SPI1 ((uint32_t)0x00001000)#define RCC_APB2Periph_TIM8 ((uint32_t)0x00002000)#define RCC_APB2Periph_USART1 ((uint32_t)0x00004000)#define RCC_APB2Periph_ADC3 ((uint32_t)0x00008000)#define RCC_APB2Periph_TIM15 ((uint32_t)0x00010000)#define RCC_APB2Periph_TIM16 ((uint32_t)0x00020000)#define RCC_APB2Periph_TIM17 ((uint32_t)0x00040000)#define RCC_APB2Periph_TIM9 ((uint32_t)0x00080000)#define RCC_APB2Periph_TIM10 ((uint32_t)0x00100000)#define RCC_APB2Periph_TIM11 ((uint32_t)0x00200000)#define IS_RCC_APB2_PERIPH(PERIPH) ((((PERIPH) & 0xFFC00002) == 0x00) && ((PERIPH) != 0x00)) 2.中断配置
通用定时器中断配置一个: TIM3_IRQ
高级定时器中断配置四个: TIM1_BRK_IRQn、 TIM1_UP_IRQn、 TIM1_TRG_COM_IRQn、 TIM1_CC_IRQn
举报