www.pudn.com > CC2420_TRX.rar > rf_blink_led_rx.c


/******************************************************************************************************* 
 *                                                                                                     * 
 *        **********                                                                                   * 
 *       ************                                                                                  * 
 *      ***        ***                                                                                 * 
 *      ***   +++   ***                                                                                * 
 *      ***   + +   ***                                                                                * 
 *      ***   +                                   CHIPCON CC2420DBK EXAMPLES                           * 
 *      ***   + +   ***                  Simple wireless dimmer / RF range tester demo                 * 
 *      ***   +++   ***                                                                                * 
 *      ***        ***                                                                                 * 
 *       ************                                                                                   * 
 *        **********                                                                                   * 
 *                                                                                                     * 
 ******************************************************************************************************* 
 * 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 pair of CC2420DBs running this program will establish a point-to-point RF link on channel 26,     * 
 * using the following node addresses:                                                                 * 
 * - PAN ID: 0x2420 (both nodes)                                                                       * 
 * - Short address:                                                                                    * 
 *		0x1234 if the joystick is moved in any direction at startup                                       * 
 *		0x5678 if the joystick button is pressed down at startup                                             * 
 *                                                                                                     * 
 * Please note that there is no so-called (PAN) coordinator.                                           * 
 *                                                                                                     * 
 * INSTRUCTIONS:                                                                                       * 
 * Data packets containing a 5-byte payload will be transmitted when the pot meter is turned, or S2 is * 
 * held down. The first byte of the payload contains the pot meter value, which is used to control the * 
 * PWM duty cycle on the receiving node. The other bytes are random (never initialized).               * 
 *                                                                                                     * 
 * LED indicators:                                                                                     * 
 *     - Red:    Transmission failed (acknowledgment not received)    PE3                                 * 
 *     - Yellow: Transmission OK (acknowledgment received)            PE4                                 * 
 *     - Orange: Remote controlled dimmer                             PB4															   * 
 *     - Green:  Packet received                                      PB7                                 * 
 ******************************************************************************************************* 
 * Compiler: AVR-GCC                                                                                   * 
 * Target platform: CC2420DB (can easily be ported to other platforms)                                 * 
 ******************************************************************************************************* 
 * Revision history:                                                                                   * 
 * $Log: rf_blink_led.c,v $ 
 * Revision 1.5  2004/07/26 11:18:13  mbr 
 * Changed PANID from 0xDEAD to 0x2420 
 * 
 * Revision 1.4  2004/04/05 08:25:52  mbr 
 * Comments changed in header 
 * 
 * Revision 1.3  2004/03/30 14:58:27  mbr 
 * Release for web 
 * 
 *  
 * 
 *                                                                                                     * 
 * 
 * 
 *******************************************************************************************************/ 
#include  
 
 
//------------------------------------------------------------------------------------------------------- 
// 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]; 
//------------------------------------------------------------------------------------------------------- 
 
 
 
 
//------------------------------------------------------------------------------------------------------- 
//  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) { 
 
    // Adjust the led brightness 
    PWM0_SET_DUTY_CYCLE(pRRI->pPayload[0]); 
 
    // Blink the green LED 
    SET_GLED(); 
    halWait(50000); 
    CLR_GLED();//PB7 
//FASTSPI_STROBE(CC2420_SACK); 
    // Continue using the (one and only) reception structure 
    return pRRI; 
 
} // basicRfReceivePacket 
 
 
 
 
//------------------------------------------------------------------------------------------------------- 
//	void main (void) 
// 
//	DESCRIPTION: 
//		Startup routine and main loop 
//------------------------------------------------------------------------------------------------------- 
int main (void)  
{ 
  //  UINT16 ledDutyCycle, dimmerDifference; 
 UINT8 n; 
//   BYTE spiStatusByte; 
     
    // Initalize ports for communication with CC2420 and other peripheral units 
    Mcu_INIT(); 
	PORT_INIT(); 
    SPI_INIT(); 
SET_GLED(); 
SET_OLED(); 
SET_RLED(); 
SET_YLED(); 
halWait(50000);   
CLR_GLED(); 
CLR_OLED(); 
CLR_YLED(); 
CLR_RLED(); 
    // Initialize PWM0 with a period of CLK/1024 
    PWM0_INIT(TIMER_CLK_DIV1024); 
	 
   // Initialize and enable the ADC for reading the pot meter 
    //ADC_INIT(); 
   // ADC_SET_CHANNEL(ADC_INPUT_0_POT_METER); 
	//ADC_ENABLE(); 
 
    // Wait for the user to select node address, and initialize for basic RF operation 
 
	basicRfInit(&rfRxInfo, 26, 0x2420, 0x0001); 
	rfTxInfo.destAddr = 0x0000;    
	 
 
    // Initalize common protocol parameters 
    rfTxInfo.length = 10; 
    rfTxInfo.ackRequest = TRUE; 
    rfTxInfo.pPayload = pTxBuffer; 
    rfRxInfo.pPayload = pRxBuffer; 
 
    for (n = 0; n < 10; n++)  
	{ 
        pTxBuffer[n] = n; 
    } 
	      
 
	 //Turn on RX mode 
    basicRfReceiveOn(); 
	 
	for(;;);	 
 
	//The main loop: 
	//while (TRUE)  
	//{ 
        // Sample the pot meter value 
        //ADC_SAMPLE_SINGLE(); 
        //ADC_GET_SAMPLE_8(ledDutyCycle); 
		// If the dimmer value has changed by more than 1, then transmit the new value automatically 
		// Transmit also when the S2 button is pressed 
		//dimmerDifference = (ledDutyCycle & 0xFF) - pTxBuffer[0]; 
		//if ((ABS(dimmerDifference) > 2) || (JOYSTICK_CENTER_PRESSED()))  
		//{ 
		    //pTxBuffer[0] = ledDutyCycle; 
    //		if (basicRfSendPacket(&rfTxInfo))  
	//		{ 
    		    // OK -> Blink the yellow LED 
			//    SET_YLED(); 
			//    halWait(50000); 
			//    CLR_YLED();			     
			 //   halWait(50000); 
			 //   SET_YLED(); 
			//	halWait(50000); 
			//	CLR_YLED(); 
	//		}  
	//		else  
	//		{ 
			    // No acknowledgment received -> Blink the red LED 
			//    SET_RLED(); 
			//    halWait(50000); 
			//    CLR_RLED(); 
	//		} 
		//} 
    //} 
return 0; 
} // main