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.

CC2530: which example project to use for battery powered system?

Part Number: CC2530
Other Parts Discussed in Thread: Z-STACK

hi

I'm using cc2530 zstack 3.0.0 

two q.

1.which example project to use for battery powered system?

2.how can I disable hall key and use my interupt routine , so it go to power mode 2 ?

please if you have example that already go to pm2 send it to me

  • 1. For each Z-Stack example, you can choose end device configuration and define POWER_SAVING to make PM2 works.
    2. You have to define ISR_KEYINTERRUPT to enable key interrupt.
  • you know my issue
    it still draw 120 uA and it's not going into pm2
  • I am pretty sure your application goes into PM2 but there’s some event keeps wake up your device to cause this 120uA current consumption. You point out a possibility is key interrupt. Z-Stack doesn’t enable key interrupt by default and it might be the cause so I suggest you to enable key interrupt to test again.
  • I did use my interrupt routine and it work fine
    but still draw current allot
    do u have any simple project that can reach pm2 ? thanks allot . I think it's the only way that left . it's so much time that I'm trying but not working right
  • Do you try to define ISR_KEYINTERRUPT in your project and test again?
  • yes I did that but still no luck
    I did some changes to sample light maybe that's why
    1.delete all ui stuff
    2.write my interrupt routine on one of pin(maybe I should use hal key what you think?)

    that's it
  • I don't think both of those two items would cause this issue. Can you set a breakpoint in the following HAL_KEY_EVENT inside Hal_ProcessEvent() to see if the breakpoint is kept hitting every 100 ms?

    if (events & HAL_KEY_EVENT)
    {
    #if (defined HAL_KEY) && (HAL_KEY == TRUE)
    /* Check for keys */
    HalKeyPoll();

    /* if interrupt disabled, do next polling */
    if (!Hal_KeyIntEnable)
    {
    osal_start_timerEx( Hal_TaskID, HAL_KEY_EVENT, 100);
    }
    #endif
    return events ^ HAL_KEY_EVENT;
    }
  • ok I'll do that but I didn't use hall key at all . I wrote my interrupt routine.maybe I don't get hall key what it is
  • If you don't define ISR_KEYINTERRUPT, Z-Stack would call "HalKeyConfig(HAL_KEY_INTERRUPT_DISABLE, OnBoard_KeyCallback);" in InitBoard() and "HalKeyConfig(HAL_KEY_INTERRUPT_DISABLE, OnBoard_KeyCallback);" would trigger HAL_KEY_EVENT to make it invoke every 100 ms. So, I suppose you don't define ISR_KEYINTERRUPT and it causes this issue.
  • I'll double check that
    thanks allot
    I'll inform
  • now it works but when an interrupt occur it get out of pm2 and its not going back to pm2

    this is my interrupt routine

    HAL_ISR_FUNCTION(halKeyPort0Isr , P0INT_VECTOR ){
    
      HAL_ENTER_ISR();
      uint8 sendbuffer[8];
      sendbuffer[0] = LocalDeviceID[0];
      sendbuffer[1] = LocalDeviceID[1];
      sendbuffer[2] = LocalDeviceID[2];
      
      sendbuffer[4] = '0';
      sendbuffer[5] = '0';
      sendbuffer[6] = '0';
      sendbuffer[7] = '\n';
      
      if(((P0& (1<<7)) == (1<<7)) && IsDoorOpen == false ){
        delay_ms(50);
         if(((P0& (1<<7)) == (1<<7)) && IsDoorOpen == false ){  
           
            IsDoorOpen = true;
            PICTL |= (1<<0); // interupt on falling edge
            //printf("Door Opened\r\n");
            sendbuffer[3] = 'O';
            mSendMessageWithShortAddress(sendbuffer,8,0,1,1);
            //osal_pwrmgr_powerconserve();
            CLEAR_SLEEP_MODE() ;
         }
      }else if(((P0& (1<<7)) != (1<<7)) && IsDoorOpen == true ){
        delay_ms(50);
        if(((P0 & (1<<7)) != (1<<7)) && IsDoorOpen == true ){
          
          IsDoorOpen = false;
          PICTL &= ~(1<<0); // interupt on rising edge
          //printf("Door Closed\r\n");
          sendbuffer[3] = 'C';
          mSendMessageWithShortAddress(sendbuffer,8,0,1,1);
          //osal_pwrmgr_powerconserve();
          CLEAR_SLEEP_MODE() ;
          
        }
      }//else if((( P0 & (1<<6)) != (1<<6))  ){
       // delay_ms(50);
       // if((( P0 & (1<<6)) != (1<<6))  ){
       //   
       //
       //   PICTL |= (1<<0); // interupt on falling edge
       //   //printf("Factory reset\r\n");
       //   //sendbuffer[3] = 'C';
       //   //mSendMessageWithShortAddress(sendbuffer,8,0,1,1);
       //   //osal_pwrmgr_powerconserve();
       //   
       // }
       //}
      
      
      
      P0IFG &= ~(1 << 6);
      P0IFG &= ~(1 << 7);
      IRCON &= ~(1 << 5);
      
      //osal_pwrmgr_powerconserve();
      
      HAL_EXIT_ISR();
    
    }

  • You shouldn't put those application processing code is ISR. So, the power consumption issue is come from KEY event, am I correct?
  • im not sure
    then where should i put them?
    they just send some information and its finished . what should i do?
  • If you look into Z-Stack hal_key.c implementation, ISR would call halProcessKeyInterrupt to check key press and also invoke HAL_KEY_EVENT to debunce and read what key is pressed. Then, HalKeyPoll would call "(pHalKeyProcessFunction) (keys, HAL_KEY_STATE_NORMAL);" to send key event to application callback which is zclSampleLight_HandleKeys using sampleLight as example. You should do the same thing to your pin interrupt.
  • so this is my interupt routine
    HAL_ISR_FUNCTION(halKeyPort0Isr , P0INT_VECTOR ){
    
      HAL_ENTER_ISR();
    
      
      if(((P0& (1<<7)) == (1<<7)) && IsDoorOpen == false ){
            IsDoorOpen = true;
            PICTL |= (1<<0); // interupt on falling edge
            osal_start_timerEx(zclSampleLight_TaskID,0x501,50);
         
      }else if(((P0& (1<<7)) != (1<<7)) && IsDoorOpen == true ){
          IsDoorOpen = false;
          PICTL &= ~(1<<0); // interupt on rising edge
          osal_start_timerEx(zclSampleLight_TaskID,0x502,50);
        
      }
    
      P0IFG &= ~(1 << 6);
      P0IFG &= ~(1 << 7);
      IRCON &= ~(1 << 5); 
      HAL_EXIT_ISR();
    
    }
    

    and this is handler in zclSampleLight_event_loop

    uint8 sendbuffer[8];
      sendbuffer[0] = LocalDeviceID[0];
      sendbuffer[1] = LocalDeviceID[1];
      sendbuffer[2] = LocalDeviceID[2];
      
      sendbuffer[4] = '0';
      sendbuffer[5] = '0';
      sendbuffer[6] = '0';
      sendbuffer[7] = '\n';
      
      if(events == 0x501){
      
        osal_stop_timerEx(zclSampleLight_TaskID,0x501);
        if(((P0& (1<<7)) == (1<<7)) && IsDoorOpen == false ){  
          sendbuffer[3] = 'O';
          mSendMessageWithShortAddress(sendbuffer,8,0,1,1);
        }
      
      }
      
      if(events == 0x502){
      
        osal_stop_timerEx(zclSampleLight_TaskID,0x502);
        if(((P0 & (1<<7)) != (1<<7)) && IsDoorOpen == true ){
          sendbuffer[3] = 'C';
          mSendMessageWithShortAddress(sendbuffer,8,0,1,1);
        }
      }
    

    but its not working at all not even sending data

  • i deleted all new stuff and just interrupt is there like this

    HAL_ISR_FUNCTION(halKeyPort0Isr , P0INT_VECTOR ){
    
      HAL_ENTER_ISR();
    
      if(((P0& (1<<7)) == (1<<7)) && IsDoorOpen == false ){
          IsDoorOpen = true;
          PICTL |= (1<<0); // interupt on falling edge
         
      }else if(((P0& (1<<7)) != (1<<7)) && IsDoorOpen == true ){
    
          IsDoorOpen = false;
          PICTL &= ~(1<<0); // interupt on rising edge
      }
    
      P0IFG &= ~(1 << 6);
      P0IFG &= ~(1 << 7);
      IRCON &= ~(1 << 5);
    
      HAL_EXIT_ISR();
    
    }

    but still not going back to pm2

  • You don't set P0IF=0 in the end of your HAL_ISR_FUNCTION(halKeyPort0Isr , P0INT_VECTOR )
  • P0IF is in P0IFG that i clear it
  • P0IF and P0IFG are different. You have to clear both. You can refer to original HAL_ISR_FUNCTION( halKeyPort0Isr, P0INT_VECTOR ). By the way, you also need to call CLEAR_SLEEP_MODE() in the end of HAL_ISR_FUNCTION( halKeyPort0Isr, P0INT_VECTOR )