2016-12-21 04:02 AM
I am trying to run a code in which timer causes an interrupt and everytime interrupt is generated, a variable h is incremented, but it remains zero in quickwatch window. My code is written below in stvd and cosmic compiler.
#include 'stm8s.h'
#include 'stm8s_tim1.h'#include 'stm8s_itc.h'#define TIM1_PSCRH (*(volatile uint8_t *)0x5260)
#define TIM1_CR1 (*(volatile uint8_t *)0x5250)#define TIM1_ARRH (*(volatile uint8_t *)0x5263)#define TIM1_ARRL (*(volatile uint8_t *)0x5264)#define TIM1_PSCRL (*(volatile uint8_t *)0x5261)#define TIM1_IER (*(volatile uint8_t *)0x5254)int h;
void main(void)
{ //TIM1_SetCounter(5);enableInterrupts();GPIO_Config(); //TIM1_DeInit();TIM1_ARRH=0X55;
TIM1_ARRL=0X26;TIM1_PSCRH = 0x3e;TIM1_PSCRL = 0x80;TIM1_CR1=0X81;TIM1_IER=0X01;enableInterrupts(); while(1) { } }INTERRUPT_HANDLER (TIM1_UPD_OVF_IRQHANDLER,23)
//@interrupt @far void TIM1_OVF_TRG_BRK_IRQ_Handler(void){ h++;}#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */void assert_failed(uint8_t* file, uint32_t line){ /* User can add his own implementation to report the file name and line number, ex: printf('Wrong parameters value: file %s on line %d\r\n', file, line) *//* Infinite loop */
while (1) { }}#endifWhat is wrong with the code? Kindly help me.
Thank you.
2016-12-21 06:48 AM
Hi,
try to use : volatile int h;
Regards
Andreas
2016-12-21 07:28 AM
Are you using the debugger?
Is the code enabling timer internal clock so you can actually write the timer registers?
In an old code, I've got this:
CLK_PeripheralClockConfig(CLK_Peripheral_TIM1, ENABLE);
Put as first step... (STM8L151)
==============================
Digging at the std lib:
void CLK_PeripheralClockConfig(CLK_Peripheral_TypeDef CLK_Peripheral, FunctionalState NewState)
{ /* Check the parameters */ assert_param(IS_CLK_PERIPHERAL(CLK_Peripheral)); assert_param(IS_FUNCTIONAL_STATE(NewState));if (((uint8_t)CLK_Peripheral & (uint8_t)0x10) == 0x00)
{ if (NewState != DISABLE) { /* Enable the peripheral Clock */ CLK->PCKENR1 |= (uint8_t)((uint8_t)1 << ((uint8_t)CLK_Peripheral & (uint8_t)0x0F)); } else { /* Disable the peripheral Clock */ CLK->PCKENR1 &= (uint8_t)(~(uint8_t)(((uint8_t)1 << ((uint8_t)CLK_Peripheral & (uint8_t)0x0F)))); } } else { if (NewState != DISABLE) { /* Enable the peripheral Clock */ CLK->PCKENR2 |= (uint8_t)((uint8_t)1 << ((uint8_t)CLK_Peripheral & (uint8_t)0x0F)); } else { /* Disable the peripheral Clock */ CLK->PCKENR2 &= (uint8_t)(~(uint8_t)(((uint8_t)1 << ((uint8_t)CLK_Peripheral & (uint8_t)0x0F)))); } }}and yes, you need to declare the variable as volatile to be sure.
2016-12-21 02:08 PM
Have you enabled the interrupt at NVIC Level?
2016-12-21 11:10 PM
Thanks, but declaring variable h as volatile didn't make any change.
2016-12-21 11:13 PM
Thanks, I am using stm8s003k3 board with debugger, but the value of h is seen as 0 in simulator also.
2016-12-21 11:15 PM
Thanks, do I have to edit any of the header files to enable interrupt at NVIC level?
2016-12-21 11:21 PM
Also, putting line
CLK_PeripheralClockConfig(CLK_Peripheral_TIM1, ENABLE);
resulted in error 'redeclared external CLK_PeripheralClockConfig'
2016-12-22 03:23 AM
This type of error seems to tell the source code has an issue like missing/too many ) or }
Calling a function should not yield such error.
2016-12-22 05:23 AM
I have included stm8s_itc.h. I have seen somewhere stm8s_it.h file being included, which I think, is supported for raisonance as well as cosmic. When I include that file, another error takes place 'symbol f_NonHandeledInterrupt multiply defined'
Thank you.