2012-08-13 07:15 AM
Hi.
I'm trying to use Input Capture mode on Timer2 (channel 3) on an STM8S105 (discovery board). It won't work, and when i m watching peripheral registers with appropriated breakpoints, the registers aren't changing from default value. I m using STVD with cosmic compiler. I'm using firmware libraries. (i already checked out, that every macros was pointing to the right register.) Here's everything relevant in my code : CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2, ENABLE); GPIO_Init(GPIOD, GPIO_PIN_2, GPIO_MODE_IN_PU_NO_IT);//!\ modify option bytes : select TIMR2-CH3 for AFR1
TM2_DISABLE; //macro resetting CEN bit in TMR2->CR1 register
TIM2_DeInit();
TIM2_TimeBaseInit(TIM2_PRESCALER_1, 0xFEFE); // changed from FFFF to FEFE to see if it applies any change to ARR register, and it does not :\
TIM2_ICInit(TIM2_CHANNEL_3,
TIM2_ICPOLARITY_FALLING,
TIM2_ICSELECTION_DIRECTTI,
TIM2_ICPSC_DIV1,
0);
TIM2_ITConfig(TIM2_IT_CC3, ENABLE);
TIM2_CCxCmd(TIM2_CHANNEL_3, ENABLE);
TM2_ENABLE; //macro setting CEN bit in TMR2->CR1 register Has anyone a clue on chat i forgot to enable so this peripheral might work ?
2012-08-14 05:58 AM
here a more precise example :
TIM2->CR1 |= (uint8_t)TIM2_CR1_CEN; after this instruction i shall see register of TIM2-CR1 (address 0x5300) change from 0x00 to 0x01. But it won't work... and i already checked base_address, macros, ref manual, and peripheral registers, they re all pointing to the same address 0x5300. My clock is also enable. I'm using HSI as main clock.2012-08-14 06:39 AM
I finally found it, my mistake :\
i was enabling/disabling every peripheral clock, but i had kept timer5 and 6 whereas they re not on STM8S105, and timer5 and 2 share same adress. So disabling timer5 was disabling my clock.... Dumb mistake ...