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.

Question about CC2510 Mini DK Code Example (GPIO interrupts with rising edge triggering vs. falling edge triggering)

Other Parts Discussed in Thread: CC2510, CC2520

I have a CC2510 Mini Development Kit with the CC Debugger. I am running the CC1110 and CC2510 Mini DK Software Example (swrc133) which is the "smpl_link_srfccxx10".

In this example, there is a function called "uint8_t BSP_SleepUntilButton(uint8_t mode, uint8_t button)" which is defined in the "bsp_extended.c" file. For the CC2510 Mini DK, this function defines it as the "BSP_BOARD_SRFCCXX10". The definition of this function is shown below.

/**************************************************************************************************
* @fn          BSP_SleepUntilButton
*
* @brief       Enter sleep mode, Set up DMA workaround according to errata note for CC251x & CC111x
*              Will wake up on Button pushes
*
* @param       mode   : Power mode, can be 0-3
*              button : Button to wake up on, can be 1 (master), 2 (slave) or 3 (both)
*
* @return      none
**************************************************************************************************
*/
uint8_t BSP_SleepUntilButton(uint8_t mode, uint8_t button)
{
 
  //  Set radio to sleep
  SMPL_Ioctl(IOCTL_OBJ_RADIO,IOCTL_ACT_RADIO_SLEEP,0); 
  IEN2 &= ~0x01;                          // Disable RF interrupt
  BSP_ENABLE_INTERRUPTS();
 
  BSP_SET_MAIN_CLOCK_RC();                // Set main clock source to RC oscillator
 
#ifdef BSP_BOARD_SRFCCXX10
    //Using SRFCCxx10 board
 
    /* Clear Port 1 Interrupt flags */
    P1IFG = 0x00;
    P1IF = 0;
 
    P1IEN &= ~0x0C;
    P1IEN |= (button<<2);                   // Enable Port interrupts
 
    /* Enable CPU Interrupt for Port 1 (IEN2.P1IE = 1) */
    IEN2 |= 0x10;
#endif
   
#ifdef BSP_BOARD_SRF04EB
     //Using SFR04 board
   
    /* Clear Port 0 Interrupt flags */
    P0IFG = 0x00;
    P0IF = 0;
       
    PICTL &= ~0x18;
    PICTL |= (button<<3);                   // Enable Port interrupts
   
    /* Enable CPU Interrupt for Port 0 (IEN1.P0IE = 1) */
    IEN1 |= 0x20;
#endif
 
  BSP_ENABLE_INTERRUPTS();
 
  bsp_PowerMode(mode);
 
  BSP_SET_MAIN_CLOCK_XOSC();              // Set main clock source to External oscillator
 
  // Wake up the radio and set it in Idle
  SMPL_Ioctl(IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE,0);
  IEN2 |= 0x01;                           // Enable RF interrupt
 
  return sButtonPushed;
}

From the function definition, it looks that the CC2520 Mini DK uses rising edge of Port 1 pins to trigger the interrupt and wakeup the radio since the default setting of the PICTL.P1ICON is 0. For my own application, I need to change this to use falling edge to trig the interrupt. Thus, I add an additional line to the original code as shown below sandwiched between two /*??????????*/ lines.

#ifdef BSP_BOARD_SRFCCXX10
    //Using SRFCCxx10 board
 
    /* Clear Port 1 Interrupt flags */
    P1IFG = 0x00;
    P1IF = 0;
   
    /*???????????????????????????????????????????????????????????????????????*/
    PICTL |= 0x02;                          // Falling edge triggers interrupts
    /*???????????????????????????????????????????????????????????????????????*/
 
    P1IEN &= ~0x0C;
    P1IEN |= (button<<2);                   // Enable Port interrupts
 
    /* Enable CPU Interrupt for Port 1 (IEN2.P1IE = 1) */
    IEN2 |= 0x10;
#endif

After recompiling the code, I found that the BSP_SleepUntilButton seems not working anymore. Can you please help to debug this problem and show me how to change the rising edge to the falling edge?

 

 

  • Here's what appears to be happening.

    When PICFG = 0x02 is executed, then P1IFG immediately becomes 0x03.  Later, when a button interrupt occurs on S1, then P1IFG=0x07.  The logic in BSP_ButtonIsr checks for P1IFG=0x04 or P1IFG=0x08;  neither of these is true, so sButtonPushed returns as zero.  So, the unit doesn't know whether it's a mster or slave, and goes into a while(1) loop.

    One solution is to rearrange some of the lines in BSP_SleepUntilButton to reset P1IFG after setting PICFG.  That is from:

    /* Clear Port 1 Interrupt flags */
        P1IFG = 0x00;
        P1IF = 0;  
     
        //Customer-added line
        PICTL |= 0x02;
        //End customer-added line

    to:

     
        //Customer-added line
        PICTL |= 0x02;
        //End customer-added line
       
        //And move the two previous lines after this
       
        /* Clear Port 1 Interrupt flags */
        P1IFG = 0x00;
        P1IF = 0;   

    I hope that gets you going.