2013-08-13 07:05 AM
Hi,
Could someone explain me how external clock for timer is done. Specially I don't understand how TI1, TI2 etc., are mapped to the physical pin. Alternate function on GPIO is mapped to different timers but is it the TIx pins? Thanks John #external-clock-timer-ti2-ti12013-08-13 08:59 AM
2013-08-14 06:09 AM
Thanks for your answer.
I have problem getting the TIMER2 working. I am polling for the UIF flag on my while loop. But it is never set. (BTW I did not use the library but by writing to registers) Here is my code./
**--------- MAIN -----------*/
while(1)
{
if
((TIM2->
SR
& 0x0001) == 0x001)
// Check for UIF flag
{ GPIOD->ODR
|= 0x2000;
// turn on led
TIM2->
SR
&= 0xfffe;
// Clear the flag
} }/***------- TIMER 2 INITIALISE ------------*/
void
InitTimer2()
{// Enable the clock for TIMER 2
RCC_AHB1PeriphClockCmd(RCC_APB1Periph_TIM2,
ENABLE
);
//NOT holding in reset
RCC->APB1RSTR
&= ~RCC_APB1RSTR_TIM2RST;
//TIMxCR1 -- Control Register 1
TIM2->CR1
= 0x0000;
TIM2->CR1
|= TIM_CR1_ARPE;
//Auto
Preload
Enable is buffered/*------ TIM2_CR2 CONTROL REGISTER 2 ----*/
TIM2->
CR2
= 0x00;
// Don't care for now/*------ TIM2_SMXR Slave Mode
Ctrl
REGISTER ----*/// Selects the internal clock
TIM2->
SMCR
= 0x00;
//
/*------ TIM2_DIER Interrupt/DMA Enable Register ----*/
TIM2->
DIER
= 0x0000;
TIM2->DIER
|= TIM_DIER_UIE;
// Update interrupt Enable
TIM2->
PSC
= 0x0f;
// Prescalar
TIM2->ARR
= 0xffff;
// Auto Reload register
TIM2->SR
&= 0xfffe;// Clear the UIF flag
TIM2->CR1
|= TIM_CR1_CEN;
// Counter Enable
} Thanks John2013-08-14 07:38 AM
I don't care for register level programming, you'll need to own that choice.
RCC_AHB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); << NOT AHB1 TIM2->SR &= 0xfffe; << NOT RMW, just WRITE 0xFFFE (ie ~1)2013-08-14 08:26 AM
Thank you clive for spotting the mistake.
Everything works now
. Writing to registers gives me more understanding (for getting started). Will switch to libraries once I understood how things work.(right practice??). Thanks Again John