Hi everyone
I am trying to read buttons from "ez430-rf2500" using pull up mode, however I could not read the button correctly, all the time it shows that the button is pressed but it is not pressed. can anyone help me? the program is shown below... I highlighted the main lines.
#define I_WANT_TO_CHANGE_DEFAULT_ROM_DEVICE_ADDRESS_PSEUDO_CODE
#include "bsp.h"
#include "mrfi.h"
#include "nwk_types.h"
#include "nwk_api.h"
#include "bsp_leds.h"
#include "bsp_buttons.h"
#include "vlo_rand.h"
#ifndef APP_AUTO_ACK
#error ERROR: Must define the macro APP_AUTO_ACK for this application.
#endif
void toggleLED(uint8_t);
static void linkTo(void);
static linkID_t sLinkID1 = 0;
#define SPIN_ABOUT_A_SECOND NWK_DELAY(1000)
#define SPIN_ABOUT_A_QUARTER_SECOND NWK_DELAY(250)
/* How many times to try a Tx and miss an acknowledge before doing a scan */
#define MISSES_IN_A_ROW 2
void createRandomAddress(void);
volatile int * tempOffset = (int *)0x10F4; // Temperature offset set at production
char * Flash_Addr = (char *)0x10F0; // Initialize radio address location
__interrupt void ADC10_ISR(void);
__interrupt void Timer_A (void);
/* work loop semaphores */
static volatile uint8_t sSelfMeasureSem = 0;
void main (void)
{
addr_t lAddr;
//WDTCTL = WDTHOLD | WDTPW;
P2SEL &=0x1F;
P2DIR &= 0xE0;
//P2REN|=0x1F;
P2OUT|=0x1F;
P4SEL&=0x38;
P4DIR &= 0xC7;
//P4REN|=0x38;
P4OUT|=0x38;
BSP_Init();
if(Flash_Addr[0] == 0xFF && Flash_Addr[1] == 0xFF &&
Flash_Addr[2] == 0xFF && Flash_Addr[3] == 0xFF )
{
createRandomAddress(); // set Random device address at initial startup
}
lAddr.addr[0] = Flash_Addr[0];
lAddr.addr[1] = Flash_Addr[1];
lAddr.addr[2] = Flash_Addr[2];
lAddr.addr[3] = Flash_Addr[3];
SMPL_Ioctl(IOCTL_OBJ_ADDR, IOCTL_ACT_SET, &lAddr);
/* Keep trying to join (a side effect of successful initialization) until
* successful. Toggle LEDS to indicate that joining has not occurred.
*/
while (SMPL_SUCCESS != SMPL_Init(0))
{
toggleLED(1);
toggleLED(2);
SPIN_ABOUT_A_SECOND;
}
/* LEDs on solid to indicate successful join. */
if (!BSP_LED2_IS_ON())
{
toggleLED(2);
}
if (!BSP_LED1_IS_ON())
{
toggleLED(1);
}
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
TACCTL0 = CCIE; // TACCR0 interrupt enabled
TACCR0 = 12000; // ~ 1 sec
TACTL = TASSEL_1 + MC_1; // ACLK, upmode
/* Unconditional link to AP which is listening due to successful join. */
linkTo();
while (1) ;
}
static void linkTo()
{
/*
In order to send the data we need to use the foll
*/
uint8_t poi=0;//pointer
uint8_t pp=0;// check state
uint8_t msg[1];
uint8_t misses, done;
int results[5];
uint8_t noAck;
smplStatus_t rc;
while(1)
{
if (!(P2IN & 0x00))
{
poi=0;
pp=1;
}
else if (!(P2IN & 0x01))
{
poi=1;
pp=1;
}
if (pp)
{
/* Keep trying to link... */
while (SMPL_SUCCESS != SMPL_Link(&sLinkID1))
{
toggleLED(1);
toggleLED(2);
SPIN_ABOUT_A_SECOND;
}
/* Turn off LEDs. */
if (BSP_LED2_IS_ON())
{
toggleLED(2);
}
if (BSP_LED1_IS_ON())
{
toggleLED(1);
}
SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, 0);
/* orginl PROGRAMM
while (1)
{
__bis_SR_register(LPM3_bits+GIE); // LPM3 with interrupts enabled
if (sSelfMeasureSem) {
volatile long temp;
int degC, volt;
int results[5];
uint8_t noAck;
smplStatus_t rc;*/
/* get radio ready...awakens in idle state */
SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0);
results[0]=0x5A;
results[1]=0x5B;
results[2]=0x46;
results[3]=0x47;
results[4]=0x28;
msg[0]=results[poi];
done = 0;
while (!done)
{
noAck = 0;
/* Try sending message MISSES_IN_A_ROW times looking for ack */
for (misses=0; misses < MISSES_IN_A_ROW; ++misses)
{
if (SMPL_SUCCESS == (rc=SMPL_SendOpt(sLinkID1, msg, sizeof(msg), SMPL_TXOPTION_ACKREQ)))
{
/* Message acked. We're done. Toggle LED 1 to indicate ack received. */
toggleLED(1); // Toggle On LED1
__delay_cycles(2000);
toggleLED(1);
break;
}
if (SMPL_NO_ACK == rc)
{
/* Count ack failures. Could also fail becuase of CCA and
* we don't want to scan in this case.
*/
noAck++;
}
}
if (MISSES_IN_A_ROW == noAck)
{
/* Message not acked. Toggle LED 2. */
toggleLED(2); // Turn On LED2
__delay_cycles(2000);
toggleLED(2);
#ifdef FREQUENCY_AGILITY
/* Assume we're on the wrong channel so look for channel by
* using the Ping to initiate a scan when it gets no reply. With
* a successful ping try sending the message again. Otherwise,
* for any error we get we will wait until the next button
* press to try again.
*/
if (SMPL_SUCCESS != SMPL_Ping(sLinkID1))
{
done = 1;
}
#else
done = 1;
#endif /* FREQUENCY_AGILITY */
}
else
{
/* Got the ack or we don't care. We're done. */
done = 1;
}
}
/* radio back to sleep */
SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_SLEEP, 0);
}
// } this for the while(1)
// }
pp=0;
}
}
void toggleLED(uint8_t which)
{
if (1 == which)
{
BSP_TOGGLE_LED1();
}
else if (2 == which)
{
BSP_TOGGLE_LED2();
}
return;
}
void createRandomAddress()
{
unsigned int rand, rand2;
do
{
rand = TI_getRandomIntegerFromVLO(); // first byte can not be 0x00 of 0xFF
}
while( (rand & 0xFF00)==0xFF00 || (rand & 0xFF00)==0x0000 );
rand2 = TI_getRandomIntegerFromVLO();
BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
DCOCTL = CALDCO_1MHZ;
FCTL2 = FWKEY + FSSEL0 + FN1; // MCLK/3 for Flash Timing Generator
FCTL3 = FWKEY + LOCKA; // Clear LOCK & LOCKA bits
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
Flash_Addr[0]=(rand>>8) & 0xFF;
Flash_Addr[1]=rand & 0xFF;
Flash_Addr[2]=(rand2>>8) & 0xFF;
Flash_Addr[3]=rand2 & 0xFF;
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCKA + LOCK; // Set LOCK & LOCKA bit
}
/*------------------------------------------------------------------------------
* ADC10 interrupt service routine
------------------------------------------------------------------------------*/
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
/*------------------------------------------------------------------------------
* Timer A0 interrupt service routine
------------------------------------------------------------------------------*/
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
sSelfMeasureSem = 1;
__bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bit from 0(SR)
}