Interrupts in C für das mySTM32 Board Light

//---------------------------------------------------------------------------
// Title     : simple extern INT Solution, ARM C application in SiSy
//---------------------------------------------------------------------------
// Function  : ...
// Wiring    : ...
//---------------------------------------------------------------------------
// Hardware  : ...
// Clock     : ... MHz
// Language  : ARM C
// Date      : ...
// Version   : ...
// Author    : ...
//---------------------------------------------------------------------------
#include <stddef.h>
#include <stdlib.h>
#include "hardware.h"

GPIO_InitTypeDef 	GPIO_InitStructure;
EXTI_InitTypeDef   	EXTI_InitStructure;
NVIC_InitTypeDef   	NVIC_InitStructure;
volatile bool mustToggle;
 
void initApplication()
{
	SysTick_Config(SystemCoreClock/100);
	// weitere Initialisierungen durchführen
 
	mustToggle=false;
 
	/* Enable the BUTTON Clock */
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
	/* Configure Button pin as input */
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
	GPIO_Init(GPIOA, &GPIO_InitStructure);
 
 	/* Enable SYSCFG AF clock */
	RCC_APB2PeriphClockCmd(RCC_APB2ENR_SYSCFGEN, ENABLE);
 
	/* Connect EXTI0 Line to PA0 pin */
	SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
	EXTI_InitStructure.EXTI_Line = EXTI_Line0;
	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;  
	EXTI_InitStructure.EXTI_LineCmd = ENABLE;
	EXTI_Init(&EXTI_InitStructure);
 
	/* Enable and set Button EXTI Interrupt to the lowest priority */
	NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPriority = 0x03;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure); 
 
	/* Enable the LED Clock */
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
 
	/* Configure red LED in output pushpull mode */
	GPIO_StructInit(&GPIO_InitStructure);	
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
	GPIO_Init(GPIOB, &GPIO_InitStructure);	
 
}
int main(void)
{
	SystemInit();
	initApplication();
	do
	{
 
		if (mustToggle)
		{
			GPIO_SetBits(GPIOB,GPIO_Pin_0);
			waitMs(100);
			GPIO_ResetBits(GPIOB,GPIO_Pin_0);
			waitMs(100);
		}
		else
			GPIO_ResetBits(GPIOB,GPIO_Pin_0);
 
	}
	while (true);
	return 0;
}
 
extern "C" void SysTick_Handler(void)
{
	// Application SysTick
}
 
extern "C" void EXTI0_1_IRQHandler()
{
	GPIO_SetBits(GPIOB,GPIO_Pin_0);
	
	if (mustToggle)
		mustToggle=false;
	else
		mustToggle=true;
 
	EXTI_ClearITPendingBit(EXTI_Line0);
}
//------------------------------------------------------------------------------

Test

Nutzen sie die Schaltflächen Kompilieren, Linken und Brennen. Stellen Sie die nötigen Verbindungen auf dem Board mit den dafür vorgesehenen Patchkabeln her. Testen Sie die Anwendung.

Weiter mit