Other Parts Discussed in Thread: CC1101
Hey guys,
I wanted to pair two ez430 chronos watches together for my college project. I am using the source code from a team project on ti website.
http://processors.wiki.ti.com/index.php/RF-PID#Engineers
The code the team used was based off the cc430 rf examples but they adjusted it for the watch. I want one of the watches to display something after the other watch has been pushed to transmit. I tried to define the words that can displayed on the screen but it isn't working. If you can help me out on this part that'd be great!
#include "RF_Toggle_LED_Demo.h"
#include "display.h"
#include "string.h"
#include "project.h"
#define PACKET_LEN (0x05) // PACKET_LEN <= 61
#define RSSI_IDX (PACKET_LEN+1) // Index of appended RSSI
#define CRC_LQI_IDX (PACKET_LEN+2) // Index of appended LQI, checksum
#define CRC_OK (BIT1) // CRC_OK bit
#define PATABLE_VAL (0x51) // 0 dBm output
#define LIGHT_ON (0xC0) //Turn LED On
#define ALL_OFF (0x00) //Turn LED Off
#define ALL_ON (0xFF) //ALL HIGH
#define BUZZER_ON (0xEA) //Turn on Buzzer
#define SPEAKER_HIGH (0x11)
#define SPEAKER_LOW (0x14)
extern RF_SETTINGS rfSettings;
unsigned char packetReceived;
unsigned char packetTransmit;
unsigned char RxBuffer[64];
unsigned char RxBufferLength = 0;
const unsigned char TxBuffer[6]= {PACKET_LEN, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE};
unsigned char buttonPressed = 0;
unsigned int i = 0;
u8 word[3] = "RDY";
u8 incoming[3] = "YES";
u8 msg[2] = "TX";
unsigned char transmitting = 0;
unsigned char receiving = 0;
unsigned char on = 0;
unsigned int nodeNow = 0;
unsigned int RSSIValue = 0;
void wait();
int x = 0;
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
// Increase PMMCOREV level to 2 for proper radio operation
SetVCore(2);
ResetRadioCore();
InitRadio();
InitButtonLeds();
lcd_init();
ReceiveOn();
receiving = 1;
RSSIValue = RxBuffer[RSSI_IDX];
while (1)
{
display_chars(LCD_SEG_L1_3_0, word, SEG_ON);
display_value1(LCD_SEG_L2_1_0, RSSIValue, 2, 0);
__bis_SR_register( LPM3_bits + GIE );
__no_operation();
RSSIValue = RxBuffer[RSSI_IDX];
if (buttonPressed) // Process a button press->transmit
{
buttonPressed = 0;
P2IFG = 0;
ReceiveOff();
receiving = 0;
if(!on)
{
display_symbol(LCD_ICON_BEEPER1, SEG_ON);
display_symbol(LCD_ICON_BEEPER2, SEG_ON);
display_symbol(LCD_ICON_BEEPER3, SEG_ON);
on=1;
}
else
{
display_symbol(LCD_ICON_BEEPER1, SEG_OFF);
display_symbol(LCD_ICON_BEEPER2, SEG_OFF);
display_symbol(LCD_ICON_BEEPER3, SEG_OFF);
on=0;
}
Transmit( (unsigned char*)TxBuffer, sizeof TxBuffer);
transmitting = 1;
P2IE |= (BIT2+BIT1); // Re-enable button press
}
else if(!transmitting)
{
ReceiveOn();
receiving = 1;
}
}
}
void wait()
{
/* simple delay function */
volatile int i;
for(i = 0; i < 228; i++)
{
}
}
void InitButtonLeds(void)
{
// Set up the button as interruptible
P2DIR &= ~(BIT2+BIT1);
P2REN |= (BIT2+BIT1);
P2IES &= ~(BIT2+BIT1);
P2IFG = 0;
// P2OUT |= BIT2;
P2IE |= (BIT2+BIT1);
// Initialize Port J
PJOUT = 0x00;
PJDIR = 0xFF;
}
void InitRadio(void)
{
// Set the High-Power Mode Request Enable bit so LPM3 can be entered
// with active radio enabled
PMMCTL0_H = 0xA5;
PMMCTL0_L |= PMMHPMRE_L;
PMMCTL0_H = 0x00;
WriteRfSettings(&rfSettings);
WriteSinglePATable(PATABLE_VAL);
}
#pragma vector=PORT2_VECTOR
__interrupt void PORT2_ISR(void)
{
switch(__even_in_range(P2IV, 16))
{
case 0: break;
case 2: break; // P2.0 IFG
case 4: // P2.1 IFG
P2IE = 0;
WDTCTL = 0x00;
break; // Software Reset of Watch
case 6: // P2.2 IFG
P2IE = 0; // Debounce by disabling buttons
buttonPressed = 1;
__bic_SR_register_on_exit(LPM3_bits);
break; // Button Press to Transmit to Nodes
case 8: break; // P2.3 IFG
case 10: break; // P2.4 IFG
case 12: break; // P2.5 IFG
case 14: break; // P2.6 IFG
case 16: break; // P2.7 IFG
}
}
void Transmit(unsigned char *buffer, unsigned char length)
{
display_chars(LCD_SEG_L1_3_0, msg, SEG_ON);
RF1AIES |= BIT9;
RF1AIFG &= ~BIT9; // Clear pending interrupts
RF1AIE |= BIT9; // Enable TX end-of-packet interrupt
WriteBurstReg(RF_TXFIFOWR, buffer, length);
Strobe( RF_STX ); // Strobe STX
}
void ReceiveOn(void)
{
display_chars(LCD_SEG_L1_3_0, msg, SEG_ON);
RF1AIES |= BIT9; // Falling edge of RFIFG9
RF1AIFG &= ~BIT9; // Clear a pending interrupt
RF1AIE |= BIT9; // Enable the interrupt
// Radio is in IDLE following a TX, so strobe SRX to enter Receive Mode
Strobe( RF_SRX );
}
void ReceiveOff(void)
{
RF1AIE &= ~BIT9; // Disable RX interrupts
RF1AIFG &= ~BIT9; // Clear pending IFG
// It is possible that ReceiveOff is called while radio is receiving a packet.
// Therefore, it is necessary to flush the RX FIFO after issuing IDLE strobe
// such that the RXFIFO is empty prior to receiving a packet.
Strobe( RF_SIDLE );
Strobe( RF_SFRX );
}
#pragma vector=CC1101_VECTOR
__interrupt void CC1101_ISR(void)
{
switch(__even_in_range(RF1AIV,32)) // Prioritizing Radio Core Interrupt
{
case 0: break; // No RF core interrupt pending
case 2: break; // RFIFG0
case 4: break; // RFIFG1
case 6: break; // RFIFG2
case 8: break; // RFIFG3
case 10: break; // RFIFG4
case 12: break; // RFIFG5
case 14: break; // RFIFG6
case 16: break; // RFIFG7
case 18: break; // RFIFG8
case 20: // RFIFG9
if(receiving) // RX end of packet
{
//display_chars(LCD_SEG_L1_3_0, letter , SEG_ON);
nodeNow = !nodeNow; // Turn on the node
// Read the length byte from the FIFO
RxBufferLength = ReadSingleReg( RXBYTES );
ReadBurstReg(RF_RXFIFORD, RxBuffer, RxBufferLength);
// Stop here to see contents of RxBuffer
__no_operation();
// Check the CRC results
if(RxBuffer[CRC_LQI_IDX] & CRC_OK)
P2OUT ^= BIT0; // Toggle LED1
}
else if(transmitting) // TX end of packet
{
//display_chars(LCD_SEG_L1_3_0, letter , SEG_ON);
RF1AIE &= ~BIT9; // Disable TX end-of-packet interrupt
P3OUT &= ~BIT6; // Turn off LED after Transmit
transmitting = 0;
}
else while(1); // trap
break;
case 22: break; // RFIFG10
case 24: break; // RFIFG11
case 26: break; // RFIFG12
case 28: break; // RFIFG13
case 30: break; // RFIFG14
case 32: break; // RFIFG15
}
__bic_SR_register_on_exit(LPM3_bits);