Untitled
unknown
c_cpp
9 months ago
1.7 kB
6
Indexable
#define PERIPH_BASE ((uint32_t)0x40000000) #define AHB1PERIPH_BASE (PERIPH_BASE + 0x00020000) #define RCC_BASE (AHB1PERIPH_BASE + 0x3800) #define RCC_APB1ENR (*(volatile uint32_t *)(RCC_BASE + 0x1C)) #define APB1PERIPH_BASE (PERIPH_BASE + 0x00000000) #define TIM2_BASE (APB1PERIPH_BASE + 0x0000) #define TIM3_BASE (APB1PERIPH_BASE + 0x0400) #define TIM2 ((TIM_TypeDef *) TIM2_BASE) #define TIM3 ((TIM_TypeDef *) TIM3_BASE) typedef struct { volatile uint32_t CR1; volatile uint32_t CR2; volatile uint32_t SMCR; volatile uint32_t DIER; volatile uint32_t SR; volatile uint32_t EGR; volatile uint32_t CCMR1; volatile uint32_t CCMR2; volatile uint32_t CCER; volatile uint32_t CNT; volatile uint32_t PSC; volatile uint32_t ARR; volatile uint32_t RCR; volatile uint32_t CCR1; volatile uint32_t CCR2; volatile uint32_t CCR3; volatile uint32_t CCR4; volatile uint32_t BDTR; volatile uint32_t DCR; volatile uint32_t DMAR; } TIM_TypeDef; void Timer1_Init(void) { RCC_APB1ENR |= (1 << 0); // Enable TIM2 clock TIM2->PSC = 0; // Prescaler value TIM2->ARR = 110; // Auto-reload value TIM2->CR1 |= (1 << 0); // Enable the timer } void Timer2_Init(void) { RCC_APB1ENR |= (1 << 1); // Enable TIM3 clock TIM3->PSC = 79; // Prescaler value for 1 MHz timer clock (8 MHz / (PSC+1)) TIM3->ARR = 1778 - 1; // Auto-reload value for 1778 microseconds TIM3->CR1 |= (1 << 0); // Enable the timer } int main(void) { Timer1_Init(); Timer2_Init(); while (1) { // Main loop } }
Editor is loading...
Leave a Comment