AnsweredAssumed Answered

stm8l151c8 Interrupt is not working

Question asked by Mohamed Osama on Jul 29, 2017
Latest reply on Jul 30, 2017 by Mohamed Osama

Hi,

 

 

I'm using stm8l151c8 controller, I'm trying to get an interrupt from PB0 but it's not working, here is my code:

 

#include "stm8l15x_conf.h"

#include "main.h"

 

uint8_t __IO BlinkSpeed = 0;
static __IO uint32_t TimingDelay;

void Delay(__IO uint32_t nCount)
{
while(nCount--)
{
}
}

void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}

uint8_t data_audio,data_transmit;

uint8_t get_bit(uint8_t bits, uint8_t pos)
{
return (bits >> pos) & 0x01;
}

#pragma vector=0x008028

@svlreg @interrupt void EXTI0_IRQHandler()
{
uint8_t i=0;
if (EXTI_GetITStatus(EXTI_IT_Pin0) != RESET) {
Delay(3);
for(i=0;i<8;i++)
{
data_audio=data_audio<<0x01;
data_audio=data_audio|GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_0);
Delay(5);
}
for(i=0;i<8;i++)
{
data_transmit=get_bit(data_audio,7-i);
if(data_transmit==0x00)
GPIO_WriteBit(GPIOD,GPIO_Pin_2,0x00);
else
GPIO_WriteBit(GPIOD,GPIO_Pin_2,0x01);
Delay(10);
}
// Clear interrupt flag
EXTI_ClearITPendingBit(EXTI_IT_Pin0);
}
}


void GPIO_cnfg()
{
GPIO_Init(GPIOD,GPIO_Pin_2,GPIO_Mode_Out_PP_Low_Fast);
GPIO_Init(GPIOB,GPIO_Pin_0,GPIO_Mode_In_FL_IT);
EXTI_SelectPort(EXTI_Port_B);
EXTI_SetHalfPortSelection(EXTI_HalfPort_B_LSB, ENABLE);
EXTI_SetPortSensitivity( EXTI_Port_B, EXTI_Trigger_Rising);
EXTI_SetPinSensitivity(EXTI_IT_Pin0, EXTI_Trigger_Rising);
enableInterrupts();
}


static void CLK_Config(void)
{
/* Select HSE as system clock source */
CLK_SYSCLKSourceSwitchCmd(ENABLE);
CLK_HSICmd(ENABLE);
CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);
/* system clock prescaler: 1*/
CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);
while (CLK_GetSYSCLKSource() != CLK_SYSCLKSource_HSI)
{}

}


int main (void) {

CLK_Config();

GPIO_cnfg();

while(1) { 
               }
}

#ifdef USE_FULL_ASSERT


void assert_failed(uint8_t* file, uint32_t line)
{

 

while (1)
{
}
}
#endif

and here is stm8_interrupt_vector.c

#include "main.h"

 

typedef void @far (*interrupt_handler_t)(void);

struct interrupt_vector {
unsigned char interrupt_instruction;
interrupt_handler_t interrupt_handler;
};

@far @interrupt void NonHandledInterrupt (void)
{
return;
}

 

extern void _stext(); /* startup routine */
extern void EXTI0_IRQHandler();

struct interrupt_vector const _vectab[] = {
{0x82, (interrupt_handler_t)_stext}, /* reset */
{0x82, NonHandledInterrupt}, /* trap */
{0x82, (interrupt_handler_t)EXTI0_IRQHandler}, /* 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, 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 */
};

main.h file includes only the prototype of the interrupt function:

@svlreg @interrupt void EXTI0_IRQHandler();

every time it calls nonhandled interrupt function, but the address I'm putting in pragma vector line is correct, it's weird, I guess there is something missing.

 

Thank you for your help.

Outcomes