Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f30x.h"
- #include "system_stm32f30x.h"
- void TIM6_DAC_IRQHandler(void);
- void setTIM6(void);
- volatile uint32_t _regValue = 1<<15;
- int main(void) {
- volatile int _timer = 1000000;
- RCC -> AHBENR |= (uint32_t) 1 <<21;
- GPIOE -> MODER |= 0x55550000; //ports 8-15 output
- setTIM6();
- TIM6 -> CR1 |=0x1; //timer enable
- while(1)
- {
- }
- } //end of main
- void setTIM6(void) {
- NVIC ->ISER[1] |= (uint32_t) 1<<22; //TIM6 int. enable
- RCC -> APB1ENR |= (uint32_t) 1<<4; //clock enable
- RCC -> CFGR |= 0x00000700; //APB1 prescaler -> clock=(8MHz/16)*2 = 1MHz
- TIM6->CR1 |= 0;
- TIM6->DIER |=1; //int. enable
- TIM6->PSC = 0xFFFF; //prescaler for TIM6. -> clk = 1Mz/2^16 = 2^4 =16Hz
- TIM6->ARR = 240; // int. flag every couple of secs.
- DBGMCU->APB1FZ |= 1<<4; //for debug - TIM6 counter freeze during breakpoint
- }
- void TIM6_DAC_IRQHandler(void)
- {
- _regValue = _regValue >> 1;
- GPIOE -> ODR = _regValue; //writing value to PORTE output
- if (_regValue == 1<<9){
- _regValue = 1<<15;
- } //this is for rotational loop of LEDs
- TIM6->SR &= ~0x1; //UIF (Interrupt flag) disabled
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement