I make interrupt for Pin PE0, but when I press key and keep it low, the interrupt alway happens.
Here is my code:
Code: Select all
/*main.c*/
static msg_t Thread1(void *arg) {
(void)arg;
chRegSetThreadName("blinker");
while (TRUE) {
palSetPad(GPIOA, 5);
chThdSleepMilliseconds(500);
palClearPad(GPIOA, 5);
chThdSleepMilliseconds(500);
R_LED = 1;
B_LED = 1;
}
return 0;
}
static msg_t Thread2(void *arg) {
(void)arg;
chRegSetThreadName("uart");
while (TRUE) {
palSetPad(GPIOA, 4);
//palSetPad(GPIOA, 5);
chThdSleepMilliseconds(250);
palClearPad(GPIOA, 4);
// palClearPad(GPIOA, 5);
chThdSleepMilliseconds(250);
R_LED = 1;
}
return 0;
}
/*
* Application entry point.
*/
void main(void) {
/*
* System initializations.
* - HAL initialization, this also initializes the configured device drivers
* and performs the board-specific initializations.
* - Kernel initialization, the main() function becomes a thread and the
* RTOS is active.
*/
halInit();
chSysInit();
/*
* Activates the serial driver 1 using the driver default configuration.
* The STM8L-Discovery requires USART1 pins remapping on PA2 and PA3.
*/
// SYSCFG->RMPCR1 = 0x1C;/*remap*/
// EXTI->CR1 &= (uint8_t)(~EXTI_CR1_P0IS);
// EXTI->CR1 |= (uint8_t)((uint8_t)(0x02) << 0x00);
sdStart(&SD1, NULL);
/*
* Creates the blinker thread.
*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
//chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO, Thread2, NULL);
/*
* Normal main() thread activity.
*/
while (TRUE) {
if (palReadPad(GPIOC, PC_BUTTON) == PAL_LOW)
//TestThread(&SD1);
if(R_LED == 1){
sdWrite(&SD1, "R_LED ON\r\n", 10);
R_LED = 0;
}
if(B_LED == 1){
sdWrite(&SD1, "R_LED OFF\r\n", 11);
B_LED = 0;
}
//chThdSleepMilliseconds(1000);
}
}
/*shared_isr.c*/
delayms(u16 ms)
{
u16 i = 0;
for(i = 0; i<ms;i++)
nop();
}
CH_IRQ_HANDLER(8) {
CH_IRQ_PROLOGUE();
chSysLockFromIsr();
/* Invocation of some I-Class system APIs, never preemptable.*/
EXTI->SR1 = 0x0001;/*clear interrupt*/
delayms(300);
if (palReadPad(GPIOE, 0) == PAL_LOW)
{
palTogglePad(GPIOA, 4);
}
chSysUnlockFromIsr();
CH_IRQ_EPILOGUE();
}Please help me.
Thanks