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.

interrupt P1.6 issue in zstack mesh

Other Parts Discussed in Thread: CC2530

Dear i have following code ,

first time it automatically generate interrupt , and second time when i press that button it generate interrupt .after that it stops generating any interrupt

* P1.6 */
#define HAL_KEY_FA_6_PORT P1
#define HAL_KEY_FA_6_BIT BV(6)
#define HAL_KEY_FA_6_SEL P1SEL
#define HAL_KEY_FA_6_DIR P1DIR

/* edge interrupt */
#define HAL_KEY_FA_6_EDGEBIT BV(2)
#define HAL_KEY_FA_6_EDGE HAL_KEY_RISING_EDGE

/* interrupts */
#define HAL_KEY_FA_6_IEN IEN2 /* CPU interrupt mask register */
#define HAL_KEY_FA_6_IENBIT BV(4) /* Mask bit for all of Port_1 */
#define HAL_KEY_FA_6_ICTL P1IEN /* Port Interrupt Control register */
#define HAL_KEY_FA_6_ICTLBIT BV(6) /* P1IEN - P1.6 enable/disable bit */
#define HAL_KEY_FA_6_PXIFG P1IFG /* Interrupt flag at source */

______________________________________________________________________________

PICTL &= ~(HAL_KEY_FA_6_EDGEBIT); /* Clear the edge bit */
/* For falling edge, the bit must be set. */
#if (HAL_KEY_FA_6_EDGE == HAL_KEY_FALLING_EDGE)
PICTL |= HAL_KEY_FA_6_EDGEBIT;
#endif

________________________________________________________________________________

HAL_KEY_FA_6_ICTL |= HAL_KEY_FA_6_ICTLBIT;
HAL_KEY_FA_6_IEN |= HAL_KEY_FA_6_IENBIT;
HAL_KEY_FA_6_PXIFG = ~(HAL_KEY_FA_6_BIT);

__________________________________________________________________________________

void halProcessKeyInterrupt (void)
{
bool valid=FALSE;


if (HAL_KEY_FA_6_PXIFG & HAL_KEY_FA_6_BIT) /* Interrupt Flag has been set */
{
HAL_KEY_FA_6_PXIFG = ~(HAL_KEY_FA_6_BIT); /* Clear Interrupt Flag */

Led = 1;

valid = TRUE;
}

if (valid)
{
osal_start_timerEx (Hal_TaskID, HAL_KEY_EVENT, HAL_KEY_DEBOUNCE_VALUE);


}
}

__________________________________________________________________________________

HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR )
{
HAL_ENTER_ISR();

if ((HAL_KEY_FA_6_PXIFG & HAL_KEY_FA_6_BIT))
{

halProcessKeyInterrupt();

}

/*
Clear the CPU interrupt flag for Port_1
PxIFG has to be cleared before PxIF
*/



HAL_KEY_FA_6_PXIFG = 0;
// HAL_KEY_SW_7_PXIFG = 0;
HAL_KEY_CPU_PORT_1_IF = 0;


CLEAR_SLEEP_MODE();
HAL_EXIT_ISR();
}

___________________________________________________________________________________

Thanks in advance 

  • Do you define ISR_KEYINTERRUPT in your project?

  • yes i have defined in preprocesser directive. Interrupts of P0.1 and P0.2 are working fine

    Thanks for concern
  • Does P1.6 still not work?
  • when i start the program it passes through

    HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR )
    {
    HAL_ENTER_ISR(); // pass from here

    if ((HAL_KEY_FA_6_PXIFG & HAL_KEY_FA_6_BIT)) // didnt pass from here ,HAL_KEY_FA_6_PXIFG==0xAF
    {

    halProcessKeyInterrupt();

    }

    /*
    Clear the CPU interrupt flag for Port_1
    PxIFG has to be cleared before PxIF
    */



    HAL_KEY_FA_6_PXIFG = 0;
    // HAL_KEY_SW_7_PXIFG = 0;
    HAL_KEY_CPU_PORT_1_IF = 0;


    CLEAR_SLEEP_MODE();
    HAL_EXIT_ISR();
    }
    _____________________________________________________________________________________

    second time when i press a button


    HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR )
    {
    HAL_ENTER_ISR(); // pass from here

    if ((HAL_KEY_FA_6_PXIFG & HAL_KEY_FA_6_BIT)) // pass from here ,HAL_KEY_FA_6_PXIFG==0x6F
    {

    halProcessKeyInterrupt();

    }

    /*
    Clear the CPU interrupt flag for Port_1
    PxIFG has to be cleared before PxIF
    */



    HAL_KEY_FA_6_PXIFG = 0;
    // HAL_KEY_SW_7_PXIFG = 0;
    HAL_KEY_CPU_PORT_1_IF = 0;


    CLEAR_SLEEP_MODE();
    HAL_EXIT_ISR();
    }
    ___________________________________________________________________________________

    third time it didn't enter into HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR ) function


    thanks for the help
  • Just have a test on P1.6 of my CC2530DK and it works fine. I attached my hal_key.c for you.

    /**************************************************************************************************
      Filename:       hal_key.c
      Revised:        $Date: 2010-09-15 19:02:45 -0700 (Wed, 15 Sep 2010) $
      Revision:       $Revision: 23815 $
    
      Description:    This file contains the interface to the HAL KEY Service.
    
    
      Copyright 2006-2010 Texas Instruments Incorporated. All rights reserved.
    
      IMPORTANT: Your use of this Software is limited to those specific rights
      granted under the terms of a software license agreement between the user
      who downloaded the software, his/her employer (which must be your employer)
      and Texas Instruments Incorporated (the "License").  You may not use this
      Software unless you agree to abide by the terms of the License. The License
      limits your use, and you acknowledge, that the Software may not be modified,
      copied or distributed unless embedded on a Texas Instruments microcontroller
      or used solely and exclusively in conjunction with a Texas Instruments radio
      frequency transceiver, which is integrated into your product.  Other than for
      the foregoing purpose, you may not use, reproduce, copy, prepare derivative
      works of, modify, distribute, perform, display or sell this Software and/or
      its documentation for any purpose.
    
      YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
      PROVIDED �AS IS� WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
      INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
      NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
      TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
      NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
      LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
      INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
      OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
      OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
      (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
    
      Should you have any questions regarding your right to use this Software,
      contact Texas Instruments Incorporated at www.TI.com.
    **************************************************************************************************/
    /*********************************************************************
     NOTE: If polling is used, the hal_driver task schedules the KeyRead()
           to occur every 100ms.  This should be long enough to naturally
           debounce the keys.  The KeyRead() function remembers the key
           state of the previous poll and will only return a non-zero
           value if the key state changes.
    
     NOTE: If interrupts are used, the KeyRead() function is scheduled
           25ms after the interrupt occurs by the ISR.  This delay is used
           for key debouncing.  The ISR disables any further Key interrupt
           until KeyRead() is executed.  KeyRead() will re-enable Key
           interrupts after executing.  Unlike polling, when interrupts
           are enabled, the previous key state is not remembered.  This
           means that KeyRead() will return the current state of the keys
           (not a change in state of the keys).
    
     NOTE: If interrupts are used, the KeyRead() fucntion is scheduled by
           the ISR.  Therefore, the joystick movements will only be detected
           during a pushbutton interrupt caused by S1 or the center joystick
           pushbutton.
    
     NOTE: When a switch like S1 is pushed, the S1 signal goes from a normally
           high state to a low state.  This transition is typically clean.  The
           duration of the low state is around 200ms.  When the signal returns
           to the high state, there is a high likelihood of signal bounce, which
           causes a unwanted interrupts.  Normally, we would set the interrupt
           edge to falling edge to generate an interrupt when S1 is pushed, but
           because of the signal bounce, it is better to set the edge to rising
           edge to generate an interrupt when S1 is released.  The debounce logic
           can then filter out the signal bounce.  The result is that we typically
           get only 1 interrupt per button push.  This mechanism is not totally
           foolproof because occasionally, signal bound occurs during the falling
           edge as well.  A similar mechanism is used to handle the joystick
           pushbutton on the DB.  For the EB, we do not have independent control
           of the interrupt edge for the S1 and center joystick pushbutton.  As
           a result, only one or the other pushbuttons work reasonably well with
           interrupts.  The default is the make the S1 switch on the EB work more
           reliably.
    
    *********************************************************************/
    
    /**************************************************************************************************
     *                                            INCLUDES
     **************************************************************************************************/
    #include "hal_mcu.h"
    #include "hal_defs.h"
    #include "hal_types.h"
    #include "hal_board.h"
    #include "hal_drivers.h"
    #include "hal_adc.h"
    #include "hal_key.h"
    #include "osal.h"
    
    #if (defined HAL_KEY) && (HAL_KEY == TRUE)
    
    /**************************************************************************************************
     *                                              MACROS
     **************************************************************************************************/
    
    /**************************************************************************************************
     *                                            CONSTANTS
     **************************************************************************************************/
    #define HAL_KEY_RISING_EDGE   0
    #define HAL_KEY_FALLING_EDGE  1
    
    #define HAL_KEY_DEBOUNCE_VALUE  25
    
    /* CPU port interrupt */
    #define HAL_KEY_CPU_PORT_0_IF P0IF
    #define HAL_KEY_CPU_PORT_1_IF P1IF
    #define HAL_KEY_CPU_PORT_2_IF P2IF
    
    /* SW_6 is at P0.1 */
    #define HAL_KEY_SW_6_PORT   P1
    #define HAL_KEY_SW_6_BIT    BV(6)
    #define HAL_KEY_SW_6_SEL    P1SEL
    #define HAL_KEY_SW_6_DIR    P1DIR
    
    /* edge interrupt */
    #define HAL_KEY_SW_6_EDGEBIT  BV(2)
    #define HAL_KEY_SW_6_EDGE     HAL_KEY_FALLING_EDGE
    
    
    /* SW_6 interrupts */
    #define HAL_KEY_SW_6_IEN      IEN2  /* CPU interrupt mask register */
    #define HAL_KEY_SW_6_IENBIT   BV(4) /* Mask bit for all of Port_0 */
    #define HAL_KEY_SW_6_ICTL     P1IEN /* Port Interrupt Control register */
    #define HAL_KEY_SW_6_ICTLBIT  BV(6) /* P0IEN - P0.1 enable/disable bit */
    #define HAL_KEY_SW_6_PXIFG    P1IFG /* Interrupt flag at source */
    
    /* Joy stick move at P2.0 */
    #define HAL_KEY_JOY_MOVE_PORT   P2
    #define HAL_KEY_JOY_MOVE_BIT    BV(0)
    #define HAL_KEY_JOY_MOVE_SEL    P2SEL
    #define HAL_KEY_JOY_MOVE_DIR    P2DIR
    
    /* edge interrupt */
    #define HAL_KEY_JOY_MOVE_EDGEBIT  BV(3)
    #define HAL_KEY_JOY_MOVE_EDGE     HAL_KEY_FALLING_EDGE
    
    /* Joy move interrupts */
    #define HAL_KEY_JOY_MOVE_IEN      IEN2  /* CPU interrupt mask register */
    #define HAL_KEY_JOY_MOVE_IENBIT   BV(1) /* Mask bit for all of Port_2 */
    #define HAL_KEY_JOY_MOVE_ICTL     P2IEN /* Port Interrupt Control register */
    #define HAL_KEY_JOY_MOVE_ICTLBIT  BV(0) /* P2IENL - P2.0<->P2.3 enable/disable bit */
    #define HAL_KEY_JOY_MOVE_PXIFG    P2IFG /* Interrupt flag at source */
    
    #define HAL_KEY_JOY_CHN   HAL_ADC_CHANNEL_6
    
    
    /**************************************************************************************************
     *                                            TYPEDEFS
     **************************************************************************************************/
    
    
    /**************************************************************************************************
     *                                        GLOBAL VARIABLES
     **************************************************************************************************/
    static uint8 halKeySavedKeys;     /* used to store previous key state in polling mode */
    static halKeyCBack_t pHalKeyProcessFunction;
    static uint8 HalKeyConfigured;
    bool Hal_KeyIntEnable;            /* interrupt enable/disable flag */
    
    /**************************************************************************************************
     *                                        FUNCTIONS - Local
     **************************************************************************************************/
    void halProcessKeyInterrupt(void);
    uint8 halGetJoyKeyInput(void);
    
    
    
    /**************************************************************************************************
     *                                        FUNCTIONS - API
     **************************************************************************************************/
    
    
    /**************************************************************************************************
     * @fn      HalKeyInit
     *
     * @brief   Initilize Key Service
     *
     * @param   none
     *
     * @return  None
     **************************************************************************************************/
    void HalKeyInit( void )
    {
      /* Initialize previous key to 0 */
      halKeySavedKeys = 0;
    
      HAL_KEY_SW_6_SEL &= ~(HAL_KEY_SW_6_BIT);    /* Set pin function to GPIO */
      HAL_KEY_SW_6_DIR &= ~(HAL_KEY_SW_6_BIT);    /* Set pin direction to Input */
    
      HAL_KEY_JOY_MOVE_SEL &= ~(HAL_KEY_JOY_MOVE_BIT); /* Set pin function to GPIO */
      HAL_KEY_JOY_MOVE_DIR &= ~(HAL_KEY_JOY_MOVE_BIT); /* Set pin direction to Input */
    
    
      /* Initialize callback function */
      pHalKeyProcessFunction  = NULL;
    
      /* Start with key is not configured */
      HalKeyConfigured = FALSE;
    }
    
    
    /**************************************************************************************************
     * @fn      HalKeyConfig
     *
     * @brief   Configure the Key serivce
     *
     * @param   interruptEnable - TRUE/FALSE, enable/disable interrupt
     *          cback - pointer to the CallBack function
     *
     * @return  None
     **************************************************************************************************/
    void HalKeyConfig (bool interruptEnable, halKeyCBack_t cback)
    {
      /* Enable/Disable Interrupt or */
      Hal_KeyIntEnable = interruptEnable;
    
      /* Register the callback fucntion */
      pHalKeyProcessFunction = cback;
    
      /* Determine if interrupt is enable or not */
      if (Hal_KeyIntEnable)
      {
        /* Rising/Falling edge configuratinn */
    
        PICTL &= ~(HAL_KEY_SW_6_EDGEBIT);    /* Clear the edge bit */
        /* For falling edge, the bit must be set. */
      #if (HAL_KEY_SW_6_EDGE == HAL_KEY_FALLING_EDGE)
        PICTL |= HAL_KEY_SW_6_EDGEBIT;
      #endif
    
    
        /* Interrupt configuration:
         * - Enable interrupt generation at the port
         * - Enable CPU interrupt
         * - Clear any pending interrupt
         */
        HAL_KEY_SW_6_ICTL |= HAL_KEY_SW_6_ICTLBIT;
        HAL_KEY_SW_6_IEN |= HAL_KEY_SW_6_IENBIT;
        HAL_KEY_SW_6_PXIFG = ~(HAL_KEY_SW_6_BIT);
    
    
    
        /* Rising/Falling edge configuratinn */
    
        HAL_KEY_JOY_MOVE_ICTL &= ~(HAL_KEY_JOY_MOVE_EDGEBIT);    /* Clear the edge bit */
        /* For falling edge, the bit must be set. */
      #if (HAL_KEY_JOY_MOVE_EDGE == HAL_KEY_FALLING_EDGE)
        HAL_KEY_JOY_MOVE_ICTL |= HAL_KEY_JOY_MOVE_EDGEBIT;
      #endif
    
    
        /* Interrupt configuration:
         * - Enable interrupt generation at the port
         * - Enable CPU interrupt
         * - Clear any pending interrupt
         */
        HAL_KEY_JOY_MOVE_ICTL |= HAL_KEY_JOY_MOVE_ICTLBIT;
        HAL_KEY_JOY_MOVE_IEN |= HAL_KEY_JOY_MOVE_IENBIT;
        HAL_KEY_JOY_MOVE_PXIFG = ~(HAL_KEY_JOY_MOVE_BIT);
    
    
        /* Do this only after the hal_key is configured - to work with sleep stuff */
        if (HalKeyConfigured == TRUE)
        {
          osal_stop_timerEx(Hal_TaskID, HAL_KEY_EVENT);  /* Cancel polling if active */
        }
      }
      else    /* Interrupts NOT enabled */
      {
        HAL_KEY_SW_6_ICTL &= ~(HAL_KEY_SW_6_ICTLBIT); /* don't generate interrupt */
        HAL_KEY_SW_6_IEN &= ~(HAL_KEY_SW_6_IENBIT);   /* Clear interrupt enable bit */
    
        osal_set_event(Hal_TaskID, HAL_KEY_EVENT);
      }
    
      /* Key now is configured */
      HalKeyConfigured = TRUE;
    }
    
    
    /**************************************************************************************************
     * @fn      HalKeyRead
     *
     * @brief   Read the current value of a key
     *
     * @param   None
     *
     * @return  keys - current keys status
     **************************************************************************************************/
    uint8 HalKeyRead ( void )
    {
      uint8 keys = 0;
    
      if (HAL_PUSH_BUTTON1())
      {
        keys |= HAL_KEY_SW_6;
      }
    
      if ((HAL_KEY_JOY_MOVE_PORT & HAL_KEY_JOY_MOVE_BIT))  /* Key is active low */
      {
        keys |= halGetJoyKeyInput();
      }
    
      return keys;
    }
    
    
    /**************************************************************************************************
     * @fn      HalKeyPoll
     *
     * @brief   Called by hal_driver to poll the keys
     *
     * @param   None
     *
     * @return  None
     **************************************************************************************************/
    void HalKeyPoll (void)
    {
      uint8 keys = 0;
    
      if ((HAL_KEY_JOY_MOVE_PORT & HAL_KEY_JOY_MOVE_BIT))  /* Key is active HIGH */
      {
        keys = halGetJoyKeyInput();
      }
    
      /* If interrupts are not enabled, previous key status and current key status
       * are compared to find out if a key has changed status.
       */
      if (!Hal_KeyIntEnable)
      {
        if (keys == halKeySavedKeys)
        {
          /* Exit - since no keys have changed */
          return;
        }
        /* Store the current keys for comparation next time */
        halKeySavedKeys = keys;
      }
      else
      {
        /* Key interrupt handled here */
      }
    
      if (HAL_PUSH_BUTTON1())
      {
        keys |= HAL_KEY_SW_6;
      }
    
      /* Invoke Callback if new keys were depressed */
      if (keys && (pHalKeyProcessFunction))
      {
        (pHalKeyProcessFunction) (keys, HAL_KEY_STATE_NORMAL);
      }
    }
    
    /**************************************************************************************************
     * @fn      halGetJoyKeyInput
     *
     * @brief   Map the ADC value to its corresponding key.
     *
     * @param   None
     *
     * @return  keys - current joy key status
     **************************************************************************************************/
    uint8 halGetJoyKeyInput(void)
    {
      /* The joystick control is encoded as an analog voltage.
       * Read the JOY_LEVEL analog value and map it to joy movement.
       */
      uint8 adc;
      uint8 ksave0 = 0;
      uint8 ksave1;
    
      /* Keep on reading the ADC until two consecutive key decisions are the same. */
      do
      {
        ksave1 = ksave0;    /* save previouse key reading */
    
        adc = HalAdcRead (HAL_KEY_JOY_CHN, HAL_ADC_RESOLUTION_8);
    
        if ((adc >= 2) && (adc <= 38))
        {
           ksave0 |= HAL_KEY_UP;
        }
        else if ((adc >= 74) && (adc <= 88))
        {
          ksave0 |= HAL_KEY_RIGHT;
        }
        else if ((adc >= 60) && (adc <= 73))
        {
          ksave0 |= HAL_KEY_LEFT;
        }
        else if ((adc >= 39) && (adc <= 59))
        {
          ksave0 |= HAL_KEY_DOWN;
        }
        else if ((adc >= 89) && (adc <= 100))
        {
          ksave0 |= HAL_KEY_CENTER;
        }
      } while (ksave0 != ksave1);
    
      return ksave0;
    }
    
    
    
    
    
    /**************************************************************************************************
     * @fn      halProcessKeyInterrupt
     *
     * @brief   Checks to see if it's a valid key interrupt, saves interrupt driven key states for
     *          processing by HalKeyRead(), and debounces keys by scheduling HalKeyRead() 25ms later.
     *
     * @param
     *
     * @return
     **************************************************************************************************/
    void halProcessKeyInterrupt (void)
    {
      bool valid=FALSE;
    
      if (HAL_KEY_SW_6_PXIFG & HAL_KEY_SW_6_BIT)  /* Interrupt Flag has been set */
      {
        HAL_KEY_SW_6_PXIFG = ~(HAL_KEY_SW_6_BIT); /* Clear Interrupt Flag */
        valid = TRUE;
      }
    
      if (HAL_KEY_JOY_MOVE_PXIFG & HAL_KEY_JOY_MOVE_BIT)  /* Interrupt Flag has been set */
      {
        HAL_KEY_JOY_MOVE_PXIFG = ~(HAL_KEY_JOY_MOVE_BIT); /* Clear Interrupt Flag */
        valid = TRUE;
      }
    
      if (valid)
      {
        osal_start_timerEx (Hal_TaskID, HAL_KEY_EVENT, HAL_KEY_DEBOUNCE_VALUE);
      }
    }
    
    /**************************************************************************************************
     * @fn      HalKeyEnterSleep
     *
     * @brief  - Get called to enter sleep mode
     *
     * @param
     *
     * @return
     **************************************************************************************************/
    void HalKeyEnterSleep ( void )
    {
    }
    
    /**************************************************************************************************
     * @fn      HalKeyExitSleep
     *
     * @brief   - Get called when sleep is over
     *
     * @param
     *
     * @return  - return saved keys
     **************************************************************************************************/
    uint8 HalKeyExitSleep ( void )
    {
      /* Wake up and read keys */
      return ( HalKeyRead () );
    }
    
    /***************************************************************************************************
     *                                    INTERRUPT SERVICE ROUTINE
     ***************************************************************************************************/
    
    /**************************************************************************************************
     * @fn      halKeyPort0Isr
     *
     * @brief   Port0 ISR
     *
     * @param
     *
     * @return
     **************************************************************************************************/
    HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR )
    {
      HAL_ENTER_ISR();
    
      if (HAL_KEY_SW_6_PXIFG & HAL_KEY_SW_6_BIT)
      {
        halProcessKeyInterrupt();
      }
    
      /*
        Clear the CPU interrupt flag for Port_0
        PxIFG has to be cleared before PxIF
      */
      HAL_KEY_SW_6_PXIFG = 0;
      HAL_KEY_CPU_PORT_1_IF = 0;
      
      CLEAR_SLEEP_MODE();
      HAL_EXIT_ISR();
    }
    
    
    /**************************************************************************************************
     * @fn      halKeyPort2Isr
     *
     * @brief   Port2 ISR
     *
     * @param
     *
     * @return
     **************************************************************************************************/
    HAL_ISR_FUNCTION( halKeyPort2Isr, P2INT_VECTOR )
    {
      HAL_ENTER_ISR();
      
      if (HAL_KEY_JOY_MOVE_PXIFG & HAL_KEY_JOY_MOVE_BIT)
      {
        halProcessKeyInterrupt();
      }
    
      /*
        Clear the CPU interrupt flag for Port_2
        PxIFG has to be cleared before PxIF
        Notes: P2_1 and P2_2 are debug lines.
      */
      HAL_KEY_JOY_MOVE_PXIFG = 0;
      HAL_KEY_CPU_PORT_2_IF = 0;
    
      CLEAR_SLEEP_MODE();
      HAL_EXIT_ISR();
    }
    
    #else
    
    
    void HalKeyInit(void){}
    void HalKeyConfig(bool interruptEnable, halKeyCBack_t cback){}
    uint8 HalKeyRead(void){ return 0;}
    void HalKeyPoll(void){}
    
    #endif /* HAL_KEY */
    
    
    
    
    
    /**************************************************************************************************
    **************************************************************************************************/
    
    
    
    

  • thanks a lot for that , i will test in few hours then i will update you.

    Again thanks
  • You are welcome.
  • Dear
    same response from your code as well
    it generate interrupt only once

    waiting for your response
  • Dear

    i am using ADX345 , it generate an interrupt on single tap /double tap . INT0 pin is connected to P1.6 pin of cc2530 and interrupt is generated on RISING edge.

    I use the previous code which was working in an old firmware now i am using it in zstack mesh . First time it generate an interrupt but second time it didnt, same response from your code as well
  • I test my code on SampleLight and it works fine. The problem might be caused by your application or modification. I suggest you to verify my hal_key.c on SampleLight first and try to find why it doesn't work on your application.
  • right , let me check and update you , thanks
  • You are welcome.
  • Dear
    can you tell me how to check interrupt with P1_6 pin ? because for P1_6 i am using ADXL345 pin directly connected with that . there is no button / or i cannot give signal separately i can only give by adxl345 interrupt pin
  • You can use scope to check it.
  • interrupt pin is working fine , i have given 3 v on this pin and it generate interrupt again , thanks for that
    Can u tell me that ,ADXL345 first time it make pin high on single tap but second time it doesn't . its adxl345 issue
  • I think you don't clear interrupt pin on ADXL345 and you should do it.
  • its working in another firmware , adxl345 on single tap first time generates an interrupt make pin high then low , but second time it didn't .that means it also make pin low by itself
  • As I know, you have to read data to clear interrupt pin, do you?
  • yes , i am doing in interrupt service routine i am again reading data , but still the same.
    i declared the functions non static , but in z stack functions are static .is it be an issue ? that first time it read and second time not ?
  • I don't see static function would cause this.
  • then any other expert opinion ? should i share the code ?
  • I can't help much even you show me your code since I don't have your HW.
  • You are welcome.
  • By the way, make sure you read all of data on adxl345 to clear all interrupt sources otherwise interrupt pin won't toggle.
  • thanks,

    i did that but no change :(
  • Can you show me how you do it?
  • Dear here is the code , protocol is i2c , i am just showing the function calls
    First time it generate interrupts but second time not

    ________________________________________________________________________________________________

    HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR )
    {
    HAL_ENTER_ISR();

    if ((HAL_KEY_FA_6_PXIFG & HAL_KEY_FA_6_BIT))
    {

    halProcessKeyInterrupt();

    }



    HAL_KEY_FA_6_PXIFG = 0;
    HAL_KEY_CPU_PORT_1_IF = 0;

    Init_ADXL345();
    CLEAR_SLEEP_MODE();
    HAL_EXIT_ISR();
    }
    __________________________________________________________________________________________________________

    void Init_ADXL345()
    {


    Single_Write_ADXL345(DATA_FORMAT, 0x01);
    Single_Write_ADXL345(INT_MAP, 0x60); //Send the Tap and Double Tap Interrupts to INT2 pin
    Single_Write_ADXL345(TAP_AXES, 0x01); //Look for taps on the Z axis(01) only.
    Single_Write_ADXL345(THRESH_TAP, 0x38); //Set the Tap Threshold to 3g
    Single_Write_ADXL345(DURATION, 0xFF); //Set the Tap Duration that must be reached
    //100ms Latency before the second tap can occur.
    Single_Write_ADXL345(LATENT, 0x50);
    Single_Write_ADXL345(WINDOW, 0xFF);


    Single_Write_ADXL345(INT_ENABLE, 0xE0); //Enable the Single and Double Taps.
    Single_Write_ADXL345(POWER_CTL, 0x08); //Measurement mode

    Single_Write_ADXL345(LATENT, 0x50);
    Single_Write_ADXL345(WINDOW, 0xFF);

    Multiple_Read_ADXL345(0x30,1);

    Multiple_Read_ADXL345(0x32,6);


    }
  • Are you sure your I2C driver for ADXL345 works fine? Do you use scope or I2c analyzer to check it?

  • unfortunately don't have scope
    But i have few observations that , when i change the address in registers like for example

    Single_Write_ADXL345(INT_MAP, 0x60); //Send the Tap and Double Tap Interrupts to INT2 pin
    i change it to
    Single_Write_ADXL345(INT_MAP, 0x10);

    then it will not generate interrupt , means protocol working up to some extent fine


    Second observation,

    i am using same code in "USB HID example code swrc088c" our there it is working fine

    The question is why first time it generate correct interrupt and second time didn't
  • I can only suggest you to find a scope and do debugging.

  • You are welcome and sorry for not really helpful to you.
  • no its ok , i am getting so much help from your experience . you are replying my post this thing is very much helpful for me
  • Anyway, I hope your problem would be solved after you dig more deep into it.
  • Dear i have connected interrupt pin with scope , you were right that interrupt pin doesn't goes low

    at start up it stays low, when single tap event occur it goes high after that, i read the register values of adxl345 , but it didn't make interrupt pin low , interrupt pin remains high after the first interrupt occured.

    After then i connected the scope on SDA,SCL pins as well , when first interrupt occured at that time scope was showing the data , but after the interrupt it didnt show any data although i was reading again.

    These were my observations , need your expert opinion

    thanks in advance
  • You should use scope to check if your driver send correct I2C command on SCL and SDA.