- 易迪拓培训,专注于微波、射频、天线设计工程师的培养
CC1101做一对一通讯会莫名其妙进入空闲模式?
CC1101做一对一通讯会莫名其妙进入空闲模式?
用CC1101做一对一通讯,从机定时发送不接收,主机只接收数据;主机长期处在RX状态,在接收到数据后进入IDLE状态并进行校准。现在发现的问题是,在一个不确定的时间(有时是非常长的时间,几小时)后,主机模块会莫名其妙的进入IDLE模式而不是RX模式,这个现象好像和信号强度有关,在信号较弱时容易出现,这是怎么回事?
/*****************************************************************************************/
//CC1100清洗RXFIFO函数
/*****************************************************************************************/
void CC1100_Clear_RXFIFO(void)
{
CC1100_Strobe(CC1100_SIDLE);//进入空闲状态
CC1100_Strobe(CC1100_SCAL); //进行校准
Delay(CAL_TIME); //等待校正完成,等待809us
CC1100_Strobe(CC1100_SFRX); //清除RXFIFO
CC1100_Strobe(CC1100_SFTX); //清除TXFIFO
CC1100_Strobe(CC1100_SRX); //进入接收状态
//注:必须进入空闲状态才可以清洗RXFIFO,否则出错。
}
/*****************************************************************************************/
//CC1100接收数据包函数
/*****************************************************************************************/
//描述:
//接收一个长度可变的数据包 (数据包的第一个字节必须是数据包长度)
//数据包的长度不能超过 RXFIFO 的长度.
//要使用这个函数,PKTCTRL1寄存器中的附加状态字节(APPEND_STATUS)必须被使能.
//一定要在确定有数据包已经被接收到(设定相应的GDO引脚指示接收完成)以后使用此函数。
//首先读取 RXBYTES 寄存器值,确定在 RXFIFO 中的数据长度.
//变量:
// unsigned char *rxBuffer 指向接收数据储存区
// unsigned char length 预期接收数据的长度
//返回值:
//0x80: CRC OK
//0x00: CRC NOT OK (在 RXFIFO 中没有要接收的数据)
unsigned char RFReceivePacket(unsigned char *rxBuffer,unsigned char length)
{
unsigned char status[2];
unsigned char rxfifo_len;
unsigned char rssi_dec;
//rxfifo_len = CC1100_ReadStatus(CC1100_RXBYTES) & CC1100_NUM_RXBYTES;
rxfifo_len = CC1100_ReadStatus(CC1100_RXBYTES);//读出RXFIFO中数据长度包括溢出位
if(rxfifo_len == (length+2))
{
CC1100_ReadBurstReg(CC1100_RXFIFO, rxBuffer, length);//读取接受到的数据并保存
CC1100_ReadBurstReg(CC1100_RXFIFO, status, 2);//读取附加的2个状态字节
rssi_dec = CC1100_ReadStatus(CC1100_RSSI);
if(rssi_dec >= 128)
RSSI_DBM = (int)((int)( rssi_dec - 256) / 2) - RSSI_OFFSET;
else
RSSI_DBM = (rssi_dec / 2) - RSSI_OFFSET;
CC1100_Clear_RXFIFO();//清除RXFIFO
return (unsigned char)(status[CC1100_LQI_RX]&CC1100_CRC_OK);
}
else
{
CC1100_ReadBurstReg(CC1100_RXFIFO, rxBuffer, 1);
CC1100_RXBUF[0] = 0;
CC1100_Clear_RXFIFO();//清除RXFIFO
return 0; //返回错误
}
}
另外,寄存器中AGC_LNA_PRIORITY位该如何设置,对无线新能有何影响?
下面是我的主机设置:
/*****************************************************************************************/
//CC1101初始化
/*****************************************************************************************/
// Chipcon
// Product = CC1101
// Chip version = A (VERSION = 0x04)
// Crystal accuracy = 10 ppm
// X-tal frequency = 26 MHz
// RF output power = 10 dBm
// RX filterbandwidth = 541.666667 kHz
// Deviation = 127 kHz
// Datarate = 249.938965 kBaud
// Modulation = (1) GFSK
// Manchester enable = (0) Manchester disabled
// RF Frequency = 407.399719 MHz
// Channel spacing = 199.951172 kHz
// Channel number = 0
// Optimization = Sensitivity
// Sync mode = (3) 30/32 sync word bits detected
// Format of RX/TX data = (0) Normal mode, use FIFOs for RX and TX
// CRC operation = (1) CRC calculation in TX and CRC check in RX enabled
// Forward Error Correction = (0) FEC disabled
// Length configuration = (1) Variable length packets, packet length configured by the first received byte after sync word.
// Packetlength = 255
// Preamble count = (2) 4 bytes
// Append status = 1
// Address check = (0) No address check
// FIFO autoflush = 0
// Device address = 0
// GDO0 signal selection = ( 6) Asserts when sync word has been sent / received, and de-asserts at the end of the packet
// GDO2 signal selection = (41) CHIP_RDY
unsigned char PATABLE[8] = {0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0};
void WriteRFSettings(void)
{
// Write register settings
CC1100_WriteReg(CC1100_FSCTRL1, 0x0C);//Freq synthesizer control.
//FREQ_IF[4:0] = 0x0C,设置中频频率为304.6875KHZ
CC1100_WriteReg(CC1100_FSCTRL0, 0x00);//Freq synthesizer control.
//FREQOFF[7:0] = 0,设置频率偏移为0
CC1100_WriteReg(CC1100_FREQ2, 0x0F);//Freq control word,high byte.
CC1100_WriteReg(CC1100_FREQ1, 0xAB);//Freq control word,mid byte.
CC1100_WriteReg(CC1100_FREQ0, 0x52);//Freq control word,low byte.
//FREQ[23:0] = 0x0FAB52,设置基频载波频率为407.399719238MHZ
CC1100_WriteReg(CC1100_MDMCFG4, 0x2D);//Modem configuration.
//CHANBW_E[1:0] = 0x00,CHANBW_M[1:0] = 0x02,设置接收器信道滤波带宽为541.666667KHZ
//DRATE_E[3:0] = 0x0D,
CC1100_WriteReg(CC1100_MDMCFG3, 0x3B);//Modem configuration.
//DRATE_M[7:0] = 0x3B,设置通讯数据速率为249.93896484375KBaud
CC1100_WriteReg(CC1100_MDMCFG2, 0x17);//Modem configuration.
//DEM_DCFILT_OFF = 0,使能解调器前的直流阻断滤波器,以提高接收灵敏度
//MOD_FORMAT[2:0] = 001,使用GFSK调制模式
//MANCHESTER_EN = 0,关闭曼彻斯特编码
//SYNC_MODE[2:0] = 0x07,设置30/32同步词汇位被侦测,载波必须超门限
CC1100_WriteReg(CC1100_MDMCFG1, 0xA2);//Modem configuration.
//FEC_EN = 1,开启交错FEC前导向纠错,只支持固定长数据包
//NUM_PREAMBLE[2:0] = 2,设置前导数据为4字节
//CHANSPC_E[1:0] = 2
CC1100_WriteReg(CC1100_MDMCFG0, 0xF8);//Modem configuration.
//CHANSPC_M[7:0] = 0xf8,设置信道间隔为199.951172KHz
CC1100_WriteReg(CC1100_CHANNR, 0x80);//Channel number.128频道是433MHZ频率中心点
CC1100_WriteReg(CC1100_DEVIATN, 0x62);//Modem dev (when FSK mod en)
//DEVIATION_E[2:0] = 6,DEVIATION_M[2:0] = 2,设置FSK调制的频移键控偏移频率为126.953125KHZ
CC1100_WriteReg(CC1100_FREND1, 0xB6);//Front end RX configuration.接收前端设置
//LNA_CURRENT[1:0] = 0x02
//LNA2MIX_CURRENT[1:0] = 0x03
//LOdiv_BUF_CURRENT_RX[1:0] = 0x01
//MIX_CURRENT[1:0] = 0x02,这些数值由SMART RF STUDIO给出,资料上没有给出说明
CC1100_WriteReg(CC1100_FREND0, 0x10);//Front end RX configuration.接收前端设置
//LOdiv_BUF_CURRENT_TX[1:0] = 0x01
//PA_POWER[2:0] = 0,选择使用PATABLE索引0定义的输出功率值
CC1100_WriteReg(CC1100_MCSM2 , 0x07);//MainRadio Cntrl State Machine
//RX_TIME_RSSI = 0
//RX_TIME_QUAL = 0
//RX_TIME[2:0] = 0x07,直到接收完数据包后结束RX状态
CC1100_WriteReg(CC1100_MCSM1 , 0x00);//MainRadio Cntrl State Machine
//CCA_MODE[1:0] = 0x00,关闭CCA
//RXOFF_MODE[1:0] = 0x00,接收完成后进入IDLE空闲状态
//TXOFF_MODE[1:0] = 0x00,发送完成后进入IDLE空闲状态
CC1100_WriteReg(CC1100_MCSM0 , 0x08);//MainRadio Cntrl State Machine
//FS_AUTOCAL[1:0] = 0x00,不进行自动校准,使用手动校准
//PO_TIMEOURT = 0x02
//PIN_CTRL_EN = 0,禁止可选的引脚方式控制无线电
//XOSC_FORCE_ON = 0,在SLEEP模式下关闭XOSC,禁止强制开启
CC1100_WriteReg(CC1100_FOCCFG, 0x1D);//Freq Offset Compensation Config
//0x3D //FOC_BS_CS_GATE = 1, 冻结解调器频率补偿,直到载波感应有效
//FOC_PRE_K[1:0] = 0x03,检测到同步字之前的频率补偿回路增益设置为4K
//FOC_POT_K = 1, 检测到同步字之后的频率补偿回路增益设置为K/2
//FOC_LIMIT[1:0] = 0x01,设置频率补偿算法饱和点为 ±BW_CHAN/8(频道带宽的1/8)
CC1100_WriteReg(CC1100_BSCFG, 0x1C);//Bit synchronization config.
//BS_PRE_K[1:0] = 0x00,在检测到同步字之前使用的时钟恢复反馈回路积分增益为Ki
//BS_PRE_KP[1:0] = 0x01,在检测到同步字之前使用的时钟恢复反馈回路比例增益为2Kp
//BS_POST_KI = 1, 在检测到同步字之后使用的时钟恢复反馈回路积分增益为Ki/2
//BS_POST_KP = 1, 在检测到同步字之后使用的时钟恢复反馈回路比例增益为Kp
//BS_LIMIT[1:0] = 0x00,不进行数据传输速率偏移补偿
CC1100_WriteReg(CC1100_AGCCTRL2,0x47);//AGC control.
//MAX_DVGA_GAIN[1:0] = 0x01,设置DVGA数字可变增益放大器的允许最大增益为The highest gain settings can not be used
//MAX_LNA_GAIN[2:0] = 0x00,设置LNA+LNA2可以使用尽可能最大的增益
//MAGN_TARGET[2:0] = 0x07,设置数字信道滤波器平均振幅为42dB
CC1100_WriteReg(CC1100_AGCCTRL1,0x00);//AGC control.
//AGC_LNA_PRIORITY = 0,增益自动调整先减小LNA2的增益
//CARRIER_SENSE_REL_THR[1:0] = 0x00,禁止载波感应相对变化阀值
//CARRIER_SENSE_ABS_THR[3:0] = 0x00,设置载波感应绝对阀值和MAGN_TARGET值相同,RSSI 绝对阀值在-81db左右
CC1100_WriteReg(CC1100_AGCCTRL0,0xB0);//AGC control.
//HYST_LEVEL[1:0] = 0x02
//WAIT_TIME[1:0] = 0x03,信道滤波器采样32次
//AGC_FREEZE[1:0] = 0x00,时钟进行自动增益调节
//FILTER_LENGHT[1:0] = 0x02,设置从通道滤波器出来的幅度的平均长度为8
CC1100_WriteReg(CC1100_FSCAL3, 0xEA);//Frequency synthesizer calibration.频率校准保存寄存器3
CC1100_WriteReg(CC1100_FSCAL2, 0x2A);//Frequency synthesizer calibration.频率校准保存寄存器2
CC1100_WriteReg(CC1100_FSCAL1, 0x00);//Frequency synthesizer calibration.频率校准保存寄存器1
CC1100_WriteReg(CC1100_FSCAL0, 0x1F);//Frequency synthesizer calibration.频率校准保存寄存器0
CC1100_WriteReg(CC1100_FSTEST, 0x59);//Frequency synthesizer calibration.
CC1100_WriteReg(CC1100_TEST2, 0x88);//Various test settings.
CC1100_WriteReg(CC1100_TEST1, 0x31);//Various test settings.
CC1100_WriteReg(CC1100_TEST0, 0x0B);//Various test settings.
CC1100_WriteReg(CC1100_FIFOTHR, 0x07);// FIFOTHR RXFIFO and TXFIFO thresholds.
CC1100_WriteReg(CC1100_IOCFG2, 0x07);//GDO2 output pin config.当接收到一个数据包,且CRC校验正确时,高电平;当从RX FIFO总读取第一个字节后,低电平。
CC1100_WriteReg(CC1100_IOCFG0, 0x07);//GDO0 output pin config.
CC1100_WriteReg(CC1100_PKTCTRL1,0x0D);//Packet automation control.
//PQT[2:0] = 0x00,前导码质量评估阀值为0
//CRC_AUTOFLUSH = 1,使能CRC错误自动清空RX FIFO
//APPEND_STATUS = 1,自动附加2字节状态量
//ADR_CHK[1:0] = 0x01,地址检查(无广播)
CC1100_WriteReg(CC1100_PKTCTRL0,0x44);//Packet automation control.
//WHITE_DATA = 1,使能数据白化
//PKT_FORMAT[1:0] = 0x00,普通模式,使用RX FIFO和TX FIFO
//CRC_EN = 1,使能TX自动计算CRC,RX自动校验CRC
//LENGTH_CONFIG[1:0] = 0x00,固定长数据包格式
CC1100_WriteReg(CC1100_ADDR, 0x01);//Device address.本机地址
CC1100_WriteReg(CC1100_PKTLEN, 0x04);//Packet length.最大允许接收数据长度为4
CC1100_WriteReg(CC1100_SYNC1, 0xD3);
CC1100_WriteReg(CC1100_SYNC0, 0x82);
CC1100_WriteBurstReg(CC1100_PATABLE, PATABLE, 8);//Write PATABLE,设置发射功率为+10dB
//CC1100_Strobe(CC1100_SIDLE);//进入空闲状态
CC1100_Strobe(CC1100_SCAL); //进行校准
Delay(CAL_TIME); //等待校正完成,等待809us
CC1100_Strobe(CC1100_SRX); //进入接收状态
}
有收到报文吗?或者有没有CRC校验失败?
又看了一下资料,发现了问题来源^_^,应该是CRC校验出错了!然后自动清空了RXFIFO,然后根据寄存器RXOFF_MODE设置进入特定的状态,我现在的设置是接收完毕后进入空闲状态,所以在CRC校验失败后就进入了空闲状态。
但是问题也来了,因为现在的GDO引脚设置并不能发现CRC校验失败这一错误,单片机就无法处理。
是否可以把RXOFF_MODE设置为接收完毕后重新进入接收模式来解决这一问题?