본문 바로가기

카테고리 없음

Nucleo-F103RB 내장 LED 깜빡이기 - BSRR

전체 보기 : https://makershackers.tistory.com/tag/baremetal_stm32_f411

 

 

#include "stm32f1xx.h"

void DelayMilliseconds (int delay);

int main(void)

  {
   RCC->APB2ENR |= 4; // user guide 66p, 내장LED PA5, data sheet 11p
   GPIOA->CRL &= 0xFF0FFFFF; // ref. 159p, 171p Reset value: 0x4444 4444 여서 필요부분만 0으로 초기화 함
   GPIOA->CRL |= 0x00300000; // ref. 159p, 171p, 1~3은 Hz의 차이만 남 01-10, 10-2, 11-50 MHz
   while (1) {
         GPIOA -> BSRR |= 0x20; // GPIOA -> ODR |= 0x20;  ref. 173p, port 5
         DelayMilliseconds(100);
         GPIOA -> BSRR = 0x200000; // GPIOA -> ODR  &=~0x20; 
         DelayMilliseconds(100);
        }
  }

void DelayMilliseconds (int delay)
{
 int i;
 for(;delay>0;delay--) {
  for (i=0;i<3195;i++);
  }
}

 

 관련 문서