CC2530: How do I Configure LEDs

Part Number: CC2530
Other Parts Discussed in Thread: CC2592, CC2590

Hi Guys, 

I working on my custom board (Zstack 1.2 based on light switch project) and I have several doubts about the LEDs configuration, I thinking that I have wrong configuration on the LED1 and LED3. At this moment only LED2 (Attaching Status) is working very well. I have tree LEDs as I describing bellow:

1 - D1  - Circuit status (ON/OFF)

2 - D2 -  Circuit Status (ON/OFF)

3 - D3 - Attaching Status, it´s working according ZDapp.c 

I using the LED1 and LED3 on my App file to represent the zclMyAPP_OnOffC1 == LIGHT_ON /LIGHT_OFF or  zclMyAPP_OnOffC2 == LIGHT_ON or /LIGHT_OFF, I made an working around using the P0 ports directly. 

Please, anybody can help to configure it?

I have setting those configuration on hal_board_cfg.h:

 LED1 (P0_0)  -  D1,

LED2 (P1_1)  - D3 

LED3 (P0_5)  -  D2


My Electrical LED Interface Circuit:

I have setting UP those configurations on my custom board as I describing bellow:

In my App I have setting up P0 SEL and P0 DIR for ports P0_0 and P0_5:

    
    Profile 1 (EP 1)
    P0SEL &= (~BV(0)); // LED GREEN CIRC. 1
    P0DIR |= (BV(0)); 
    
    Profie 2 (EP 2)
    P0SEL &= (~BV(5)); // LED GREEN CIRC 2
	P0DIR |= (BV(5)); 

On_board_cfg.h Ports definitions:

/* 1 - Green D1 - Circuit 1 */
  #define LED1_BV           BV(0)
  #define LED1_SBIT         P0_0
  #define LED1_DDR          P0DIR
  #define LED1_POLARITY     ACTIVE_LOW
  
  /* 2 - Green D2 - Circuit 2 */
  #define LED3_BV           BV(5)
  #define LED3_SBIT         P0_5 
  #define LED3_DDR          P0DIR
  #define LED3_POLARITY     ACTIVE_LOW
  
  /* 3 - Red - D3 - Attaching Status LED*/
  #define LED2_BV           BV(1) 
  #define LED2_SBIT         P1_1
  #define LED2_DDR          P1DIR
  #define LED2_POLARITY     ACTIVE_HIGH

On_bord_cfg.h LED configuration:

/* ----------- LED's ---------- */
#if defined (HAL_BOARD_CC2530EB_REV17) && !defined (HAL_PA_LNA) && \
    !defined (HAL_PA_LNA_CC2590) && !defined (HAL_PA_LNA_SE2431L) && \
    !defined (HAL_PA_LNA_CC2592)

  #define HAL_TURN_OFF_LED1()       st( LED1_SBIT = LED1_POLARITY (1); )
  #define HAL_TURN_OFF_LED2()       st( LED2_SBIT = LED2_POLARITY (0); )
  #define HAL_TURN_OFF_LED3()       st( LED3_SBIT = LED3_POLARITY (1); )

  #define HAL_TURN_ON_LED1()        st( LED1_SBIT = LED1_POLARITY (0); )
  #define HAL_TURN_ON_LED2()        st( LED2_SBIT = LED2_POLARITY (1); )
  #define HAL_TURN_ON_LED3()        st( LED3_SBIT = LED3_POLARITY (0); )

  #define HAL_TOGGLE_LED1()         st( if (LED1_SBIT) { LED1_SBIT = 0; } else { LED1_SBIT = 1;} )
  #define HAL_TOGGLE_LED2()         st( if (LED2_SBIT) { LED2_SBIT = 0; } else { LED2_SBIT = 1;} )
  #define HAL_TOGGLE_LED3()         st( if (LED3_SBIT) { LED3_SBIT = 0; } else { LED3_SBIT = 1;} )

  #define HAL_STATE_LED1()          (LED1_POLARITY (LED1_SBIT))
  #define HAL_STATE_LED2()          (LED2_POLARITY (LED2_SBIT))
  #define HAL_STATE_LED3()          (LED3_POLARITY (LED3_SBIT))
      
#elif defined (HAL_PA_LNA_SE2431L) || defined (HAL_PA_LNA_CC2592)

#elif defined (HAL_BOARD_CC2530EB_REV13) || defined (HAL_PA_LNA) || \
      defined (HAL_PA_LNA_CC2590)
  #define HAL_TURN_OFF_LED1()       st( LED1_SBIT = LED1_POLARITY (1); )
  #define HAL_TURN_OFF_LED2()       st( LED2_SBIT = LED2_POLARITY (0); )
  #define HAL_TURN_OFF_LED3()       st( LED3_SBIT = LED3_POLARITY (1); )

  #define HAL_TURN_ON_LED1()        st( LED1_SBIT = LED1_POLARITY (0); )
  #define HAL_TURN_ON_LED2()        st( LED2_SBIT = LED2_POLARITY (1); )
  #define HAL_TURN_ON_LED3()        st( LED3_SBIT = LED3_POLARITY (0); )

  #define HAL_TOGGLE_LED1()         st( if (LED1_SBIT) { LED1_SBIT = 0; } else { LED1_SBIT = 1;} )
  #define HAL_TOGGLE_LED2()         st( if (LED2_SBIT) { LED2_SBIT = 0; } else { LED2_SBIT = 1;} )
  #define HAL_TOGGLE_LED3()         st( if (LED3_SBIT) { LED3_SBIT = 0; } else { LED3_SBIT = 1;} )

  #define HAL_STATE_LED1()          (LED1_POLARITY (LED1_SBIT))
  #define HAL_STATE_LED2()          (LED2_POLARITY (LED2_SBIT))
  #define HAL_STATE_LED3()          (LED3_POLARITY (LED3_SBIT))

#endif

Could you see attached my on_board_cfg.h

hal_board_cfg.h

  • Do you define HAL_BOARD_CC2530EB_REV17 in your project?

  • Hi Mr Yk,

    Yes I have already included HAL_BOARD_CC2530EB_REV17 on IAR compiler options. But the LED1 and LED3 doesn´t working!

    I forgot to include the Hal_borg_cfg.h information about the number of leds included on my project .

    * ------------------------------------------------------------------------------------------------
     *                                       LED Configuration
     * ------------------------------------------------------------------------------------------------
     */
    #if defined (HAL_BOARD_CC2530EB_REV17) && !defined (HAL_PA_LNA) && \
        !defined (HAL_PA_LNA_CC2590) && !defined (HAL_PA_LNA_SE2431L) && \
        !defined (HAL_PA_LNA_CC2592)
      #define HAL_NUM_LEDS            3
    #elif defined (HAL_BOARD_CC2530EB_REV13) || defined (HAL_PA_LNA) ||  \
          defined (HAL_PA_LNA_CC2590)  || defined (HAL_PA_LNA_CC2592) || \
          defined (HAL_PA_LNA_SE2431L)
      #define HAL_NUM_LEDS            1
    #else
      #error Unknown Board Indentifier
    #endif

    Br,

    Alex

  • Your hardware and software configuration work well,you shall put HAL_TURN_ON_LED1() on next of HAL_BOARD_INIT() in main function for test LED work correct or not,if work well,you can step by step hit the issue. 

  • I would suggest you to set breakpoints on when your turn on/off D1 and D3 to check if P0SEL and P0DIR are overwrite by other drivers.

  • Hi Mr YK, thanks.

    I tried before to make breakpoints at hal_borad and hal_led, but I didn´t have a success to see what is the problem. After your advise, I included breakpoint on my APP, at the point of my code call LED3, and saw that the Port P1_4 is activated or deactivated, according my device turn on or turn off. But the Port P1_4 doesn´t defined on hal_board_cfg. The port defined on hal_board is P0_5, as you can see bellow:

      /* 2 - Green D2 - Circuit 2 */
      #define LED3_BV           BV(5)
      #define LED3_SBIT         P0_5 
      #define LED3_DDR          P0DIR
      #define LED3_POLARITY     ACTIVE_LOW

    My app code, at the point that the code explain when it call LED3

    Note: I commented out P0_5 to test HAL_LED_3.

      if ( keys & HAL_KEY_SW_6 )
      {
        // toggle local light immediately
        zclAZh0004_OnOffC2 = zclAZh0004_OnOffC2 ? LIGHT_OFF : LIGHT_ON;
    	
    	if ( zclAZh0004_OnOffC2 == LIGHT_ON )
    	{
    	  osal_start_timerEx( zclAZh0004_TaskID, AZh0004_LEVEL_CTRL_EVT, 100 );
    		//P1_5 = 1; // AZH0004 OC2 turn on Relay
    		 //P0_5 = 0; // LED GREEN is active in low
    		 HalLedSet ( HAL_LED_3, HAL_LED_MODE_OFF );
    
    		
    
    	}
    	
    	// Turn off the light via ZCL ON/OFF CMD
    	else if ( zclAZh0004_OnOffC2 == LIGHT_OFF )
    	{
    	  //osal_start_timerEx( zclAZh0004_TaskID, AZh0004_LEVEL_CTRL_EVT, 100 );
    		//P1_5 = 0; // AZH0004 OC2 turn on Relay
    		//P0_5 = 1; // LED GREEN is active in low
    		HalLedSet ( HAL_LED_3, HAL_LED_MODE_ON );
    
    		
    	}

    The breakpoint at excly moment when LED3 was called, but hit P1_4 

  • Maybe try to use the following code to turn on LED3

    P0SEL ^= BV(5);

    P0DIR |= BV(5);

    P0_5= 1;

    and the following code to turn off LED3

    P0SEL ^= BV(5);

    P0DIR |= BV(5);

    P0_5= 0;

  • Mr Yk, I got success before when I use directly P0_5 in my app code in the  keys & HAL_KEY_SW_6 (on/off)!

    I really trying to use the drive structure (hla_board_cfg and hal_led) to turn on or turn off the LED3. But I doesn't know why is happening that LED3_BV and LED3_SBIT as P0_5 is not working.

    BR

    Alex

  • There must be somewhere change P0SEL or P0DIR in your code to cause P0.5 not working so you can only trace it step by step after initialization to know which part of your application makes such modifications.

  • Mr. Yk, Sorry for my delay!

    I found my the problem, thanks a lot for your assistance!

    I´ll explain bellow for anyone to make the same mistake!

    After checked that the port that working when the LEDs are called, I observed that are the default ports used in Z stack files, after it I commented my hal_board_cfg.h in my project folder and start to rebuilding my project on IAR IDE and than noticed that nothing has been changed. The main problem is I have created a new hal target device and do not included it on Compiler options PROCESSOR. As you can see bellow:

    $PROJ_DIR$\..\..\..\..\..\Components\hal\target\NEW TARGET FOLDER

    after I fixed it everything works well!