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.
2017-01-04 02:08 PM
NVIC is the CortexM interrupt controller in STM32 devices. Therefore ignore my post as you are working with STM8.
2017-01-05 12:55 AM
Have you enabled the interrupts?
enableInterrupts(); // usally before the main while loop...
therefore you have to include: stm8l15x.h
2017-01-08 11:55 PM
TIM1_CR1=0X81;
TIM1_IER=0X01;�?�?
Change to
TIM1_IER=0X01;
TIM1_CR1=0X81;�?�?