This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler: Can I do this in HAL_ISR_FUNCTION?

Tool/software: TI C/C++ Compiler

HAL_ISR_FUNCTION(zclSwitchControlPort0Isr, P0INT_VECTOR)
{
  HAL_ENTER_ISR();
 
  if (P0IFG & 0x02)  //P0_1   CTIN
  {

    P0IEN &= ~BV(1);
    if(P0_1 == 0)
    {
      P0IFG = 0;
      P0IF = 0;
      PICTL &= ~(0x1 << 0);
    }
    if(P0_1 == 1)
    {
      P0IFG = 0;
      P0IF = 0;
      PICTL |= (0x1 << 0);
    }
    osal_start_timerEx(zclSmartDoor_TaskID,
                       ZCL_DEVICE_SWITCH0_TOUCHPANEL_EVENT,
                       80);
  }
 
  P0IFG = 0;
  P0IF = 0;
 
  CLEAR_SLEEP_MODE();
  HAL_EXIT_ISR();
}

I enable interrput after event ZCL_DEVICE_SWITCH0_TOUCHPANEL_EVENT in 1.5s.

  • Yes , I also see it is OK.But there is problem in this way.

    In event ZCL_DEVICE_SWITCH0_TOUCHPANEL_EVENT I use

      if (events & ZCL_DEVICE_SWITCH0_TOUCHPANEL_EVENT) 
      {    
        
          if(P0_1 == 0)         //
          {
            //P0DIR |= BV(1);
            PICTL &= ~(0x1 << 0);
            if( zclSmartDoor_OnOff == SWITCH_ON )
            {
              LED_RED_ON();
              zclSmartDoor_OnOff = SWITCH_OFF;
              if ( zclDevice_NwkState == DEV_END_DEVICE ) {
                zclSwitchReportEvent(SAMRTDOOR_ENDPOINT, &zclSmartDoor_OnOff);
              }
            }
            osal_start_timerEx(zclSmartDoor_TaskID,
                               ZCL_DEVICE_LEN_RED_OFF_EVENT,
                               100);
          
        }
        

          if(P0_1 == 1)
          {
            PICTL |= (0x1 << 0);
            if( zclSmartDoor_OnOff == SWITCH_OFF )
            {
              LED_RED_ON();
              zclSmartDoor_OnOff = SWITCH_ON;
              if ( zclDevice_NwkState == DEV_END_DEVICE ) {
                zclSwitchReportEvent(SAMRTDOOR_ENDPOINT, &zclSmartDoor_OnOff);
              }
            }
            osal_start_timerEx(zclSmartDoor_TaskID,
                               ZCL_DEVICE_LEN_RED_OFF_EVENT,
                               100);
          }
        
        
        zcl_Flag = 0;
        osal_start_timerEx(zclSmartDoor_TaskID,
                           ZCL_DEVICE_SWITCH0_ABLE_EVENT,
                           1000);
        //    return (events ^ ZCL_DEVICE_SWITCH0_TOUCHPANEL_EVENT);
      }

    it sometime  report two times.

  • I suggest you to set breakpoint in your event to debug it.
  • I don't know if I am understanding well your problem. Does your PORT0 ISR is being triggered twice?

    If this is your problem, I believe it is related to PORT INTERRUPT mode. For ONE-SHOT mode you need to first clear the PIN flag and only after that you should clear the PORT flag.
    If you invert the sequence, you will get your ISR triggering a second time immediately after returning from the first ISR.

  • Yes I had clear PIN flag and PORT flag.I also change ISR trigger after frist ISR.And when I change trigger I clear PIN flag and PORT flag frist.

    After do events I set in HAL_ISR_FUNCTION I can't go to  HAL_ISR_FUNCTION again.It seems isn't set PIN flag,but I have set P0IEN in the end of events.

  • I suggest you to pause application in IAR and check registers to see what's wrong.