AnsweredAssumed Answered

why I can't get the lwgpio isr work??

Question asked by botao yang on Dec 28, 2015
Latest reply on Jan 19, 2016 by soledad

In fact, I need to set 4 pins to work in the interrupt, and these 4 pins are PTB16、PTB17、PTB18、PTB19,below are the init part and the isr function.

the problem is these 4 interrupts works well at first, but after the _lwevent_set(&lwevent,Event_SaveTEMP) is implemented and the the event is using MFS to save data in the SD card(this part works well too), then if I press the BUTTON4, the interrupt function will stay at lwgpio_int_get_flag((LWGPIO_STRUCT_PTR)&btn4(this is found by set the breakpoint).

if I do't use the MFS the interrupt function has no problem.

what is the problem of my program??

 

void init_button(void){

    /*******Open the pin (BSP_BUTTON) for input, initialize .**************/

    lwgpio_init(&btn1, BSP_BUTTON1, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE);

    lwgpio_init(&btn2, BSP_BUTTON2, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE);

    lwgpio_init(&btn3, BSP_BUTTON3, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE);

    lwgpio_init(&btn4, BSP_BUTTON4, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE);

   

    /* Some platforms require to setup MUX to IRQ functionality,for the rest just set MUXto GPIO functionality */

    lwgpio_set_functionality(&btn1, BSP_BUTTON1_MUX_GPIO);

    lwgpio_set_functionality(&btn2, BSP_BUTTON2_MUX_GPIO);

    lwgpio_set_functionality(&btn3, BSP_BUTTON3_MUX_GPIO);

    lwgpio_set_functionality(&btn4, BSP_BUTTON4_MUX_GPIO);

   

    lwgpio_set_attribute(&btn1, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE);

    lwgpio_set_attribute(&btn2, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE);

    lwgpio_set_attribute(&btn3, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE);

    lwgpio_set_attribute(&btn4, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE);

   

    /* enable gpio functionality for given pin, react on falling edge */

    lwgpio_int_init(&btn1, LWGPIO_INT_MODE_FALLING);

    lwgpio_int_init(&btn2, LWGPIO_INT_MODE_FALLING);

    lwgpio_int_init(&btn3, LWGPIO_INT_MODE_FALLING);

    lwgpio_int_init(&btn4, LWGPIO_INT_MODE_FALLING);

   

    /* install gpio interrupt service routine */

    _int_install_isr(lwgpio_int_get_vector(&btn1), btn_isr, (void *) &btn1);

    /* set the interrupt level, and unmask the interrupt in interrupt controller*/

    _bsp_int_init(lwgpio_int_get_vector(&btn1), 3, 0, TRUE);

    /* enable interrupt on GPIO peripheral module*/

    lwgpio_int_enable(&btn1, TRUE);

   

    /* install gpio interrupt service routine */

    _int_install_isr(lwgpio_int_get_vector(&btn2), btn_isr, (void *) &btn2);

    /* set the interrupt level, and unmask the interrupt in interrupt controller*/

    _bsp_int_init(lwgpio_int_get_vector(&btn2), 3, 0, TRUE);

    /* enable interrupt on GPIO peripheral module*/

    lwgpio_int_enable(&btn2, TRUE);

   

    /* install gpio interrupt service routine */

    _int_install_isr(lwgpio_int_get_vector(&btn3), btn_isr, (void *) &btn3);

    /* set the interrupt level, and unmask the interrupt in interrupt controller*/

    _bsp_int_init(lwgpio_int_get_vector(&btn3), 3, 0, TRUE);

    /* enable interrupt on GPIO peripheral module*/

    lwgpio_int_enable(&btn3, TRUE);

   

    /* install gpio interrupt service routine */

    _int_install_isr(lwgpio_int_get_vector(&btn4), btn_isr, (void *) &btn4);

    /* set the interrupt level, and unmask the interrupt in interrupt controller*/

    _bsp_int_init(lwgpio_int_get_vector(&btn4), 3, 0, TRUE);

    /* enable interrupt on GPIO peripheral module*/

    lwgpio_int_enable(&btn4, TRUE);

}

 

 

void btn_isr(void *pin)

{

    if(lwgpio_int_get_flag((LWGPIO_STRUCT_PTR)&btn1))

    {

        lwgpio_int_clear_flag((LWGPIO_STRUCT_PTR) &btn1);

        switch(Screenstate)

        {

        case 0:

        {

             YMJH[5]=0x01;

            break;

        }

        case 2:

        {

             YMJH[5]=0x02;

             _lwevent_set(&lwevent,Event_TempACQ);

            break;

        }

        case 3:

        {

             YMJH[5]=0x02;

             _lwevent_set(&lwevent,Event_TempACQ);

            break;

        }

        default:

            break;;   

        }

        _lwevent_set(&lwevent,Event_SendYMJH);

    }

    else if(lwgpio_int_get_flag((LWGPIO_STRUCT_PTR)&btn2))

    {

        lwgpio_int_clear_flag((LWGPIO_STRUCT_PTR) &btn2);

        switch(Screenstate)

        {

        case 0:

        {

             YMJH[5]=0x01;

            break;

        }

        case 3:

        {

            //YMJH[5]=0x06;

            _lwevent_set(&lwevent,Event_SaveTEMP);

            break;

        }

        case 4:

        {

             YMJH[5]=0x04;

            break;

        }

       

        default:

            break;;   

        }

        _lwevent_set(&lwevent,Event_SendYMJH);

       

    }

    else if(lwgpio_int_get_flag((LWGPIO_STRUCT_PTR)&btn3))

    {

        lwgpio_int_clear_flag((LWGPIO_STRUCT_PTR) &btn3);

        switch(Screenstate)

        {

        case 0:

        {

             YMJH[5]=0x01;

            break;

        }

        case 2:

        {

             YMJH[5]=0x03;

            break;

        }

        case 3:

        {

             YMJH[5]=0x05;

            break;

        }

        default:

            break;;   

        }

        _lwevent_set(&lwevent,Event_SendYMJH);   

    }

    else if(lwgpio_int_get_flag((LWGPIO_STRUCT_PTR)&btn4))

    {

        lwgpio_int_clear_flag((LWGPIO_STRUCT_PTR) &btn4);

        switch(Screenstate)

        {

        case 0:

        {

             YMJH[5]=0x00;

            break;

        }

        case 3:

        {

             YMJH[5]=0x05;

            break;

        }

        default:

            break;;   

        }

        _lwevent_set(&lwevent,Event_SendYMJH);

    }          

}

Outcomes