GPIOx_Init(GPIOC, BIT5, OUT_PP_10M);
CC1101_SCLK_H();
//初始化MOSI
GPIOx_Init(GPIOC, BIT6, OUT_PP_10M);
CC1101_MOSI_H();
//初始化MISO
GPIOx_Init(GPIOC, BIT7, IN_UP);
CC1101_SCLK_L();
CC1101_MOSI_L();
//初始化GDO0,GDO2对应PC3,PC4
GPIOx_Init(GPIOC, BIT3, IN_UP);
GPIOx_Init(GPIOC, BIT4, IN_UP);
//初始化寄存器
CC1101_Command(CC1101_CMD_SRES); //复位
Delay_MS(10);
while(CC1101_ReadReg(CC1101_REG_AGCTEST) != 0x3F) //检测通信
{
LED_ON();
Delay_MS(10);
LED_OFF();
Delay_MS(100);
}
LED_OFF();
CC1101_WriteReg(CC1101_REG_IOCFG0,0x06); //发送提示引脚
CC1101_WriteReg(CC1101_REG_IOCFG2,0x01); //接收提示引脚
CC1101_WriteReg(CC1101_REG_FIFOTHR,0x0f); //RX FIFO和TX FIFO门限
CC1101_WriteReg(CC1101_REG_SYNC1,0xD3); //同步词汇,高字节
CC1101_WriteReg(CC1101_REG_SYNC0,0x91); //同步词汇,低字节
CC1101_WriteReg(CC1101_REG_PKTLEN,CC1101_DATA_LEN); //数据包长度,255
CC1101_WriteReg(CC1101_REG_PKTCTRL1,0x04); //数据包自动控制
CC1101_WriteReg(CC1101_REG_PKTCTRL0,0x04); //数据包自动控制
CC1101_WriteReg(CC1101_REG_ADDR,0x00); //设备地址
CC1101_WriteReg(CC1101_REG_CHANNR,0x00); //信道
CC1101_WriteReg(CC1101_REG_FSCTRL1,0x06); //频率合成器控制,高字节
CC1101_WriteReg(CC1101_REG_FSCTRL0,0x00); //频率合成器控制,低字节
CC1101_WriteReg(CC1101_REG_FREQ2,0x10); //频率控制词汇,高字节
CC1101_WriteReg(CC1101_REG_FREQ1,0xb1); //频率控制词汇,中间字节
CC1101_WriteReg(CC1101_REG_FREQ0,0x3b); //频率控制词汇,低字节
//2.4KBPS
CC1101_WriteReg(CC1101_REG_MDMCFG4,0xF6); //调制器配置
CC1101_WriteReg(CC1101_REG_MDMCFG3,0x83); //调制器配置
CC1101_WriteReg(CC1101_REG_MDMCFG2,0x13); //调制器配置
CC1101_WriteReg(CC1101_REG_MDMCFG1,0x22); //调制器配置
CC1101_WriteReg(CC1101_REG_MDMCFG0,0xf8); //调制器配置
CC1101_WriteReg(CC1101_REG_DEVIATN,0x15); //调制器背离设置
CC1101_WriteReg(CC1101_REG_MCSM2,0x07); //主通信控制状态机配置 CC1101_WriteReg(CC1101_REG_MCSM1,0x30); //主通信控制状态机配置 (责任编辑:admin) |