With STM8 sduino, attachInterrupt works but not like on a normal arduino.
Interrupts are separate per PORT, not per pin. Each port has multiple pins. PA1, PA2 are on port A, PC3-PC7 are on port C etc.
Use pinMode to designate the pin as input, so that digitalRead can keep working in case you need it.
After that, you must call GPIO_Init (an STM8-specific API function) to actually enable interrupts for a particular pin.
Then, you disable interrupts and call EXTI_SetExtIntSensitivity to set the interrupt trigger type on that entire port.
Finally attachInterrupt(). See my example below, this code works for me on my STM8S003F3.
Hope this saves someone some time.
Code: Select all
void ISR()
{
//your code here
}
void setup()
{
pinMode(2,INPUT);
GPIO_Init(GPIOA, GPIO_PIN_3, GPIO_MODE_IN_FL_IT);
disableInterrupts();
EXTI_SetExtIntSensitivity( EXTI_PORT_GPIOA, EXTI_SENSITIVITY_RISE_ONLY);
enableInterrupts();
attachInterrupt(INT_PORTA & 0xFF,ISR,0);
}