Timer-INT in C für das mySTM32 Board Light

//---------------------------------------------------------------------------
// Title     : simple Timer-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"

void initApplication()
{
 
	SysTick_Config(SystemCoreClock/100);
	// weitere Initialisierungen durchführen
 
	// GPIOD Takt einschalten 
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
 
	// Konfiguriere PD15 
	GPIO_InitTypeDef  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);
 
	// Takt für Timer einschalten
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM16, ENABLE);
 
	// Timer konfigurieren
	TIM_TimeBaseInitTypeDef TIM_TimeBase_InitStructure;
	TIM_TimeBase_InitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
	TIM_TimeBase_InitStructure.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBase_InitStructure.TIM_Period = 4800;
	TIM_TimeBase_InitStructure.TIM_Prescaler = 10000;
	TIM_TimeBaseInit(TIM16, &TIM_TimeBase_InitStructure);
	TIM_ITConfig(TIM16, TIM_IT_Update, ENABLE);
 
	// Timer einschalten
 	TIM_Cmd(TIM16, ENABLE);
 
	// Interruptcontroller konfigurieren
	NVIC_InitTypeDef NVIC_InitStructure;
	NVIC_InitStructure.NVIC_IRQChannel = TIM16_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_InitStructure.NVIC_IRQChannelPriority = 0x03;
	NVIC_Init(&NVIC_InitStructure);
 
}
 
int main(void)
{
	SystemInit();
	initApplication();
	while(true)
	{
		//leer
	}
}
 
extern "C" void SysTick_Handler(void)
{
	//leer		
}
 
extern "C" void TIM16_IRQHandler()
{  
	GPIO_ToggleBits(GPIOB,GPIO_Pin_0);		
	TIM_ClearITPendingBit(TIM16, TIM_IT_Update);
}
//------------------------------------------------------------------------------

Version mit der STM32 HAL Library

Version mit der STM32 LL Library

Weiter mit