Warning
This page is located in archive. Go to the latest version of this course pages.

03 - Externí přerušení

#include "stm32f4xx.h"
 
/*
 * definice maker, ktera se budou pouzivat pro praci s 32b registrem STM32F4xx
 */
 
#define setbit(reg, bit) ((reg) |= (1U << (bit)))
#define clearbit(reg, bit) ((reg) &= (~(1U << (bit))))
#define togglebit(reg, bit) ((reg) ^= (1U << (bit)))
#define getbit(reg, bit) ((reg & (1U << bit)) >> bit)
 
void EXTI15_10_IRQHandler()
{
    /* zmenit PR (pending interrupt) na 1, pokud je 0 */
    setbit(EXTI->PR, 13);
    /* zmena stavu LED na desce */
    togglebit(GPIOA->ODR, 5);
}
 
void buttonConfig(void)
{
    setbit(RCC->AHB1ENR, 2);
    /* RCC->AHB1ENR |= 0x05; -- konfigurace dvou bran najednou */
    setbit(GPIOC->PUPDR, 26);
 
    /* nastaveni hodin systemove sbernice */
    setbit(RCC->APB2ENR, 14);
    /* nastaveni masky */
    setbit(EXTI->IMR, 13);
    /* nastaveni smyslu spousteni preruseni - falling, rising */
    setbit(EXTI->FTSR, 13);
    /* konfigiurace brany PC13 */
    setbit(SYSCFG->EXTICR[3], 5);
    /* povoleni preruseni */
    NVIC_EnableIRQ(EXTI15_10_IRQn); // 40 ~ EXTI15_10_IRQn
    /* ekvivalentni zapis */
    setbit(NVIC->ISER[40/32], 40%32);
}
 
void ledConfig()
{
    /* minimalni konfigurace, kompletni konfigurace viz uloha 1 */
    setbit(RCC->AHB1ENR, 0);
    setbit(GPIOA->MODER, 10);
}
 
int main(void)
{
    ledConfig();
    buttonConfig();
 
    while (1)
    {
        /*
         *
         */
    }
}

courses/b2m37mam/priklady/stm32/03-btn_ext_int.txt · Last modified: 2022/09/13 14:32 by nentvond