Skip to content

Instantly share code, notes, and snippets.

@saffetblt
Created April 7, 2020 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saffetblt/02cd760e3a7b2822bd95a419a0833d1a to your computer and use it in GitHub Desktop.
Save saffetblt/02cd760e3a7b2822bd95a419a0833d1a to your computer and use it in GitHub Desktop.
#include "stm32f4xx.h" // Device header
int main(){
//GPIO Config
RCC->AHB1ENR |=0x8;
GPIOD->MODER |= (1<<30);
//TIM2 Config @16Mhz
RCC->APB1ENR |= 0x1; //Enable TIM2 Clock Bus
TIM2->PSC = 1600-1; //16.000.000 dive by 1.600 = 10.000 (Prescaler Register)
TIM2->ARR = 10000-1; //10.000 dive by 10.000 = 1Hz (Auto Reload Register)
TIM2->CNT = 0; //Clear timer counter (Counter Register)
TIM2->CR1 = 1; //Enable TIM2 (Control 1 Register)
while(1){
while(!(TIM2->SR & 0x1)); //Check Update Interrupt Flag (Status Register)
TIM2->SR &= ~0x1; //Clear Update Interrupt Flag (Status Register)
GPIOD->ODR ^= (1<<15);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment