I'm new to Cortex M4 and programming on a microcontroller. I'm still learning the basics.
I'm using this board (stm32f411re), here is the reference manual.
I am trying to make an interrupt on the press of a button (the user button which is connected to the "PC13" port (pin 2)). First, I'm trying to initialize the button so when I click it, it will fire one exception.
Here is my code :
void button_init(void)
{
<======== PART THAT I'M TRYING TO UNDERSTAND ========>
// Enable GPIOC clock because BUTTON is connected to GPIOC
RCC->AHB1ENR |= 0x04; // (page 114)
// Configure the mode
GPIOC->MODER &= ~0x3; // GPIO port mode register (page 153)
GPIOC->PUPDR &= ~0x3; // GPIO port pull-up/pull-down register (page 156)
<======== PART THAT I'M TRYING TO UNDERSTAND ========>
//System configuration controller clock enable (page 118)
RCC->APB2ENR |= 0x00004000;
SYSCFG->EXTICR[3] |= (0x02 << 4); // (page 139)
//configure the interrupt for exti 13 line
// EXTI->IMR |= (0x01 << 13)// enable interrupt on EXTI 13
EXTI->IMR |= 0x01;
// EXTI->RTSR |= 0X01;
// EXTI->FTSR |= (0X01 << 13) // sensitive to falling edge
EXTI->FTSR |= 0X01;
//nvic configuration
NVIC->IP[EXTI15_10_IRQn] = 0x00;
NVIC_EnableIRQ(EXTI15_10_IRQn); // EXTI15_10_IRQn must be 40.. please confirm
}
- Here are my questions :
Am I right with this calculation ~0x3 = ~(0000 0011) = 1111 1100
?
So when I do GPIOC->MODER &= ~0x3;
, am I setting the first to bits of this register to 00 (input mode)?
Should I set other two bits of this register ? How can I know wich two bits of this register are linked with my button ?
Same questions with GPIOC->PUPDR &= ~0x3;
Finally, I want to enable a clock so I do RCC->APB2ENR |= 0x00004000;
: 0x00004000 = 0100 0000 0000 0000
=> I set the 16th bit of this register which is "TIM9 clock enable". Is that what we want to do ? Why TIM9 and not TIM10 or TIM11 ?
Thank you very much!