Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include "stm32f30x.h"
  2. #include "system_stm32f30x.h"
  3.  
  4. void TIM6_DAC_IRQHandler(void);
  5. void setTIM6(void);
  6.  
  7. volatile uint32_t _regValue = 1<<15;
  8.  
  9.  
  10. int main(void) {
  11.  
  12.  
  13. volatile int _timer = 1000000;
  14.  
  15. RCC -> AHBENR |= (uint32_t) 1 <<21;
  16. GPIOE -> MODER |= 0x55550000; //ports 8-15 output
  17. setTIM6();
  18. TIM6 -> CR1 |=0x1; //timer enable
  19.  
  20. while(1)
  21. {
  22. }
  23. } //end of main
  24.  
  25. void setTIM6(void) {
  26.  
  27. NVIC ->ISER[1] |= (uint32_t) 1<<22; //TIM6 int. enable
  28. RCC -> APB1ENR |= (uint32_t) 1<<4; //clock enable
  29. RCC -> CFGR |= 0x00000700; //APB1 prescaler -> clock=(8MHz/16)*2 = 1MHz
  30. TIM6->CR1 |= 0;
  31. TIM6->DIER |=1; //int. enable
  32. TIM6->PSC = 0xFFFF; //prescaler for TIM6. -> clk = 1Mz/2^16 = 2^4 =16Hz
  33. TIM6->ARR = 240; // int. flag every couple of secs.
  34.  
  35. DBGMCU->APB1FZ |= 1<<4; //for debug - TIM6 counter freeze during breakpoint
  36. }
  37.  
  38. void TIM6_DAC_IRQHandler(void)
  39. {
  40. _regValue = _regValue >> 1;
  41. GPIOE -> ODR = _regValue; //writing value to PORTE output
  42.  
  43. if (_regValue == 1<<9){
  44. _regValue = 1<<15;
  45. } //this is for rotational loop of LEDs
  46.  
  47. TIM6->SR &= ~0x1; //UIF (Interrupt flag) disabled
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement