main.c
上传用户:zhingjinbo
上传日期:2014-07-24
资源大小:32k
文件大小:5k
- //----------------------------------------------------------------------------
- // RF Lab
- // ATC 2006
- // Participant's Code
- //
- // Presenter: K. Quiring
- // Texas Instruments, Inc.
- // November 2006
- // IAR Embedded Workbench v3.41
- //----------------------------------------------------------------------------
- #include "include.h"
- extern char paTable[];
- extern char paTableLen;
- char txBuffer[20];
- char rxBuffer[20];
- const unsigned int kTableCount=20;
- char kCrLn[2] = {0x0A, 0x0D};
- unsigned int i, address_bind;
- void main (void)
- {
- WDTCTL = WDTPW + WDTHOLD; // Stop WDT
- address_bind = 0;
- // Wait for xtal to stabilize
- do
- {
- IFG1 &= ~OFIFG; // Clear OSCFault flag
- for (i = 0x47FF; i > 0; i--); // Time for flag to set
- }
- while ((IFG1 & OFIFG)); // OSCFault flag still set?
- TI_CC_SPISetup(); // Initialize SPI port
- TI_CC_PowerupResetCCxxxx(); // Reset CCxxxx
- writeRFSettings(); // Write RF settings to config reg
- TI_CC_SPIWriteBurstReg(TI_CCxxx0_PATABLE, paTable, paTableLen);//Write PATABLE
- // Configure ports -- switch inputs, LEDs, GDO0 to RX packet info from CCxxxx
- TI_CC_SW_PxIES = TI_CC_SW1; // Int on falling edge
- TI_CC_SW_PxIFG &= ~(TI_CC_SW1); // Clr flags
- TI_CC_SW_PxIE = TI_CC_SW1; // Activate enables
- TI_CC_GDO0_PxIES |= TI_CC_GDO0_PIN; // Int on falling edge (end of pkt)
- TI_CC_GDO0_PxIFG &= ~TI_CC_GDO0_PIN; // Clear flag
- TI_CC_GDO0_PxIE |= TI_CC_GDO0_PIN; // Enable int on end of packet
- // *** PHASE 1 TEST CODE ***
- // To test the SPI connection, uncomment this code and set a breakpoint to
- // observe testBuffer after the burst read is executed. The register settings
- // should match the ones programmed in writeRFSettings().
- char testBuffer[0x3A];
- TI_CC_SPIReadBurstReg(TI_CCxxx0_IOCFG2, testBuffer, 0x3B);
- _NOP();
- halUARTSetup();
- TI_CC_SPIStrobe(TI_CCxxx0_SRX); // Initialize CCxxxx in RX mode.
- // When a pkt is received, it will
- // signal on GDO0 and wake CPU
- _BIS_SR(LPM3_bits + GIE); // Enter LPM3, enable interrupts
- }
- // The ISR assumes the interrupt came from a press of one of the four buttons
- // and therefore does not check the other four inputs.
- #pragma vector=PORT1_VECTOR
- __interrupt void port1_ISR (void)
- {
- unsigned int i;
- const char kTableStr[] = "MSP430 TEST";
- char len;
- if(P1IFG&TI_CC_SW1) // If interrupt comes from switch
- {
- if (!address_bind)
- {
- txBuffer[0] = 7;
- txBuffer[1] = 0x01; // Pkt address
- txBuffer[2] = 0x35;
- txBuffer[3] = 0xFF;
- txBuffer[4] = 0xFF;
- txBuffer[5] = 0xFF;
- txBuffer[6] = 0x80;
- txBuffer[7] = 0x35;
- RFSendPacket(txBuffer, 8); // Send Address Binding
- address_bind = 1;
- for (i=0; i<50000; i++); // delay
- }
- // Build packet
- txBuffer[0] = 19; // Pkt length (not inc. len byte)
- txBuffer[1] = 0x01; // Pkt address
- txBuffer[2] = 0x35;
- txBuffer[3] = 0x12;
- txBuffer[4] = 0x13;
- txBuffer[5] = 0x14;
- txBuffer[6] = 0x00;
- for (i=0; i<11; i++)
- txBuffer[i+7] = kTableStr[i];
- txBuffer[18] = 0xA;
- txBuffer[19] = 0xD;
- RFSendPacket(txBuffer, 20); // Send Data Packet
- txBuffer[1] = 0x35;
- RFSendPacket(txBuffer, 20);
- for (i=0; i<50000; i++); // delay
- txBuffer[0] = 7; // Pkt length (not inc. len byte)
- txBuffer[1] = 0x01; // Pkt address
- txBuffer[2] = 0x35;
- txBuffer[3] = 0x12;
- txBuffer[4] = 0x13;
- txBuffer[5] = 0x14;
- txBuffer[6] = 0x20;
- txBuffer[7] = 0x0A;
- RFSendPacket(txBuffer, 8); // Send Data Request
- }
- //else if(P1IFG&TI_CC_GDO0_PIN) // If int comes from rx'ed packet
- //{
- if (RFReceivePacket(rxBuffer,&len)) // Fetch packet from CCxxxx
- {
- txBuffer[0] = 6; // Pkt length (not inc. len byte)
- txBuffer[1] = 0x01; // Pkt address
- txBuffer[2] = 0x35;
- txBuffer[3] = 0x12;
- txBuffer[4] = 0x13;
- txBuffer[5] = 0x14;
- txBuffer[6] = 0x40|*(rxBuffer+5);
- RFSendPacket(txBuffer, 7); // Send Ack
- if (len > 6)
- {
- blastString(rxBuffer+6,len-6);
- blastString(kCrLn,2); // Carriage return / new line
- }
- }
- //}
- P1IFG &= ~(TI_CC_SW1+TI_CC_GDO0_PIN); // Clr flags set by switch and GDO0
- }