INT8U TEST0; // Various test settings.
INT8U IOCFG2; // GDO2 output pin configuration INT8U IOCFG0; // GDO0 output pin configuration INT8U PKTCTRL1; // Packet automation control. INT8U PKTCTRL0; // Packet automation control. INT8U ADDR; // Device address. INT8U PKTLEN; // Packet length. } RF_SETTINGS;
///////////////////////////////////////////////////////////////// const RF_SETTINGS rfSettings = { 0x00,
0x08, // FSCTRL1 Frequency synthesizer control. 0x00, // FSCTRL0 Frequency synthesizer control.
0x10, // FREQ2 Frequency control word, high byte. 0xA7, // FREQ1 Frequency control word, middle byte. 0x62, // FREQ0 Frequency control word, low byte. 0x5B, // MDMCFG4 Modem configuration. 0xF8, // MDMCFG3 Modem configuration. 0x03, // MDMCFG2 Modem configuration. 0x22, // MDMCFG1 Modem configuration. 0xF8, // MDMCFG0 Modem configuration. 0x00, // CHANNR Channel number.
0x47, // DEVIATN Modem deviation setting (when FSK modulation is enabled). 0xB6, // FREND1 Front end RX configuration. 0x10, // FREND0 Front end RX configuration.
0x18, // MCSM0 Main Radio Control State Machine configuration. 0x1D, // FOCCFG Frequency Offset Compensation Configuration. 0x1C, // BSCFG Bit synchronization Configuration. 0xC7, // AGCCTRL2 AGC control. 0x00, // AGCCTRL1 AGC control. 0xB2, // AGCCTRL0 AGC control.
0xEA, // FSCAL3 Frequency synthesizer calibration. 0x2A, // FSCAL2 Frequency synthesizer calibration. 0x00, // FSCAL1 Frequency synthesizer calibration. 0x11, // FSCAL0 Frequency synthesizer calibration. 0x59, // FSTEST Frequency synthesizer calibration. 0x81, // TEST2 Various test settings. 0x35, // TEST1 Various test settings. 0x09, // TEST0 Various test settings.
0x0B, // IOCFG2 GDO2 output pin configuration.
0x06, // IOCFG0D GDO0 output pin configuration. Refer to SmartRF?Studio User Manual for detailed pseudo register explanation.
0x04, // PKTCTRL1 Packet automation control.
0x05, // PKTCTRL0 Packet automation control. 0x00, // ADDR Device address. 0x0c // PKTLEN Packet length. };
//*****************************************************************************************
//函数名:delay(unsigned int s) //输入:时间 //输出:无
//功能描述:普通廷时,内部用
//*****************************************************************************************
static void delay(unsigned int s) { unsigned int i; for(i=0; i
void halWait(INT16U timeout) { do {
_nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); } while (--timeout); }
void SpiInit(void) { CSN=0; SCK=0; CSN=1; }
/******************************************************************************
***********
//函数名:CpuInit() //输入:无 //输出:无
//功能描述:SPI初始化程序
/*****************************************************************************************/ void CpuInit(void) { SpiInit(); delay(5000); }
//*****************************************************************************************
//函数名:SpisendByte(INT8U dat) //输入:发送的数据 //输出:无
//功能描述:SPI发送一个字节
//*****************************************************************************************
INT8U SpiTxRxByte(INT8U dat) { INT8U i,temp; temp = 0; SCK = 0; for(i=0; i<8; i++) { if(dat & 0x80) { MOSI = 1; } else MOSI = 0; dat <<= 1; SCK = 1; _nop_(); _nop_(); temp <<= 1; if(MISO)temp++; SCK = 0; _nop_(); _nop_(); }
return temp; }
//*****************************************************************************************
//函数名:void RESET_CC1100(void) //输入:无 //输出:无
//功能描述:复位CC1100
//*****************************************************************************************
void RESET_CC1100(void) { CSN = 0; while (MISO); SpiTxRxByte(CCxxx0_SRES); //写入复位命令 while (MISO); CSN = 1; }
//*****************************************************************************************
//函数名:void POWER_UP_RESET_CC1100(void) //输入:无 //输出:无
//功能描述:上电复位CC1100
//*****************************************************************************************
void POWER_UP_RESET_CC1100(void) { CSN = 1; halWait(1); CSN = 0; halWait(1); CSN = 1; halWait(41); RESET_CC1100(); //复位CC1100 }
//*****************************************************************************************
//函数名:void halSpiWriteReg(INT8U addr, INT8U value) //输入:地址和配置字 //输出:无
//功能描述:SPI写寄存器
//*****************************************************************************************