⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hal_rf_set_channel.c

📁 基于无线传感器网络的CC2420收发芯片初始化源代码
💻 C
字号:
/*******************************************************************************************************
 *                                                                                                     *
 *        **********                                                                                   *
 *       ************                                                                                  *
 *      ***        ***                                                                                 *
 *      ***   +++   ***                                                                                *
 *      ***   + +   ***                                                                                *
 *      ***   +                        CHIPCON HARDWARE ABSTRACTION LIBRARY FOR THE CC2420             *
 *      ***   + +   ***                             CC2420 channel selection                           *
 *      ***   +++   ***                                                                                *
 *      ***        ***                                                                                 *
 *       ************                                                                                  *
 *        **********                                                                                   *
 *                                                                                                     *
 *******************************************************************************************************
 * The Chipcon Hardware Abstraction Library is a collection of functions, macros and constants, which  *
 * can be used to ease access to the hardware on the CC2420 and the target microcontroller.            *
 *                                                                                                     *
 * This file contains a function that allows you to switch radio channels on the CC2420.               *
 *                                                                                                     *
 * EXAMPLE OF USAGE:                                                                                   *
 *     // Turn off RX...                                                                               *
 *     DISABLE_GLOBAL_INT();                                                                           *
 *     FASTSPI_STROBE(CC2420_SRFOFF);                                                                  *
 *     ENABLE_GLOBAL_INT();                                                                            *
 *                                                                                                     *
 *     // ... switch to the next channel in the loop ...                                               *
 *     halRfSetChannel(channel++);                                                                     *
 *     if (channel == 27) channel = 11;                                                                *
 *                                                                                                     *
 *     // ... and go back into RX                                                                      *
 *     DISABLE_GLOBAL_INT();                                                                           *
 *     FASTSPI_STROBE(CC2420_SRXON);                                                                   *
 *     ENABLE_GLOBAL_INT();                                                                            *
 *******************************************************************************************************
 * Compiler: AVR-GCC                                                                                   *
 * Target platform: CC2420DB, CC2420 + any MCU with very few modifications required                    *
 *******************************************************************************************************
 * Revision history:                                                                                   *
 * $Log: hal_rf_set_channel.c,v $
 * Revision 1.3  2004/03/30 14:59:35  mbr
 * Release for web
 * 
 *
 *
 *
 *******************************************************************************************************/
#include <include.h>




//-------------------------------------------------------------------------------------------------------
//	void halRfSetChannel(UINT8 Channel)
//
//	DESCRIPTION:
//		Programs CC2420 for a given IEEE 802.15.4 channel. 
//		Note that SRXON, STXON or STXONCCA must be run for the new channel selection to take full effect.
//
//	PARAMETERS:
//		UINT8 channel
//			The channel number (11-26)
//-------------------------------------------------------------------------------------------------------
void halRfSetChannel(UINT8 channel) {
	UINT16 f;
	
	// Derive frequency programming from the given channel number
	f = (UINT16) (channel - 11); // Subtract the base channel 
	f = f + (f << 2);    		 // Multiply with 5, which is the channel spacing
	f = f + 357 + 0x4000;		 // 357 is 2405-2048, 0x4000 is LOCK_THR = 1
	
    // Write it to the CC2420
	DISABLE_GLOBAL_INT();
	FASTSPI_SETREG(CC2420_FSCTRL, f);
	ENABLE_GLOBAL_INT();

} // rfSetChannel


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -