2018-06-17 02:15 AM
Hi,
I am trying to implement timer based on interrupt in STM8S003F3 using STVD and COSMIC C Compiler free version.
I tried following this tutorial available on web
http://embedded-lab.com/blog/starting-stm8-microcontrollers/19/
. However, while modifying the stm8_interrupt_vector.c file for adding my TIM2_IRQHandler in the interrupt vector struct under irq no. 13, I am getting this error: 'invalid pointer initializer'. What am I doing wrong here?My stm8_interrupt_vector.c looks like this:
typedef void @far (*interrupt_handler_t)(void);
struct interrupt_vector {
unsigned char interrupt_instruction; interrupt_handler_t interrupt_handler;};@far @interrupt_handler_t void NonHandledInterrupt (void)
{ /* in order to detect unexpected events during development, it is recommended to set a breakpoint on the following instruction */ return;}extern void _stext(); /* startup routine */
struct interrupt_vector const _vectab[] = { {0x82, (interrupt_handler_t)_stext}, /* reset */ {0x82, NonHandledInterrupt}, /* trap */ {0x82, NonHandledInterrupt}, /* irq0 */ {0x82, NonHandledInterrupt}, /* irq1 */ {0x82, NonHandledInterrupt}, /* irq2 */ {0x82, NonHandledInterrupt}, /* irq3 */ {0x82, NonHandledInterrupt}, /* irq4 */ {0x82, NonHandledInterrupt}, /* irq5 */ {0x82, NonHandledInterrupt}, /* irq6 */ {0x82, NonHandledInterrupt}, /* irq7 */ {0x82, NonHandledInterrupt}, /* irq8 */ {0x82, NonHandledInterrupt}, /* irq9 */ {0x82, NonHandledInterrupt}, /* irq10 */ {0x82, NonHandledInterrupt}, /* irq11 */ {0x82, NonHandledInterrupt}, /* irq12 */ //{0x82, NonHandledInterrupt}, /* irq13 */ {0x82, (interrupt_handler_t)TIM2_UPD_IRQHandler}, /* irq13 */ {0x82, NonHandledInterrupt}, /* irq14 */ {0x82, NonHandledInterrupt}, /* irq15 */ {0x82, NonHandledInterrupt}, /* irq16 */ {0x82, NonHandledInterrupt}, /* irq17 */ {0x82, NonHandledInterrupt}, /* irq18 */ {0x82, NonHandledInterrupt}, /* irq19 */ {0x82, NonHandledInterrupt}, /* irq20 */ {0x82, NonHandledInterrupt}, /* irq21 */ {0x82, NonHandledInterrupt}, /* irq22 */ {0x82, NonHandledInterrupt}, /* irq23 */ {0x82, NonHandledInterrupt}, /* irq24 */ {0x82, NonHandledInterrupt}, /* irq25 */ {0x82, NonHandledInterrupt}, /* irq26 */ {0x82, NonHandledInterrupt}, /* irq27 */ {0x82, NonHandledInterrupt}, /* irq28 */ {0x82, NonHandledInterrupt}, /* irq29 */};and added this to stm8_itc.h
/* Define to prevent recursive inclusion -------------------------------------*/
&sharpifndef __STM8S_ITC_H&sharpdefine __STM8S_ITC_H@far @interrupt void TIM2_UPD_IRQHandler(void);/* Includes ------------------------------------------------------------------*/&sharpinclude 'stm8s.h'and this is my TIM2_UPD_IRQHandler(void) ISR inside stm8_itc.c:
extern char cFlag; // char cFlag is declared in main.c and used in the interrupt as a flag to be used in while(1)
void TIM2_UPD_IRQHandler(void)
{ TIM4_ClearITPendingBit(TIM2_IT_UPDATE); TIM4_ClearFlag(TIM2_FLAG_UPDATE); cFlag = 1;}What am I doing wrong here? Any suggestions would be of really great help. Thanks!
#stm8s003f3p #stm8s-spl #stm82018-06-17 04:22 AM
Or are there any better ways to use interrupt functions in a program?
2018-06-17 11:30 PM
Any help on this regard? or is this too trivial an issue?
2018-06-18 03:20 AM
1. does the compiler give you a line number for the error?
2. is the ISR properly declared -> as extern or in a header file?
2018-06-18 04:49 AM
Here are my known to be working snipplets:
extern @far @interrupt void NonHandledInterrupt(void);
extern @far @interrupt void RX_IOC(void);extern @far @interrupt void Seed_IOC(void);extern @far @interrupt void Seed_2_3_IOC(void);extern @far @interrupt void OneMsTimerOVF(void);extern @far @interrupt void RX_ISR(void);extern @far @interrupt void TX_ISR(void);extern @far @interrupt void MicroSecTickTimerOVF(void);.....
struct interrupt_vector const _vectab[] = {
{0x82, (interrupt_handler_t)_stext}, /* reset */ {0x82, NonHandledInterrupt}, /* TRAP */ {0x82, NonHandledInterrupt}, /* TLI */ {0x82, NonHandledInterrupt}, /* AWU */ {0x82, NonHandledInterrupt}, /* CLK */ {0x82, Seed_2_3_IOC}, /* EXTI PORTA for seed signal 2-3 */@far @interrupt void NonHandledInterrupt(void);
@far @interrupt void RX_IOC(void);
@far @interrupt void Seed_IOC(void);@far @interrupt void Seed_2_3_IOC(void);@far @interrupt void Seed_2_3_IOC(void){ uint8_t tmp = SEED_SIGNAL_2_port;As far as I can see:
- No typecasting in the ISR vector table
- extern function declarations in the interrupt table file
- @far @interrupt specifiers a the ISR function implementations
2018-06-19 01:08 AM
Hello,
did you solve this? Most likely you missed the extern..
Regards,
Luca (Cosmic)