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

📄 cc1100.c

📁 cc1100通讯源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
//*****************************************************************************
//CC1100.C
//*****************************************************************************
#include "intrins.h"
#include "CPU.h"
#include "mydefine.h"
#include "CC1100.H"



//*****************************************************************************
// ConfigCC1100
//*****************************************************************************


///////////////////////////////////////////////////////////////////////////////
unsigned char const PaTabel[8] = {0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0 ,0xC0}; 
//功率配置
///////////////////////////////////////////////////////////////////////////////


//*****************************************************************************
// RF_SETTINGS is a data structure which contains all relevant CCxxx0 registers
typedef struct S_RF_SETTINGS{
	unsigned char FSCTRL2;	
	unsigned char FSCTRL1;   // Frequency synthesizer control.
	unsigned char FSCTRL0;   // Frequency synthesizer control.
	unsigned char FREQ2;     // Frequency control word, high unsigned char.
	unsigned char FREQ1;     // Frequency control word, middle unsigned char.
	unsigned char FREQ0;     // Frequency control word, low unsigned char.
	unsigned char MDMCFG4;   // Modem configuration.
	unsigned char MDMCFG3;   // Modem configuration.
	unsigned char MDMCFG2;   // Modem configuration.
	unsigned char MDMCFG1;   // Modem configuration.
	unsigned char MDMCFG0;   // Modem configuration.
	unsigned char CHANNR;    // Channel number.
	unsigned char DEVIATN;   // Modem deviation setting (when FSK modulation is enabled).
	unsigned char FREND1;    // Front end RX configuration.
	unsigned char FREND0;    // Front end RX configuration.
	unsigned char MCSM0;     // Main Radio Control State Machine configuration.
	unsigned char FOCCFG;    // Frequency Offset Compensation Configuration.
	unsigned char BSCFG;     // Bit synchronization Configuration.
	unsigned char AGCCTRL2;  // AGC control.
	unsigned char AGCCTRL1;  // AGC control.
	unsigned char AGCCTRL0;  // AGC control.
	unsigned char FSCAL3;    // Frequency synthesizer calibration.
	unsigned char FSCAL2;    // Frequency synthesizer calibration.
	unsigned char FSCAL1;    // Frequency synthesizer calibration.
	unsigned char FSCAL0;    // Frequency synthesizer calibration.
	unsigned char FSTEST;    // Frequency synthesizer calibration control
	unsigned char TEST2;     // Various test settings.
	unsigned char TEST1;     // Various test settings.
	unsigned char TEST0;     // Various test settings.
	unsigned char IOCFG2;    // GDO2 output pin configuration
	unsigned char IOCFG0;    // GDO0 output pin configuration
	unsigned char PKTCTRL1;  // Packet automation control.
	unsigned char PKTCTRL0;  // Packet automation control.
	unsigned char ADDR;      // Device address.
	unsigned char PKTLEN;    // Packet length.
} RF_SETTINGS;
//*****************************************************************************


//*****************************************************************************
const RF_SETTINGS rfSettings = {
	0x00,
	0x0B,   // 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.
	0x2D,   // MDMCFG4   Modem configuration.
	0x3B,   // MDMCFG3   Modem configuration.
	0x73,   // MDMCFG2   Modem configuration.
	0x22,   // MDMCFG1   Modem configuration.
	0xF8,   // MDMCFG0   Modem configuration.
	
	0x00,   // CHANNR    Channel number.
	0x00,   // 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.
	0x0A,   // FSCAL2    Frequency synthesizer calibration.
	0x00,   // FSCAL1    Frequency synthesizer calibration.
	0x11,   // FSCAL0    Frequency synthesizer calibration.
	0x59,   // FSTEST    Frequency synthesizer calibration.
	0x88,   // TEST2     Various test settings.
	0x31,   // TEST1     Various test settings.
	0x0B,   // TEST0     Various test settings.
	0x06,   // IOCFG2    GDO2 output pin configuration.
	0x0B,   // 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.
};
//*****************************************************************************

//*****************************************************************************
//函数名:void halWait(unsigned int timeout) 
//功能描述:廷 时 函 数
//*****************************************************************************
void halWait(unsigned int timeout) 
{
    do {
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
		_nop_();
    
    } while (--timeout);
}	
	
	
//*****************************************************************************
//函数名:void RESET_CC1100(void)
//功能描述:复位CC1100
//*****************************************************************************
void RESET_CC1100(void) 
{
	CS_CC1100 = 0; 
	while (GDO2); 
	SpiReadWrite(CCxxx0_SRES); 		//写入复位命令
	while (GDO2); 
	CS_CC1100 = 1; 
}

//*****************************************************************************
//函数名:void POWER_UP_RESET_CC1100(void) 
//功能描述:上电复位CC1100
//*****************************************************************************
void POWER_UP_RESET_CC1100(void) 
{
	CS_CC1100 = 1; 
	halWait(1); 
	CS_CC1100 = 0; 
	halWait(1); 
	CS_CC1100 = 1; 
	halWait(41); 
	RESET_CC1100();   		//复位CC1100
}
//*****************************************************************************
//函数名:void halSpiWriteReg(unsigned char addr, unsigned char value)
//功能描述:SPI写寄存器
//*****************************************************************************
void halSpiWriteReg(unsigned char addr, unsigned char value) 
{
	EA = 0;
	CS_CC1100 = 0;
	while (GDO2);
	SpiReadWrite(addr);		//写地址
	SpiReadWrite(value);		//写入配置
	CS_CC1100 = 1;
	EA = 1;
}

//*****************************************************************************
//函数名:void halSpiWriteBurstReg(unsigned char addr, unsigned char *buffer, unsigned char count)

⌨️ 快捷键说明

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