Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gpio.h>
- #include <stdint.h>
- #define EXTI_INTENR REGISTER(0x40010400)
- #define EXTI_RTENR REGISTER(0x40010408)
- #define EXTI_FTENR REGISTER(0x4001040C)
- #define EXTI_INTFR REGISTER(0x40010410)
- #define AFIO_EXTICR (*(volatile uint32_t *)(0x40010008))
- #define P_PIN 3
- void configure_pd3_interrupt() {
- // Map EXTI line 3 to Port D (4 bits per line)
- AFIO_EXTICR &= ~(0xF << (4 * 3));
- AFIO_EXTICR |= (0x03 << (4 * 3)); // 0x03 for Port D
- // enable interrupt for gpio pin
- EXTI_INTENR |= PIN(3);
- EXTI_RTENR |= PIN(3);
- EXTI_FTENR |= PIN(3);
- EXTI_INTFR &= ~PIN(3);
- REGISTER(0xE000E100) |= PIN(20); // Enable EXTI7_0 interrupt in PFIC (IRQ 20)
- }
- int main(void) {
- enable_APB2_peripheral(AFIOEN); // enable alternative function
- enable_gpio_port(PORT_D); // enable port D
- gpio_set_mode(PORT_D, 3, GPIO_MODE_INPUT_FLOATING);
- gpio_set_mode(PORT_D, 2, GPIO_MODE_OUTPUT_PP_50MHZ);
- configure_pd3_interrupt();
- while (1) {
- uint32_t flag_register_value = EXTI_INTFR;
- if (flag_register_value & PIN(3)) {
- EXTI_INTFR &= ~PIN(3);
- gpio_write(PORT_D, 2, 1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment