Professional Documents
Culture Documents
1
Florida, Orlando, Key West, Miami Travel
Learning Object
How to Design a Control Program That Turns On/Off of 1 LED with a switch using the
interrupt method
2
Refer p.88
1. 인터럽트 (Interrupt)
• 인터럽트는 프로그램을 실행하는 도중에 예기치 않은 상황이 발생할 경우 현재 실행중인 작업을 즉시 중단하고
발생된 상황을 우선 처리한 후 실행 중이던 작업으로 복귀하여 계속 처리하는 것
2. 인터럽트 발생 종류
• 외부 인터럽트
• 내부 인터럽트
• 소프트웨어 인터럽트
Refer p.88
3
Refer p.88
3. 인터럽트 (interrupt) 처리 방식 (1 of 2)
Refer p.88
4. 인터럽트 요청 시 처리 과정
• 인터럽트 발생 인터럽트 요구
• 인터럽트 처리 루틴 수행
4
Class-1 : How to design a control program that turns
on/off 1 LED with a switch using the
interrupt method
2. MCU/MPU Selector
-Core : Arm Cortex-M4
-Series : STM32F4
-Line : STM32F429/439
-Package : LQFP144
-Next
-Project Name : INT_EX4_8
-Finish
5
2. Pinout & Configuration (1 of 4) Refer p.101
6
2. Pinout & Configuration (3 of 4) Refer p.101
-Set the GPIOD port to CubeMX -Set the port output of GPIOD (LED1) to CubeMX with CubeMX
-Set the ports of GPIOG (SW1, SW2) as interrupts with CubeMX
-PD0 LED1 Output
-PG0/1 SW1, SW2 (using interrupt method)
7
3. Clock Configuration Refer p.101
It does not matter whether the clock setting is the default setting value
First of all today, we will be started with an example program as a way to understand the
concept of interrupt handling. Because there is a lot of content related to interrupts.
In the next time, we will be added more details about interrupts and interrupt service
routines.
The contents (ADC, TIMER) that continue from the next time describe the contents of the
interrupt.
8
4. Coding : main.h & main.c Refer p.101
main.h (1 of 1)
main.h (1 of 1)
9
main.c (1 of 4) Refer p.101
uint16_t flag= 0;
int main(void)
{
/* Initialize all configured peripherals */
10
main.c (3 of 4) Refer p.101
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
if (flag == 1){
HAL_GPIO_WritePin (GPIOD, GPIO_PIN_0, GPIO_PIN_SET);
}
if (flag== 0)
{
HAL_GPIO_WritePin (GPIOD, GPIO_PIN_0, GPIO_PIN_RESET);
}
11
stm32f4xx_it.c (1 of 2) This file is where Interrupt Service Routines are defined. Refer p.101
HAL_GPIO_EXTI_IRQHandler (GPIO_PIN_0);
12
Class-2 : How to design a control program that turns
on/off 1 LED with a switch using the
interrupt method
main.h (1 of 1)
13
main.c (1 of 3) Refer p.111
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
GPIO_InitTypeDef LEDConfig;
GPIO_InitTypeDef SWConfig;
LEDConfig.Pin = GPIO_PIN_0;
LEDConfig.Mode = GPIO_MODE_OUTPUT_PP; // Without this code, the LED will not turn on
HAL_GPIO_Init (GPIOD, &LEDConfig);
while(1)
{
14
main.c (3 of 3) Refer p.111
if (GPIO_Pin == GPIO_PIN_1 )
HAL_GPIO_WritePin (GPIOD, GPIO_PIN_0, GPIO_PIN_RESET);
}
/*****************************************************************************/
/* STM32F4xx Peripheral Interrupt Handlers */
/* Add here the Interrupt Handlers for the used peripherals. */
/* For the available peripheral interrupt handler names, */
/* please refer to the startup file (startup_stm32f4xx.s). */
/*****************************************************************************/
15
Class-3 : How to design a control program that turns
on/off 1 LED with a switch using the
interrupt method and register direct access
Refer p.112
1. Project
-Same as INT_EX4_8, INT_EX4_11
2. Clock Configuration
-Same as Example INT_EX4, INT_EX4_11
16
5. Coding : main.h & main.c Refer p.112
main.h (1 of 1)
uint16_t flag=0;
17
main.c (2 of 4) Refer p.112
int main(void) These two codes are absolutely necessary
{
/* USER CODE BEGIN 2 */
// GPIOG PG0~PG1 input SYSCFG external interrupt configuration registers, Address offset: 0x08-0x14
GPIOG->OSPEEDR &= 0x00000000;
GPIOG->PUPDR &= 0x00000000; -If an interrupt is applied to pin PG0/1 If I delete this
code, it doesn't work
// SYSCFG
SYSCFG->EXTICR[0] = (SYSCFG_EXTICR1_EXTI0_PG | SYSCFG_EXTICR1_EXTI1_PG);
NVIC_SetPriority (EXTI0_IRQn,0);
NVIC_EnableIRQ (EXTI0_IRQn);
NVIC_SetPriority (EXTI1_IRQn,0);
NVIC_EnableIRQ (EXTI1_IRQn);
18
main.c (2 of 4) for explanation Refer p.112
6 6
typedef struct
{
__IO uint32_t MEMRMP; /*!< SYSCFG memory remap register, Address offset: 0x00 */
__IO uint32_t PMC; /*!< SYSCFG peripheral mode configuration register, Address offset: 0x04 */
__IO uint32_t EXTICR[4]; /*!< SYSCFG external interrupt configuration registers, Address offset: 0x08-0x14 */
uint32_t RESERVED[2]; /*!< Reserved, 0x18-0x1C */
__IO uint32_t CMPCR; /*!< SYSCFG Compensation cell control register, Address offset: 0x20 */
} SYSCFG_TypeDef;
19
main.c (2 of 4) for explanation Refer p.112
EXTI->IMR
1 1 1 1
EXTI->EMR
GPIOG1, GPIOG0
EXTI->RTSR |= 0x0000000F;
EXTI->RTSR
1 1 1 1
EXTI->FTSR
8 4 2 1
1 0 1 0
20
main.c (3 of 4) Refer p.112
/* Infinite loop */
while (1)
{
if(flag ==1)
GPIOD->ODR |= 0x00000001;
if(flag ==0)
GPIOD->ODR &= 0xFFFF0000;
21
Stm32f4xx_it.c Refer p.112
Summary : Day-5
22