作为作业,我需要使用TIM17而不是TIM16来使L432kc中的集成LED闪烁,LED位于引脚PB3中,但它不工作。
该程序在TIM16上运行良好,但是当我更改为TIM17时,LED不闪烁,起初我以为我忘记更改寄存器或其他东西,所以我尝试使用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);
}
这是stm32l432kc_sfr.h中的代码:
#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))