I'm learning to use the MCU STM32f100RB, which is based on the arm cortex m3.
To test the timer 6, I wrote a bit of codes as following.It's supposed to make the led blink. But it does not work.Anyone can give me a hand telling me what's problem? Is the timer initialized correctly?
Thx
#include "stm32f10x.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_tim.h"
void delay_millisec(register unsigned short n);
int main(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB1Periph_TIM6, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //enable the pin 8 and pin 9
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
while(1)
{
GPIO_WriteBit(GPIOC, GPIO_Pin_8, Bit_RESET);
delay_millisec(1000);
GPIO_WriteBit(GPIOC, GPIO_Pin_8, Bit_SET);
delay_millisec(1000);
}
return 0;
}
void delay_millisec(register unsigned short n)
{
if (n > 1) n--;
TIM6->PSC = 23999; // Set prescaler to 24,000 (PSC + 1)
TIM6->ARR = n; // n = 1 gives 2msec delay rest are ok
TIM6->CNT = 0;
TIM6->EGR = TIM_EGR_UG; // copy values into actual registers!
// Enable timer in one pulse mode
TIM6->CR1 |= (TIM_CR1_OPM | TIM_CR1_CEN);
while (TIM6->CR1 & TIM_CR1_CEN); // wait for it to switch off
}
You are not enabling the timer peripheral's clock, from what I can see.
Note that your code does this:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB1Periph_TIM6, ENABLE);
^ ^ ^
| | |
APB2 APB2 APB1?!!
but this can't be right; you're using constants for peripheral clock 1 and 2 in the same call, to clock 2. That won't fly.
You need to have:
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
You really should be using the Standard Peripheral Library for the timer initialization too, no point in poking registers directly.
Related
Trying to get some simple DAC output before
moving forward. Have a multimeter on the output A2
but this seems to never change from about 1V6 for whatever value
I put into the DAC2 output function.
#include "stm32f4xx.h"
#include "stm32f4xx_dac.h"
void io_config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* DMA1 & DMA2 clock and GPIOA & GPIOC clock enable */
RCC_AHB1PeriphClockCmd( /*RCC_AHB1Periph_DMA1 | RCC_AHB1Periph_DMA2 |*/
RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOB, ENABLE);
/* DAC Periph clock, TIM2 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC | RCC_APB1Periph_TIM2, ENABLE);
/* ADC1 Periph Clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
DAC_InitTypeDef dac_init_s;
int main(void)
{
unsigned int i, adcr;
i = adcr = 0;
io_config ();
DAC_StructInit(&dac_init_s);
//dac_init_s.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
DAC_Init(DAC_Channel_2, &dac_init_s);
while(1) {
DAC_SetChannel2Data(DAC_Align_12b_R,500);
}
}
I do not use HAL for such a simple peripheral
Enable clock, configure GPIO pin
for channel 1
DAC -> CR |= DAC_CR_EN1;
DAC -> DHR12R1 = 454 /* your value */
for channel 2
DAC -> CR |= DAC_CR_EN2;
DAC -> DHR12R2 = 454 /* your value */
For waveform generation (using TIM6 and DAC Channel 1)
TIM6 -> DIER &= ~(TIM_DIER_UDE);
TIM6 -> DIER |= TIM_DIER_UDE;
TIM6 -> PSC = /* PSC value */
TIM6 -> ARR = /* PSC value */
TIM6 -> CR2 |= TIM_CR2_MMS_1;
DAC -> CR &= ~(DAC_CR_MAMP1 | DAC_CR_WAVE1);
DAC -> CR = DAC_CR_DMAEN1 | DAC_SR_DMAUDR1 | DAC_CR_TEN1 | DAC_CR_BOFF1;
DAC -> CR |= DAC_CR_EN1;
DMA1_Stream5 -> NDTR = /* Number of samples */
DMA1_Stream5 -> PAR = (uint32_t)&(DAC -> DHR12R1);
DMA1_Stream5 -> M0AR = (uint32_t)(/* address of the waveform data */);
DMA1_Stream5 -> CR = (DMA_SxCR_TEIE | DMA_SxCR_CHSEL | DMA_SxCR_CIRC | DMA_SxCR_DIR_0 | DMA_SxCR_EN | DMA_SxCR_PSIZE_0 | DMA_SxCR_MSIZE_0 | DMA_SxCR_MINC | DMA_SxCR_PL_0);
TIM6 -> CR1 |= TIM_CR1_CEN;
OK this WORKS! STM32F446RE NUCLEO DAC OUTPUT simple example
not tied to timers and/or DMA etc. SOLVED !!!
http://imgur.com/a/wuq4a
varsågod!
#include "stm32f4xx.h"
#include "stm32f4xx_dac.h"
void io_config2 (void) {
// Enable clocks for port A and DAC
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* DAC channel 2 Configuration */
DAC_InitTypeDef DAC_InitStructure2;
DAC_InitStructure2.DAC_Trigger = DAC_Trigger_None;
DAC_InitStructure2.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure2.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
DAC_Init(DAC_Channel_2, &DAC_InitStructure2);
/* DAC channel 1 Configuration */
DAC_InitTypeDef DAC_InitStructure1;
DAC_InitStructure1.DAC_Trigger = DAC_Trigger_None;
DAC_InitStructure1.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure1.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
DAC_Init(DAC_Channel_1, &DAC_InitStructure1);
/* Enable DAC Channel 1 and 2 */
DAC_Cmd(DAC_Channel_2, ENABLE);
DAC_Cmd(DAC_Channel_1, ENABLE);
}
DAC_InitTypeDef dac_init_s;
int main(void)
{
unsigned int i, adcr, j, k;
i = adcr = j = k = 0;
io_config2 ();
//DAC_Cmd( DAC_Channel_2, ENABLE);
DAC_Cmd( DAC_Channel_1, ENABLE);
while(1) {
#define OVAL 4095
//DAC_Cmd( DAC_Channel_2, DISABLE);
//DAC_SetChannel2Data(DAC_Align_12b_R, OVAL );
DAC_SetChannel1Data(DAC_Align_12b_R, OVAL ); /* 1000/4096 * 3V3 == 0V8 */
//if ( OVAL != DAC_GetDataOutputValue (DAC_Channel_2)) {
j = DAC_GetDataOutputValue (DAC_Channel_1);
k = DAC_GetDataOutputValue (DAC_Channel_2);
//}
}
}
#include "stm32f30x_conf.h"
uint16_t read_pos(void);
void PC_Conf(void);
uint8_t get_bit(uint8_t, uint8_t);
// PROCESSORTACT = 64 MHz
// AHB Prescaler = 1
// APB1 Prescaler = 2
// APB2 Prescaler = 1
long pin = 1;
long dir = 1;
char recvd;
int main(void){
/*
*/
//Definitions
GPIO_InitTypeDef GPIO_Initstructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_NVICInitStructure;
//ENABLE CLOCK
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
//GPIO
GPIO_Initstructure.GPIO_Mode=GPIO_Mode_OUT;
GPIO_Initstructure.GPIO_OType=GPIO_OType_PP;
GPIO_Initstructure.GPIO_Pin=GPIO_Pin_All;
GPIO_Initstructure.GPIO_PuPd=GPIO_PuPd_NOPULL;
GPIO_Initstructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_Initstructure);
//TIMER
TIM_TimeBaseInitStructure.TIM_Prescaler = (64000-1); //TIM2 cycle to 1kHz
TIM_TimeBaseInitStructure.TIM_Period = 500; //Every 500ms
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseInitStructure);
//NVIC
NVIC_NVICInitStructure.NVIC_IRQChannel=TIM2_IRQn;
NVIC_NVICInitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_NVICInitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_NVICInitStructure.NVIC_IRQChannelSubPriority=0;
NVIC_Init(&NVIC_NVICInitStructure);
//Enable everything
TIM_Cmd(TIM2, ENABLE);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
/* Infinite loop */
while (1)
{
}
}
void TIM2_IRQHandler(void)
{
GPIOB->ODR &= 0;
GPIOB->ODR ^=1<<pin;
//Pin to new value
if(dir == 1)
{
if(pin == 5)
pin=11;
else if(pin == 15)
{ pin-=1;
dir = 0;
}
else
pin+=1;
}
else
{
if(pin == 11)
pin = 5;
else if(pin == 1)
{
pin+=1;
dir = 1;
}
else
pin-=1;
}
TIM_ClearITPendingBit(TIM2,TIM_IT_Update);
}
I have trouble understanding this code. First part is okay, but I don't understand the last function.
Can someone explain me simply what is going on in the last part of this code in TIM2_IRQHandler(void)?
I am new in this, any help would be welcome.
In many interrupts you need to clear the interrupt pending flag. If you don't when you exit from the handler, the interrupt will be called again. Every interrupt is described in the Reference manual of your micro. For example SPI interrupt pending flag is cleared by writing or reading from the DR register. Another one requires that bit to be cleared by the programmer.
The rule of thumb: clear the flag as soon as you enter the interrupt.
If the interrupt can be triggered by more than one event, the programmer should check which one was the source of the exception.
I recently purchased a NUCLEO-F446RE board (an STM32F4 product) and one minor issue has been bugging me. All the code I've written executes and works just fine, but they only work after pressing the reset button on the NUCLEO board.
IDE: Keil v5
For example, I wrote code for a blinking LED:
#include "stm32f446xx.h"
int main(void) {
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;
GPIOA->MODER |= GPIO_MODER_MODE5_0;
GPIOA->ODR |= GPIO_ODR_OD5;
volatile int i;
while(1) {
for(i=0; i<100000; i++)
GPIOA->ODR |= GPIO_ODR_OD5;
for(i=0; i<100000; i++)
GPIOA->ODR &= ~GPIO_ODR_OD5;
}
}
After I run and download the code onto the board, nothing will happen. Once I press reset, the LED will blink as expected.
I'm fairly certain it's something not included in my code because when I run an example program it executes immediately.
For example, a blinking LED provided by KIEL:
#include <stdio.h>
#include "Board_LED.h" // ::Board Support:LED
#include "Board_Buttons.h" // ::Board Support:Buttons
#include "stm32f4xx.h" // Device header
extern int stdout_init (void);
volatile uint32_t msTicks; /* counts 1ms timeTicks */
/*----------------------------------------------------------------------------
* SysTick_Handler:
*----------------------------------------------------------------------------*/
void SysTick_Handler(void) {
msTicks++;
}
/*----------------------------------------------------------------------------
* Delay: delays a number of Systicks
*----------------------------------------------------------------------------*/
void Delay (uint32_t dlyTicks) {
uint32_t curTicks;
curTicks = msTicks;
while ((msTicks - curTicks) < dlyTicks) { __NOP(); }
}
/*----------------------------------------------------------------------------
* SystemCoreClockConfigure: configure SystemCoreClock using HSI
(HSE is not populated on Nucleo board)
*----------------------------------------------------------------------------*/
void SystemCoreClockConfigure(void) {
RCC->CR |= ((uint32_t)RCC_CR_HSION); /* Enable HSI */
while ((RCC->CR & RCC_CR_HSIRDY) == 0); /* Wait for HSI Ready */
RCC->CFGR = RCC_CFGR_SW_HSI; /* HSI is system clock */
while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_HSI); /* Wait for HSI used as system clock */
FLASH->ACR = (FLASH_ACR_PRFTEN | /* Enable Prefetch Buffer */
FLASH_ACR_ICEN | /* Instruction cache enable */
FLASH_ACR_DCEN | /* Data cache enable */
FLASH_ACR_LATENCY_5WS ); /* Flash 5 wait state */
RCC->CFGR |= (RCC_CFGR_HPRE_DIV1 | /* HCLK = SYSCLK */
RCC_CFGR_PPRE1_DIV2 | /* APB1 = HCLK/2 */
RCC_CFGR_PPRE2_DIV1 ); /* APB2 = HCLK/1 */
RCC->CR &= ~RCC_CR_PLLON; /* Disable PLL */
/* PLL configuration: VCO = HSI/M * N, Sysclk = VCO/P */
RCC->PLLCFGR = ( 16ul | /* PLL_M = 16 */
(200ul << 6) | /* PLL_N = 200 */
( 0ul << 16) | /* PLL_P = 2 */
(RCC_PLLCFGR_PLLSRC_HSI) | /* PLL_SRC = HSI */
( 7ul << 24) | /* PLL_Q = 7 */
( 2ul << 28) ); /* PLL_R = 2 */
RCC->CR |= RCC_CR_PLLON; /* Enable PLL */
while((RCC->CR & RCC_CR_PLLRDY) == 0) __NOP(); /* Wait till PLL is ready */
RCC->CFGR &= ~RCC_CFGR_SW; /* Select PLL as system clock source */
RCC->CFGR |= RCC_CFGR_SW_PLL;
while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL); /* Wait till PLL is system clock src */
}
/*----------------------------------------------------------------------------
* main: blink LED and check button state
*----------------------------------------------------------------------------*/
int main (void) {
int32_t max_num = LED_GetCount();
int32_t num = 0;
SystemCoreClockConfigure(); /* configure HSI as System Clock */
SystemCoreClockUpdate();
LED_Initialize();
Buttons_Initialize();
stdout_init(); /* Initializ Serial interface */
SysTick_Config(SystemCoreClock / 1000); /* SysTick 1 msec interrupts */
for (;;) {
LED_On(num); /* Turn specified LED on */
Delay(500); /* Wait 500ms */
while (Buttons_GetState() & (1 << 0)); /* Wait while holding USER button */
LED_Off(num); /* Turn specified LED off */
Delay(500); /* Wait 500ms */
while (Buttons_GetState() & (1 << 0)); /* Wait while holding USER button */
num++; /* Change LED number */
if (num >= max_num) {
num = 0; /* Restart with first LED */
}
printf ("Hello World\n\r");
}
}
The example code doesn't appear to have anything special that will make it run immediately.
Any help is greatly appreciated.
My guess is that it's in the project flash tools settings, maybe "run to main" or "Load Application at Startup" (not your code). To check, copy/paste your code over the top of one of the samples.
In Kiel Following Steps Follow:
Go to "Flash" options.
In flash, go to "Configure Flash Tools".
Go to the last bar/option "Utilities"
In utilities chose "Settings" options.
Finally,tick "Run and Reset" Options.
upload the code, it working without a click reset button.
I got the same problem. In Keil you need to go to "Flash -> Configure Flash Tools -> Utilities" and turn on "Run and reset" option
Regards:)
I have smt32l1xx board and this code below is not working. Debugger shows pinA5 is set, but diode connected to this pin is still not lightening. I dont know why. Even i add delay after setting bit it is not working. diode is connected to PA5 and GND on board.
#include <stm32l1xx.h>
#define ENABLE 1
#define DISABLE 0
void TIM2_IRQHandler() //interrupt
{
if (TIM_GetITStatus(TIM2, TIM_IT_Update) == SET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
if (GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_5))
GPIO_ResetBits(GPIOA, GPIO_Pin_5); //LED OFF
else
GPIO_SetBits(GPIOA, GPIO_Pin_5); //LED ON <- im here and still nothing
}
}
int main(void)
{
/* gpio init struct */
GPIO_InitTypeDef gpio;
TIM_TimeBaseInitTypeDef tim;
NVIC_InitTypeDef nvic;
/* reset rcc */
RCC_DeInit();
RCC_APB2PeriphClockCmd(RCC_AHBENR_GPIOAEN, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
GPIO_StructInit(&gpio);
/* use pin 0 */
gpio.GPIO_Pin = GPIO_Pin_5;
/* mode: output */
gpio.GPIO_Mode = GPIO_Mode_OUT;
/* apply configuration */
GPIO_Init(GPIOA, &gpio);
TIM_TimeBaseStructInit(&tim); //timer
tim.TIM_CounterMode = TIM_CounterMode_Up;
tim.TIM_Prescaler = 64000 - 1;
tim.TIM_Period = 1000 - 1;
TIM_TimeBaseInit(TIM2, &tim);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM2, ENABLE);
nvic.NVIC_IRQChannel = TIM2_IRQn; //interrupt
nvic.NVIC_IRQChannelPreemptionPriority = 0;
nvic.NVIC_IRQChannelSubPriority = 0;
nvic.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvic);
while (1)
{
}
/* never reached */
return 0;
}
To make sure that your hardware is properly initialized, you should use STM32CubeMX.
It seems that the GPIOA clock is on the AHB bus, however you call RCC_APB2PeriphClockCmd which is for APB2. So try to use the equivalent for AHB something like RCC_AHBPeriphClockCmd
I am currently working on STM32F3 Discovery Board. I wrote a basic program in C to see if it works at 72 MHz which is about 14 ns in time. Hopefully it worked at this frequency, but when I want to toggle just one random pin on the device, turning it ON or OFF takes 660 ns in an infinite while loop. Then I checked with an oscilloscope, how much each command takes. Values might not be exact, Here is what I found;
a while loop(only for checking) = 120 ns, a "for" loop(only for checking) = 160 ns
One turn of a while loop = 280 ns, one turn of a for loop = 320 ns, which means each turn takes 160 ns.
asm("NOP") = 14 ns(which must be equal to operator frequency(72 MHz, as expected), an empty function call = 225 ns
I don't think these values are same for other compilers, or other computers, but I am not even close to 72 MHz. Minimum interrupt I got was 2 microsecond. Is there any way to minimize these values? Is there anyway to increase the gcc compiler speed?
#include "stm32f30x.h"
#include <common.h>
void InitializeTimer(void) ;
void EnableTimerInterrupt(void);
void TIM2_IRQHandler(void);
GPIO_InitTypeDef configuration;
void dly(int dly_nmbr);
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//NVIC_InitTypeDef NVIC_InitStructure;
RCC_ClocksTypeDef RCC_ClockFreq;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* Configure PA10 in output pushpull mode */
/*****I called init_pin function from common.c because it was easier
but I guess it takes some time too*********/
init_pin(GPIOA,GPIO_Pin_10,GPIO_Mode_OUT,GPIO_Speed_50MHz,GPIO_OType_PP,GPIO_PuPd_NOPULL);
/****I tried usual way to configure the pins too****/
//configuration.GPIO_Pin = GPIO_Pin_10;
//configuration.GPIO_Mode = GPIO_Mode_OUT;
//configuration.GPIO_OType = GPIO_OType_PP;
//configuration.GPIO_Speed = GPIO_Speed_50MHz;
//configuration.GPIO_PuPd = GPIO_PuPd_NOPULL;
//GPIO_Init(GPIOA, &configuration);
//InitializeTimer();
/*** This function fills the RCC_ClockFreq structure with the current
frequencies of different on chip clocks (for debug purpose) **************/
RCC_GetClocksFreq(&RCC_ClockFreq);
/* Enable Clock Security System(CSS): this will generate an NMI exception
when HSE clock fails *****************************************************/
RCC_ClockSecuritySystemCmd(ENABLE);
/* Enable and configure RCC global IRQ channel, will be used to manage HSE ready
and PLL ready interrupts.
These interrupts are enabled in stm32f0xx_it.c file **********************/
/* I disabled the interrupts for the purpose of maximizing the program speed*/
// NVIC_InitStructure.NVIC_IRQChannel = RCC_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
// NVIC_Init(&NVIC_InitStructure);
/************* Output HSE clock on MCO1 pin(PA8) ************/
/****************** Enable the GPIOA Clock ******************/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* MCO pin configuration: PA8 */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Output System Clock on MCO pin */
RCC_MCOConfig(RCC_MCOSource_SYSCLK);
/************** This is the toggling part. I tried each command here ***************/
while(1)
{
// volatile int i = 0;
// dly(0);
/*I called an empty function called dly before and after the toggle
to see function call time*/
GPIO_Toggle(GPIOA,GPIO_Pin_10);
// dly(0);
// while(i<=0)
// {
// i++;
// }
// for(i=0;i<=0;i++);
}
}
/*Empty Function*/
void dly(int dly_nmbr)
{
}
/************** Interrupt Functions **************/
// void TIM2_IRQHandler()
// {
// if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
// {
// TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
// }
// }
// void InitializeTimer()
// {
// RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
//
// TIM_TimeBaseInitTypeDef timerInitStructure;
// timerInitStructure.TIM_Prescaler = 0;
// timerInitStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned2;
// timerInitStructure.TIM_Period = 2;
// timerInitStructure.TIM_ClockDivision = 0x0000;
// timerInitStructure.TIM_RepetitionCounter = 100;
// TIM_TimeBaseInit(TIM2, &timerInitStructure);
//
// TIM_Cmd(TIM2, ENABLE);
// TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
// EnableTimerInterrupt();
// }
// void EnableTimerInterrupt()
// {
// NVIC_InitTypeDef nvicStructure;
// nvicStructure.NVIC_IRQChannel = TIM2_IRQn;
// nvicStructure.NVIC_IRQChannelCmd = ENABLE;
// // TIM2->ARR = 1;
// // TIM2->PSC = 1;
// NVIC_Init(&nvicStructure);
//
// }
/****************** EOF ********************/