Ich habe mal ihre code mit den IAR compiler in meines Discovery board versucht. Das scheint zu functionieren. Jeden mal das ich den user button drucke, erhoht die variable "INT_count", und die LEDS fangen an zu blinken Ich habe nur kleine aenderungen gemacht wegend andere compiler. Moglich sind andere systemfiles auch noch wichtig (Clock Init).
Ich kopîere das nochmal hierein.
Code:
/* Includes */
#include <stddef.h>
#include "stm32f10x.h"
/* ---------------------------Private typedef -------------------------------*/
TIM_TimeBaseInitTypeDef TIM2_Configuration;
NVIC_InitTypeDef NVIC_InitStructure;
//TIM_OCInitTypeDef Output_Compare;
TIM_ICInitTypeDef Input_Capture;
GPIO_InitTypeDef GPIO_Inity;
/*---------------------------Global Variable---------------------------------*/
volatile uint32_t INT_Counter = 0;
volatile uint32_t delayCount;
/************************************************** *****************************
# * Function Name : RCC_cONFIGURATION
# * Description : .
# * Input : None
# * Output : None
# * Return : None
# ************************************************** *****************************/
void RCC_Configuration(void)
{
/* TIM2clock= SystemCoreColock, enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* GPIOA clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
/* ALTERNATE FUNCTION ENABLE*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
/* GPIOC clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
}
/************************************************** *****************************
# * Function Name : GPIO_SETUP
# * Description : .
# * Input : None
# * Output : None
# * Return : None
# ************************************************** *****************************/
void GPIO_Setup ()
{
/* LEDs pin (PC.08 and 09) configuration */
GPIO_Inity.GPIO_Pin =GPIO_Pin_8 | GPIO_Pin_9;
GPIO_Inity.GPIO_Mode =GPIO_Mode_Out_PP;
GPIO_Inity.GPIO_Speed =GPIO_Speed_50MHz;
/* TIM2 PA.0 configuration*/
GPIO_Inity.GPIO_Mode =GPIO_Mode_IN_FLOATING;// soll ich PULL-Down oder Pull up werwenden wenn der
//Eingang als Pull-Down Konfiguriert?
//Der AF weil bei dieser Pin wir der Alternate Function verwendet
GPIO_Inity.GPIO_Speed =GPIO_Speed_50MHz;
GPIO_Inity.GPIO_Pin =GPIO_Pin_0;
GPIO_Init(GPIOA, &GPIO_Inity);
GPIO_Init(GPIOC, &GPIO_Inity);
}
/************************************************** *****************************
# * Function Name : TIM2_SETUP
# * Description : Timer2 as Output/Compare
# * Input : None
# * Output : None
# * Return : None
# ************************************************** *****************************/
void TIM2_SETUP ()
{
/*----Time_Base_Counter-----*/
TIM2_Configuration.TIM_CounterMode= TIM_CounterMode_Up;
TIM2_Configuration.TIM_ClockDivision= 0;
TIM2_Configuration.TIM_Period=65535;
TIM2_Configuration.TIM_Prescaler=1;
TIM_TimeBaseInit(TIM2,&TIM2_Configuration);
/*----Input_Capture Mode CH1----*/
Input_Capture.TIM_ICSelection = TIM_ICSelection_DirectTI;// hier verstehe ich der Unterschied
// zwischen Direct und Indirekt nicht
//wirklich, aber ich verwende Direct weil ich
// kein remaping durchführe
Input_Capture.TIM_ICPolarity= TIM_ICPolarity_Rising;
Input_Capture.TIM_ICPrescaler = TIM_ICPSC_DIV1;
Input_Capture.TIM_Channel= TIM_Channel_1;
Input_Capture.TIM_ICFilter = 0;
TIM_ICInit(TIM2, &Input_Capture);
TIM_Cmd(TIM2, ENABLE);
/*----Enable the Capture Compare Interrupt Request-----*/
TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);
}
/************************************************** *****************************
# * Function Name : Configure the nested vectored interrupt controller.
# * Description : .
# * Input : None
# * Output : None
# * Return : None
# ************************************************** *****************************/
void NVIC_SETUP ()
{
/* Enable the TIM2 global Interrupt */
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
NVIC_InitStructure.NVIC_IRQChannel= TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd= ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/************************************************** *****************************
# * Function Name : delayloop
# * Description : .
# * Input : None
# * Output : None
# * Return : None
# ************************************************** *****************************/
void delayLoop()
{
delayCount = 1000000;
while (delayCount > 0)
{
delayCount--;
}
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++*/
int main (void)
{
RCC_Configuration();
GPIO_Setup();
TIM2_SETUP();
NVIC_SETUP();
while (1)
{
if(INT_Counter >1)
{
GPIOC->BSRR = GPIO_Pin_8; // LED On
delayLoop();
GPIOC->BRR = GPIO_Pin_8; // LED Off
delayLoop();
GPIOC->BSRR = GPIO_Pin_8; // LED On
delayLoop();
GPIOC->BRR = GPIO_Pin_8; // LED Off
delayLoop();
GPIOC->BSRR = GPIO_Pin_9; // LED On
delayLoop();
GPIOC->BRR = GPIO_Pin_9; // LED Off
delayLoop();
}
}
return 0;
}
//steht bei mir in eine ander file : STM32F10x_it.c
void TIM2_IRQHandler (void)
{
// Interrupt Flag muß per Software gelöscht werden
TIM_ClearFlag(TIM2, TIM_FLAG_CC1);
//TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);
INT_Counter++;
}
Ha der Atollic compiler auchj eine debugger ?
Fiel erfolg !!
Lesezeichen