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?
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.
if (HAL_KEY_SW_7_PXIFG & HAL_KEY_SW_7_BIT) {HAL_KEY_SW_7_EDGE & = ~ (HAL_KEY_FALLING_EDGE);// 0 or 1PICTL |= HAL_KEY_SW_7_EDGEBIT;
halProcessKeyInterrupt(); }
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?
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
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.
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?
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
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
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);
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.
baby ,you are so kind
thanks very much
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
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.