STM32L432KC使用TIM17驱动PB3引脚LED闪烁失败求助
问题:TIM17替代TIM16实现STM32L432KC板载LED闪烁失效
作业任务要求使用TIM17替代TIM16,实现STM32L432KC板载PB3引脚的LED闪烁功能,但程序运行后LED毫无反应。原程序使用TIM16时工作正常,换成TIM17后就失效了,换成TIM15则能正常运行。以下是主程序及寄存器定义头文件的代码:
主程序代码
#include "stm32l432kc_sfr.h" #define DEBUG(X) Serial.printf("%s\t%x\n",#X,X) #define TIM_SR_UIF (1<<0) void my_delay(uint32_t time_ms){ TIM17_SR &= ~TIM_SR_UIF; for (uint32_t i=0; i<=time_ms;i++){ TIM17_CNT=0; while((TIM17_SR & TIM_SR_UIF)==0); TIM17_SR &= ~TIM_SR_UIF; } } void setup() { RCC_AHB2ENR |=1<<1; GPIOB_MODER &= ~(3<<6); GPIOB_MODER |=1<<6; RCC_APB2ENR |=1<<18; //Register bit 16, 17 or 18 TIM17_PSC = 79; TIM17_ARR = 999; TIM17_CR1 |=1; //set to 1 } void loop(){ GPIOB_BSRR = 1<<3; my_delay(500); GPIOB_BSRR = 1<<19; my_delay(500); }
寄存器定义头文件代码
#define RCC_BASE 0x4002'1000UL #define RCC_AHB2ENR (*(volatile uint32_t*) (RCC_BASE+0x4c)) #define RCC_APB2ENR (*(volatile uint32_t*) (RCC_BASE+0x60)) #define GPIOB_BASE 0x4800'0400UL #define GPIOB_MODER (*(volatile uint32_t*) (GPIOB_BASE+0x00)) #define GPIOB_BSRR (*(volatile uint32_t*) (GPIOB_BASE+0x18)) #define TIM16_BASE 0x4001'4400UL #define TIM16_CR1 (*(volatile uint32_t*) (TIM16_BASE+0x00)) #define TIM16_SR (*(volatile uint32_t*) (TIM16_BASE+0x10)) #define TIM16_CNT (*(volatile uint32_t*) (TIM16_BASE+0x24)) #define TIM16_PSC (*(volatile uint32_t*) (TIM16_BASE+0x28)) #define TIM16_ARR (*(volatile uint32_t*) (TIM16_BASE+0x2c)) #define TIM17_BASE 0x4001'4800UL #define TIM17_CR1 (*(volatile uint32_t*) (TIM17_BASE+0x00)) #define TIM17_SR (*(volatile uint32_t*) (TIM17_BASE+0x10)) #define TIM17_CNT (*(volatile uint32_t*) (TIM17_BASE+0x24)) #define TIM17_PSC (*(volatile uint32_t*) (TIM17_BASE+0x28)) #define TIM17_ARR (*(volatile uint32_t*) (TIM17_BASE+0x2C)) #define TIM15_BASE 0x4001'4000UL #define TIM15_CR1 (*(volatile uint32_t*) (TIM15_BASE+0x00)) #define TIM15_SR (*(volatile uint32_t*) (TIM15_BASE+0x10)) #define TIM15_CNT (*(volatile uint32_t*) (TIM15_BASE+0x24)) #define TIM15_PSC (*(volatile uint32_t*) (TIM15_BASE+0x28)) #define TIM15_ARR (*(volatile uint32_t*) (TIM15_BASE+0x2C))
内容的提问来源于stack exchange,提问作者Johan Melgarejo
相关产品推荐
相关产品推荐

