nRF51 Example 4 - Key and Interrupt

Source work

A key and an Interrupt

My assignment:

And other 3 keys and Interrupts

Please click “more” on the right!

Part of my source files

exit.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
void EXIT_KEY_Init(void)
{
nrf_gpio_cfg_input(KEY_1,GPIO_PIN_CNF_PULL_Pullup);
nrf_gpio_cfg_input(KEY_2,GPIO_PIN_CNF_PULL_Pullup);
nrf_gpio_cfg_input(KEY_3,GPIO_PIN_CNF_PULL_Pullup);
nrf_gpio_cfg_input(KEY_4,GPIO_PIN_CNF_PULL_Pullup);
NVIC_EnableIRQ(GPIOTE_IRQn);
NRF_GPIOTE->CONFIG[0] = (GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos)
| (30 << GPIOTE_CONFIG_PSEL_Pos)
| (GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos);
NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN0_Set << GPIOTE_INTENSET_IN0_Pos;
NRF_GPIOTE->CONFIG[1] = (GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos)
|(21 << GPIOTE_CONFIG_PSEL_Pos)
|(GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos);
NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN1_Set << GPIOTE_INTENSET_IN1_Pos;
NRF_GPIOTE->CONFIG[2] = (GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos)
|(22 << GPIOTE_CONFIG_PSEL_Pos)
|(GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos);
NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN2_Set << GPIOTE_INTENSET_IN2_Pos;
NRF_GPIOTE->CONFIG[3] = (GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos)
|(23 << GPIOTE_CONFIG_PSEL_Pos)
|(GPIOTE_CONFIG_MODE_Event << GPIOTE_CONFIG_MODE_Pos);
NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN3_Set << GPIOTE_INTENSET_IN3_Pos;
}
void GPIOTE_IRQHandler(void)
{
if ((NRF_GPIOTE->EVENTS_IN[0] == 1) &&
(NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_IN0_Msk))
{
NRF_GPIOTE->EVENTS_IN[0] = 0;
LED_Toggle(LED_0);
}
if ((NRF_GPIOTE->EVENTS_IN[1] == 1)&&
(NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_IN1_Msk))
{
NRF_GPIOTE->EVENTS_IN[1] = 0;
LED_Toggle(LED_1);
}
if ((NRF_GPIOTE->EVENTS_IN[2] == 1)&&
(NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_IN2_Msk))
{
NRF_GPIOTE->EVENTS_IN[2] = 0;
LED_Toggle(LED_2);
}
if ((NRF_GPIOTE->EVENTS_IN[3] == 1)&&
(NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_IN3_Msk))
{
NRF_GPIOTE->EVENTS_IN[3] = 0;
LED_Toggle(LED_3);
}
}

Download my files


This work is licensed under a Creative Commons Attribution 4.0 International License.