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

📄 hh_basic_rf_init.c

📁 zigbee中心节点源代码
💻 C
字号:

#include "include.h"

void basicRfReceiveOn(void) {
	FASTSPI_STROBE(CC2420_SRXON);
	FASTSPI_STROBE(CC2420_SFLUSHRX);
	FIFOP_INT_INIT();
        ENABLE_FIFOP_INT();
} // basicRfReceiveOn

void basicRfReceiveOff(void) {
	FASTSPI_STROBE(CC2420_SRFOFF);
        DISABLE_FIFOP_INT();
} // basicRfReceiveOff

void basicRfInit(UINT8 channel, WORD panId, WORD shortAddr) {
    UINT8 n;

    // Make sure that the voltage regulator is on, and that the reset pin is inactive
    SET_VREG_ACTIVE();//p1.4 out
    halWait(2000);
    SET_RESET_ACTIVE();//p1.5 out
    halWait(2000);
    SET_RESET_INACTIVE();
    halWait(1000);
    
    // Initialize the FIFOP external interrupt
    // FIFOP_INT_INIT();
    // ENABLE_FIFOP_INT();

    // Turn off all interrupts while we're accessing the CC2420 registers
    DISABLE_GLOBAL_INT();//_DINT

    // Register modifications
    FASTSPI_STROBE(CC2420_SXOSCON);          // Turn on the crystal oscillator
    FASTSPI_SETREG(CC2420_MDMCTRL0, 0x1AE2); // Turn on adr_decode, autocrc, autoack, is a pan coordinator
   // FASTSPI_SETREG(CC2420_MDMCTRL0, 0x1AF2); // Turn on adr_decode, autocrc, autoack, is a device
    //FASTSPI_SETREG(CC2420_MDMCTRL0, 0x0AB2);
    
      // PREFESSOR HUANG--------------------
     FASTSPI_SETREG(CC2420_TXCTRL, 0xA0FF);
     FASTSPI_SETREG(CC2420_RXCTRL1, 0x2A56);
	//--------------------------------- 
     FASTSPI_SETREG(0x20, 0x7A94);
    
    
    
    //FASTSPI_SETREG(CC2420_MDMCTRL0, 0x0A72);
    FASTSPI_SETREG(CC2420_RSSI, 0xF0E7);//-16   -25 ?
    
    FASTSPI_SETREG(CC2420_MDMCTRL1, 0x0500); // Set demodulator correlation threshold = 20, buffered mode (use TX/RXFIFO), IEEE 802.15.4 compliant RF modulation mode for RX/TX
    FASTSPI_SETREG(CC2420_IOCFG0, 0x007F);   // Set the FIFOP threshold to maximum
    FASTSPI_SETREG(CC2420_SECCTRL0, 0x01C4); // Turn off security mode
    
    // Set the RF channel
    halRfSetChannel(channel);
    ENABLE_GLOBAL_INT();
    
   // Wait for the crystal oscillator to become stable
    halRfWaitForCrystalOscillator();    
    
    // Write the short address and the PAN ID to the CC2420 RAM (requires that the XOSC is on and stable)
    DISABLE_GLOBAL_INT();
    FASTSPI_WRITE_RAM_LE(&shortAddr, CC2420RAM_SHORTADDR, 2, n);
    FASTSPI_WRITE_RAM_LE(&panId, CC2420RAM_PANID, 2, n);
    ENABLE_GLOBAL_INT();
    
    /*
    UINT16 aaa=CC2420RAM_PANID;
    UINT8 xxx,yyy,zzz;
    SPI_ENABLE();
    FASTSPI_TX(0x80 | (aaa & 0x7F));
    FASTSPI_TX((aaa >> 1) & 0xC0);
    FASTSPI_RX(xxx);
    FASTSPI_RX(yyy);
    zzz=xxx&yyy;
    SPI_DISABLE();
    */    


} // basicRfInit

⌨️ 快捷键说明

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