?? rfcom.c
字號:
/*******************************************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** *
* *** + CHIPCON CC2420DBK EXAMPLES *
* *** + + *** RF Blinking LED Demo - Application Note 033 *
* *** +++ *** *
* *** *** *
* ************ *
* ********** *
* *
*******************************************************************************************************
* This program demonstrates the use of the CC2420DB library, including the basic RF library. The *
* packet protocol being used is a small subset of the IEEE 802.15.4 standard. It uses an 802.15.4 MAC *
* compatible frame format, but does not implement any other MAC functions/mechanisms (e.g. CSMA-CA). *
* The basic RF library can thus not be used to communicate with compliant 802.15.4 networks. *
* *
* A MSP430F1611 running this program will establish a point-to-point RF link on channel 26 with *
* a CC2420DB using the following node addresses: *
* - PAN ID: 0x2420 (both nodes) *
* - Short address: *
* 0x5678 *
* Destination address: 0x1234 *
* *
* This application is intended to work with the blinking LED application on a CC2420DB. *
* The pot-meter on the CC2420DB can be used to change the blinking frequency of the diode on *
* the MSP-FET430P140 board. *
* Please note that there is no so-called (PAN) coordinator. *
* *
* INSTRUCTIONS: *
* Outgoing data packets containing a 10-byte payload will be transmitted each 50th cycle of the *
* main program loop. Byte 0 contains the LED dimmer value to the CC2420DBB, byte 1 contains the *
* status byte from CC2420 and bytes 2/3 the number of packets received from the CC2420DB. *
* This application uses the value of byte 0 FROM the CC2420DB to regulate the blinking frequency of *
* the LED on the MSP-FET430P140. * *
* This example is based on the blinking LED example for the CC2420DB board. *
*******************************************************************************************************
* Compiler: MSP430 IAR C/C++ compiler or msp430-gcc GNU C compiler *
* Target platform: MSP-FET430P140 (can easily be ported to other platforms) *
*******************************************************************************************************
* Revision history: *
* *
*******************************************************************************************************/
//-------------------------------------------------------------------------------------------------------
// Include section
//-------------------------------------------------------------------------------------------------------
#include "rfcom.h"
//-------------------------------------------------------------------------------------------------------
// Defintions used locally in this file
//-------------------------------------------------------------------------------------------------------
#define PAYLOAD_SIZE 10
#define RF_CHANNEL 26
#define NUMBER_OF_BYTES 8 // Number of bytes in packet
static BYTE bytesCount = 0; // Bytes Counter
//-------------------------------------------------------------------------------------------------------
// Functions prototypes section
//-------------------------------------------------------------------------------------------------------
void ledFlash (UINT16, UINT16);
//-------------------------------------------------------------------------------------------------------
// Basic RF transmission and reception structures
//-------------------------------------------------------------------------------------------------------
BASIC_RF_RX_INFO rfRxInfo;
BASIC_RF_TX_INFO rfTxInfo;
//BYTE pTxBuffer[BASIC_RF_MAX_PAYLOAD_SIZE];
//BYTE pRxBuffer[BASIC_RF_MAX_PAYLOAD_SIZE];
BYTE pTxBuffer[PAYLOAD_SIZE];
BYTE pRxBuffer[PAYLOAD_SIZE];
//-------------------------------------------------------------------------------------------------------
// BASIC_RF_RX_INFO* basicRfReceivePacket(BASIC_RF_RX_INFO *pRRI)
//
// DESCRIPTION:
// This function is a part of the basic RF library, but must be declared by the application. Once
// the application has turned on the receiver, using basicRfReceiveOn(), all incoming packets will
// be received by the FIFOP interrupt service routine. When finished, the ISR will call the
// basicRfReceivePacket() function. Please note that this function must return quickly, since the
// next received packet will overwrite the active BASIC_RF_RX_INFO structure (pointed to by pRRI).
//
// ARGUMENTS:
// BASIC_RF_RX_INFO *pRRI
// The reception structure, which contains all relevant info about the received packet.
//
// RETURN VALUE:
// BASIC_RF_RX_INFO*
// The pointer to the next BASIC_RF_RX_INFO structure to be used by the FIFOP ISR. If there is
// only one buffer, then return pRRI.
//-------------------------------------------------------------------------------------------------------
BASIC_RF_RX_INFO* basicRfReceivePacket(BASIC_RF_RX_INFO *pRRI)
{
// Continue using the (one and only) reception structure
return pRRI;
} // basicRfReceivePacket
//--------------------------------------------------------------------------------------------------------
// MAIN
//--------------------------------------------------------------------------------------------------------
int main(void)
{
// Initalize basic clock module
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 &= ~XT2OFF; // XT2= HF XTAL
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (int i = 0xFF; i > 0; i--); // Time for flag to set
}
while ((IFG1 & OFIFG)); // OSCFault flag still set?
BCSCTL2 |= SELM_2 + SELS + DIVM_0 + DIVS_0; // MCLK = XT2 = 8MHz = 8MHz(safe); SMCLK = XT2/1 = 1MHz
// Initalize ports for communication with CC2420 and other peripheral units
PORT_INIT();
SPI_INIT();
// Wait for the user to select node address, and initialize for basic RF operation
halWait(1000);
basicRfInit(&rfRxInfo, RF_CHANNEL, 0x2420, 0x5678);
// Initalize common protocol parameters
rfTxInfo.destAddr = 0x1234;
rfTxInfo.length = PAYLOAD_SIZE;
rfTxInfo.ackRequest = FALSE;
rfTxInfo.pPayload = pTxBuffer;
rfRxInfo.pPayload = pRxBuffer;
basicRfReceiveOn();
//Initialize UART 115200 bod, 8bit, no parity, 2 stop bits.
P3SEL |= 0x30;
ME1 |= UTXE0 + URXE0;
UCTL0 |= CHAR + SPB;
UTCTL0 |= SSEL1;
UBR00 = 0x45; // 8MHz 115200
UBR10 = 0x00; // 8MHz 115200
UMCTL0 = 0x6B; // 8MHz 115200 modulation
UCTL0 &= ~SWRST;
IE1 |= URXIE0;
ENABLE_GLOBAL_INT();
for (;;)
{
/* while (BUTTON_PRESSED)
{
for (int i=1; i<=10000; i++)
{
pTxBuffer[0] = i;
pTxBuffer[1] = 0x01;
basicRfSendPacket(&rfTxInfo);
for (int k=1; k<=50; k++)
{
halWait(5000);
}
TOGGLE_LED1();
}
}
*/
while (bytesCount == NUMBER_OF_BYTES)
{
bytesCount = 0;
basicRfSendPacket(&rfTxInfo);
TOGGLE_LED1();
}
} // for(;;)
} // main
//-------------------------------------------------------------------------------------------------------
// void ledFlash(UINT16 cycles, UINT16 period)
//
// DESCRIPTION:
// Toggles the led 'cycles' times with a half-cycle duration of 'period' uSeconds.
//
// ARGUMENTS:
// UINT16 cycles
// Number of times to toggle the LED
// UINT16 period
// Half-cycle period, i.e the time the LED is on respectively off.
//
//-------------------------------------------------------------------------------------------------------
void ledFlash(UINT16 cycles, UINT16 period)
{
for (int i=0; i < cycles; i++)
{
TOGGLE_LED1();
if (period > 0)
{
halWait(period);
}
}
}
//-------------------------------------------------------------------------------------------------------
// INTERRUPT
//-------------------------------------------------------------------------------------------------------
#pragma vector=UART0RX_VECTOR
__interrupt void usart0_rx (void)
{
pTxBuffer[bytesCount++] = RXBUF0; // 耥圜嚯
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -