• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Low Power RF & Wireless Connectivity » Low Power RF ZigBee® Software & IEEE 802.15.4 Forum » Add a new key question
Share
Low Power RF & Wireless Connectivity
  • Forums
  • Announcements
  • Files
  • E2E Wiki
Options
  • Subscribe via RSS

Forums

Add a new key question

This question is not answered
kidd dexter
Posted by kidd dexter
on Aug 10 2012 10:08 AM
Prodigy215 points

I want add a new key on port p1_6

cc2530EB, zstack2.3.0

#define HAL_KEY_SW_7_PORT P1
#define HAL_KEY_SW_7_BIT BV(6)
#define HAL_KEY_SW_7_SEL P1SEL
#define HAL_KEY_SW_7_DIR P1DIR

#define HAL_KEY_SW_7_EDGEBIT BV(2)
#define HAL_KEY_SW_7_EDGE HAL_KEY_FALLING_EDGE

#define HAL_KEY_SW_7_IEN IEN2 /* CPU interrupt mask register */
#define HAL_KEY_SW_7_IENBIT BV(4) /* Mask bit for all of Port_1 */
#define HAL_KEY_SW_7_ICTL P1IEN /* Port Interrupt Control register */
#define HAL_KEY_SW_7_ICTLBIT BV(6) /* P0IEN - P0.1 enable/disable bit */
#define HAL_KEY_SW_7_PXIFG P1IFG /* Interrupt flag at source */

actually , I copied the #defines from HAL_KEY_SW_6

but something changed 

like #define HAL_KEY_SW_7_EDGEBIT BV(2) and  #define HAL_KEY_SW_7_IENBIT BV(4) 

I dont know why  HAL_KEY_SW_7_IENBIT is BV(4) and HAL_KEY_SW_6_IENBIT   is BV(5)

actually , I could not change these two defines, If I changed, the sw1 key (p0_1) and p1_6 wont work

anybody know why?

Now

in void HalKeyInit( void )

I also add 

HAL_KEY_SW_7_SEL &= ~(HAL_KEY_SW_7_BIT); /* Set pin function to GPIO */
HAL_KEY_SW_7_DIR &= ~(HAL_KEY_SW_7_BIT); /* Set pin direction to Input */

in  HalKeyConfig 

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

HAL_KEY_SW_7_ICTL |= HAL_KEY_SW_7_ICTLBIT;
HAL_KEY_SW_7_IEN |= HAL_KEY_SW_7_IENBIT;
HAL_KEY_SW_7_PXIFG = ~(HAL_KEY_SW_7_BIT);

in HalKeyRead 

//if (HAL_PUSH_BUTTON1())

if(!(HAL_KEY_SW_6_PORT & HAL_KEY_SW_6_BIT) )
{
   keys |= HAL_KEY_SW_6;
}

if (!(HAL_KEY_SW_7_PORT & HAL_KEY_SW_7_BIT)) /* Key is active low *///,P1.6
{
   keys |= HAL_KEY_SW_7;
}

as you can see, I change HAL_KEY_SW_6  ,  from HAL_PUSH_BUTTON1 to !.....

in HalKeyPoll

//if (HAL_PUSH_BUTTON1())
if(!(HAL_KEY_SW_6_PORT & HAL_KEY_SW_6_BIT) )
{
  keys |= HAL_KEY_SW_6;
}

if (!(HAL_KEY_SW_7_PORT & HAL_KEY_SW_7_BIT)) /* Key is active low *///,P1.6
// if( (!(P1_6)))
{
  keys |= HAL_KEY_SW_7;
}

nearly, I copied the process way as HAL_KEY_SW_6

in void halProcessKeyInterrupt (void)

if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT) /* Interrupt Flag has been set */
{
 HAL_KEY_SW_7_PXIFG = ~(HAL_KEY_SW_7_BIT); /* Clear Interrupt Flag */
 valid = TRUE;
}

then add a interrupt

HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR )
{

if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT)
{
   halProcessKeyInterrupt();

}

/*
Clear the CPU interrupt flag for Port_0
PxIFG has to be cleared before PxIF
*/
  HAL_KEY_SW_7_PXIFG = 0;
  HAL_KEY_CPU_PORT_1_IF = 0;
}

that's all in hal/target/CC2530EB/hal_key.c

then in my GenericApp_HandleKeys( uint8 shift, uint8 keys )

in the condition of 

if I  press the button on p1_6,which is HAL_KEY_SW_7

it will always mixed with HAL_KEY_SW_1,which the if ( keys& HAL_KEY_SW_X ) can be true both HAL_KEY_SW_1 and HAL_KEY_SW_7

and the key event is not very stable

I can catch every time of my pressing

but not everytime of my releasing

why?

CC2530 KEY HAL
Report Abuse
  • Reply
You have posted to a forum that requires a moderator to approve posts before they are publicly available.
All Replies
  • greenja
    Posted by greenja
    on Aug 14 2012 03:37 AM
    Guru11560 points

    Hello dexter,

    The first thing to do is download the latest version of ZStack.

    Keyswitch 6 is actually defined as bit 1 Port 0 in the hal_key.c #define HAL_KEY_SW_6_BIT    BV(1)

    I believe the P1_7, P1_6 and P1_5 are being used for SPI and is set as a priority for those pins. 

    For testing for HAL_KEY_SW_7, the if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT) in your interrupt ISR routine should work fine.

    I don't think you can set the Interrupt level for both rising and falling edges, I think it has to be one or the other.

    There may be a lot of noise on they key and you are getting a lot of key bounce. You would have to change the edge trigger level to the opposite value in the interrupt.

    HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR )
    {

    if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT)
    {
    HAL_KEY_SW_7_EDGE & = ~ (HAL_KEY_FALLING_EDGE);// 0 or 1
    PICTL |= HAL_KEY_SW_7_EDGEBIT;

       halProcessKeyInterrupt();
    }

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • kidd dexter
    Posted by kidd dexter
    on Aug 15 2012 22:33 PM
    Prodigy215 points

    Hello greenja

    Thanks for your reply

    So you mean cc2530 can not have a switch function, only button with pressing?

    and I still confused about  EDGEBIT and IENBIT, why  EDGEBIT & IENBIT OF HAL_KEY_SW_7  is different from HAL_KEY_SW_6

    is there any doc about how to decide EDGEBIT & IENBIT?

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • kidd dexter
    Posted by kidd dexter
    on Aug 15 2012 23:15 PM
    Prodigy215 points

    And

    I do want to use the latest version of zstack

    But the latest version of zstack has problem with secure

    such as can not join or rejoin in the SECURE mode

    if I modify the ZSecMgr.c as the forum told me,  which is about key frame count  

    the coordinator will remove any successfully joined router/end device from assocDevList

    etc..

    So

    I may choice a stable verion of zstack

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • greenja
    Posted by greenja
    on Aug 16 2012 04:30 AM
    Guru11560 points

    Hello kidd,

    I think of a switch and button as being the same thing really and so does the MCU.  The only difference is that a switch can be held in a position permanently while a button is momentary.

    You can use the CC2530 for both a switch and button function.

    You can find all the information on EDGEBIT and IENBIT in the CC253x/CC254x user guide.  It doesn't really explain anything in detail though and is found here:

    http://www.ti.com/litv/pdf/swru191c

    Take a look at the ioCC2530.h file for more clarity on the registers and how they are set up.

    In general, the EDGEBIT determines if the rising edge (0 -> 1) or falling edge (1 -> 0) is used to trigger an interrupt.  The IENBIT allows an interrupt to happen based on the setting of the EDGEBIT for a particular bit.  That is the reason for the difference.

    As for the ZStack, you should post that as another question for a faster answere.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • kidd dexter
    Posted by kidd dexter
    on Aug 17 2012 00:05 AM
    Prodigy215 points

    Hello greenja

    Thanks for your professional reply

    it help me a lot

    lol

    as for the zstack, I think ti is working on it

    so I just need wait

    By the way, is there a interrupt or something in cc2530 ,to deal with long time key pressing? such as press like five seconds

    or

    I still need a timer by my hand to deal with the long time pressing?

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • kidd dexter
    Posted by kidd dexter
    on Aug 17 2012 03:40 AM
    Prodigy215 points

    And

    if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT)
    {
      HAL_KEY_SW_7_EDGE &=~(HAL_KEY_FALLING_EDGE);// 0 or 1

      PICTL |= HAL_KEY_SW_7_EDGEBIT;

      halProcessKeyInterrupt();
    } // 


    These codes can not be complied by IAR 8.0.3

    Error[Pe137]: expression must be a modifiable lvalue D:\Texas Instruments\ZStack-CC2530-2.3.0-1.4.0\Components\hal\target\CC2530EB\hal_key.c 559


    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • kidd dexter
    Posted by kidd dexter
    on Aug 17 2012 03:47 AM
    Prodigy215 points

    And

    The default key ,sw1, HAL_KEY_SW_6 is not stable with pressing and releasing,too 

    I think the problem is not just about HAL_KEY_SW_7 

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • greenja
    Posted by greenja
    on Aug 17 2012 06:06 AM
    Guru11560 points

    Hello,

    The line HAL_KEY_SW_7_EDGE &=~(HAL_KEY_FALLING_EDGE);// 0 or 1 is what is causing the error.  It is a #define statement and cannot be changed.

    You can try this:

    if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT)
    {
     

      PICTL |=  ~(HAL_KEY_SW_7_EDGEBIT);

      halProcessKeyInterrupt();
    } //

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • greenja
    Posted by greenja
    on Aug 17 2012 06:23 AM
    Guru11560 points

    The problem with the stability of the HAL_KEY_SW_6 is due to contact bounce. 

    You are not really suppose to use a switch that has not been conditioned as an interrupt input, it has to be properly debounced.

    There is a software debounce used for the keys found in hal_board_cfg.h, you can try extending the time or create another function based on some of the other debounce routines you can find on the internet:

    #define HAL_DEBOUNCE(expr)    { int i; for (i=0; i<500; i++) { if (!(expr)) i = 0; } }

    There are many ways to debounce the switch and some very good articles.  I can't seem to find them on my system right now.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • kidd dexter
    Posted by kidd dexter
    on Aug 17 2012 07:23 AM
    Prodigy215 points

    Hello greenja

    baby ,you are so kind

    thanks very much

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • kidd dexter
    Posted by kidd dexter
    on Aug 18 2012 07:52 AM
    Prodigy215 points

    hello greenja

    I dont knon if you can see this

    I tested today

    the results is not good

    first, I still confused about HAL_KEY_SW_1 AND HAL_KEY_SW_6

    you say HAL_KEY_SW_6 is BV(1) 

    so why in the key event

    if ( keys & HAL_KEY_SW_1 ) and if ( keys & HAL_KEY_SW_6 )  working true both in the same time?

    so what it really is ? SW_1 OR SW_6 ? OR BOTH??

    Is this  wired ?

    and 

    when I  press button on p1_6

    It returned with two key events

     HAL_KEY_SW_1 and  HAL_KEY_SW_7

    yeah' that's funny, another working true both in the same time

    Cause I thought , because I define  HAL_KEY_SW_7 as BV(6) 

    it might be the event of  HAL_KEY_SW_6

    now I really confused

    Are these key event associaed with the names of #define?

    But 

    not true  for HAL_KEY_SW_6, you know, it is  HAL_KEY_SW_1 and HAL_KEY_SW_6

    and I  do not understand,why TI made this wired key 

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
  • kidd dexter
    Posted by kidd dexter
    on Aug 18 2012 08:02 AM
    Prodigy215 points

    and other funny thing

    I do the same init on HAL_KEY_SW_6 and HAL_KEY_SW_7

    same  EDGE

    #define HAL_KEY_SW_6_EDGE     HAL_KEY_FALLING_EDGE

    #define HAL_KEY_SW_7_EDGE     HAL_KEY_FALLING_EDGE

    WHEN I press the key on P0_1 which is HAL_KEY_SW_6 

    it will happend in my key event ,with if(shift) == true

    not the same as HAL_KEY_SW_7

    For HAL_KEY_SW_7

    it will  be untrue of if(shift)

    you know, there is a shift in  KEY event function.

    static void GenericApp_HandleKeys( uint8 shift, uint8 keys )

    The key problem 

    is really killing me.

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
TI E2E™ Community
  • Support Forums
  • Blogs
  • Videos
  • Groups
  • Site Support & Feedback
  • Settings
TI E2E™ Community Groups
  • TI University Program
  • Make the Switch
  • Microcontroller Projects
  • Motor Drive & Control
Other Communities
  • Deyisupport
  • Designsomething.org
  • beagleboard.org
  • TI on Element 14
  • TI on TechXchangeSM
Other Technical & Support Resources
  • WEBENCH® Design Center
  • Product Information Centers
  • Technical Documents
  • TI Design Network
  • TI Technical Articles
  • TI Training

All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
embedded processors, along with software, tools and the industry’s largest sales/support staff.

© Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy Policy | Terms of Use