TI中文支持网
TI专业的中文技术问题搜集分享网站

CC1101接受信号时,MSP430F149偶尔会内存溢出,导致全局变量数据错乱,请问怎么解决?

程序结构是,CC1101空中唤醒模式,主程序LPM3模式,CC1101接受到信号产生中断1,唤醒MSP430,在主程序中进行信号接受处理,接受完毕后再次休眠,CC1101有在定时器中定时校准频率,现在出现的问题是,大部分时间程序运行很正常,但是在运行几天以后,偶尔在接受信号以后,程序里的全局变量数据错乱,这几个全局变量是写在FLASH中的,发生错乱以后,再从FLASH中重新读出数据,数据是正确的,判断错乱应该是内存溢出导致,请问有没有什么方法可以解决这个溢出问题?

////////////////////////////////////////以下是部分代码

const RF_SETTINGS rfSettings =   /////////////////////////////////////////// CC1101设定
{
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.
//0x07,//PKTCTRL1by sheng 170913增加地址过滤d1-0为11,地址检查和0(0x00)和255(0xFF)广播
0x0f,//PKTCTRL1by sheng 170913增加地址过滤d1-0为11,地址检查和0(0x00)和255(0xFF)广播,2017108增加 CRC过滤d3为1时
0x05, // PKTCTRL0 Packet automation control.
0xf0, // ADDR Device address.//摇控器地址始终为0x01 bysheng20171009
0xff // PKTLEN Packet length.最大
};

void halRfWriteRfSettings(void){
halSpiWriteReg(CCxxx0_FSCTRL0, rfSettings.FSCTRL2);//自已加的
// Write register settings
halSpiWriteReg(CCxxx0_FSCTRL1, rfSettings.FSCTRL1);
halSpiWriteReg(CCxxx0_FSCTRL0, rfSettings.FSCTRL0);
halSpiWriteReg(CCxxx0_FREQ2, rfSettings.FREQ2);
halSpiWriteReg(CCxxx0_FREQ1, rfSettings.FREQ1);
halSpiWriteReg(CCxxx0_FREQ0, rfSettings.FREQ0);
halSpiWriteReg(CCxxx0_MDMCFG4, rfSettings.MDMCFG4);
halSpiWriteReg(CCxxx0_MDMCFG3, rfSettings.MDMCFG3);
halSpiWriteReg(CCxxx0_MDMCFG2, rfSettings.MDMCFG2);
halSpiWriteReg(CCxxx0_MDMCFG1, rfSettings.MDMCFG1);
halSpiWriteReg(CCxxx0_MDMCFG0, rfSettings.MDMCFG0);
halSpiWriteReg(CCxxx0_CHANNR, rfSettings.CHANNR);
halSpiWriteReg(CCxxx0_DEVIATN, rfSettings.DEVIATN);
halSpiWriteReg(CCxxx0_FREND1, rfSettings.FREND1);
halSpiWriteReg(CCxxx0_FREND0, rfSettings.FREND0);
halSpiWriteReg(CCxxx0_MCSM0 , rfSettings.MCSM0 );
halSpiWriteReg(CCxxx0_FOCCFG, rfSettings.FOCCFG);
halSpiWriteReg(CCxxx0_BSCFG, rfSettings.BSCFG);
halSpiWriteReg(CCxxx0_AGCCTRL2, rfSettings.AGCCTRL2);
halSpiWriteReg(CCxxx0_AGCCTRL1, rfSettings.AGCCTRL1);
halSpiWriteReg(CCxxx0_AGCCTRL0, rfSettings.AGCCTRL0);
halSpiWriteReg(CCxxx0_FSCAL3, rfSettings.FSCAL3);
halSpiWriteReg(CCxxx0_FSCAL2, rfSettings.FSCAL2);
halSpiWriteReg(CCxxx0_FSCAL1, rfSettings.FSCAL1);
halSpiWriteReg(CCxxx0_FSCAL0, rfSettings.FSCAL0);
halSpiWriteReg(CCxxx0_FSTEST, rfSettings.FSTEST);
halSpiWriteReg(CCxxx0_TEST2, rfSettings.TEST2);
halSpiWriteReg(CCxxx0_TEST1, rfSettings.TEST1);
halSpiWriteReg(CCxxx0_TEST0, rfSettings.TEST0);
halSpiWriteReg(CCxxx0_IOCFG2, rfSettings.IOCFG2);
halSpiWriteReg(CCxxx0_IOCFG0, rfSettings.IOCFG0); halSpiWriteReg(CCxxx0_PKTCTRL1, rfSettings.PKTCTRL1);
halSpiWriteReg(CCxxx0_PKTCTRL0, rfSettings.PKTCTRL0);
//halSpiWriteReg(CCxxx0_ADDR, rfSettings.ADDR);//by sheng 20171110
halSpiWriteReg(CCxxx0_PKTLEN, rfSettings.PKTLEN);
halSpiWriteReg(CCxxx0_WOREVT1, 0x6F); //高位 0x0f
//halSpiWriteReg(CCxxx0_WOREVT1, 0x6f); //高位 0x0f
halSpiWriteReg(CCxxx0_WOREVT0, 0xc5); //低位,即0X08C5, TEVENT0=0.116 S, 116.3ms halSpiWriteReg(CCxxx0_WORCTRL, 0x48); //RC_PD=0;EVENT1=4;RC_CAL=1;WOR_RES=00;
halSpiWriteReg(CCxxx0_MCSM2, 0x01); //只侦测同步词汇,RX终止定时116.3*12.5%=14.53ms ,//这里没有测RSSI,省电效电差by sheng170916
//halSpiWriteReg(CCxxx0_MCSM2, 0x17); //只侦测同步词汇,RX终止定时116.3*12.5%=14.53ms ,//这里有测RSSI,省电效果好,但试验不行by sheng170921
}

////////////////////////////////////////////////////////////////////////////////////

INT8U halRfReceivePacket(INT8U *rxBuffer, INT8U *length) //                       CC1101接受程序
{
WDTCTL = WDT_ARST_1000;
INT8U status[3];
INT8U packetLength;
INT8U i=leng*4;
halSpiStrobe(CCxxx0_SRX);
// WDTCTL = WDTPW + WDTHOLD;
// halWait(2000);
delay(2); while(P1IN & 0x10)

{

delay(2);

–i;

if(i<1)

return 0;

}
WDTCTL = WDTPW + WDTHOLD;
if ((halSpiReadStatus(CCxxx0_RXBYTES) & BYTES_IN_RXFIFO)) //如果接的字节数不为0
{
packetLength = halSpiReadReg(CCxxx0_RXFIFO);//读出第一个字节,此字节为该帧数据长度
if (packetLength <= *length) //如果所要的有效数据长度小于等于接收到的数据包的长度
{
halSpiReadBurstReg(CCxxx0_RXFIFO, rxBuffer, packetLength); //当第一个字节为节点地址时,读出所有接收到的数据
*length = packetLength; //把接收数据长度的修改为当前数据的长度
if(RxBuf[0]==halSpiReadReg(CCxxx0_ADDR)||RxBuf[0]==0xFF&&RxBuf[2]>=0x02&&RxBuf[2]<=0x20)//by sheng171008读入节点地址 {
halSpiReadBurstReg(CCxxx0_RXFIFO, status, 2); //读出CRC校验位
RSSI_FIFO=status[0];
//RSSI_G=halSpiReadReg(CCxxx0_RSSI);
RSSI_G=status[0];
halSpiStrobe(CCxxx0_SFRX); //清洗接收缓冲区
return (status[1] & CRC_OK); //如果校验成功返回接收成功
}
}
else {
*length = packetLength;
halSpiStrobe(CCxxx0_SFRX); //清洗接收缓冲区
return 0;
}
} else
return 0;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma vector=PORT1_VECTOR// 有无线信号进入中断1,唤醒主程序
__interrupt void Port_1(void)
{
//LPM3_EXIT;//退出LPM3
_DINT();//关总中断 if (P1IFG & BIT4)
{

P1IE &= ~(BIT4);//关P1.4 中断
P1IFG &= ~(BIT4);
RXFlag=1; LPM3_EXIT;
}
_EINT();}

////////////////////////////////////////////////////////////////////////////////////////////////////////////

 if(RXFlag==1)//在main函数while1中进行收信号,接受完以后进入LPM3休眠状态,CC1101设置为空中唤醒模式

{

if( halRfReceivePacket(RxBuf,&leng))
{
if( (RxBuf[2]==0x17 )&&Mode==0)
{ LED1_1;
YLFlg=1;
if(COUNT<10)
{ COUNT=COUNT+1;
}
else
{COUNT=0;}
}

··········

halSpiStrobe(CCxxx0_SIDLE);
halSpiStrobe(CCxxx0_SRX);//进入接收状态
halSpiStrobe(CCxxx0_SWOR);//进入空中唤醒状态
// _EINT();
P1IFG &= ~(BIT4);
P1IE |= BIT4 ; if(Mode==0)
{ __bis_SR_register(LPM3_bits + GIE); } // Enter LPM3 w/interrupt
delay_ms(10);

、、、、、、、、、、、、、

#pragma vector=TIMERB0_VECTOR// 定时计数器B中每一小时校准一次天线
__interrupt void Timer_B (void)
{
_DINT();//关总中断
SIDCount++;
if(SIDCount>=3600)
{
SIDCount=0;
halSpiStrobe(CCxxx0_SIDLE);
halSpiStrobe(CCxxx0_SRX);//进入接收状态
halSpiStrobe(CCxxx0_SWOR);//进入空中唤醒状态
}

/////////////////////////////////////////////

Viki Shi:

数组过大可能会导致内存溢出,你排查一下。另外,MSP430的问题建议发布到如下板块:
e2echina.ti.com/…/

user6109087:

回复 Viki Shi:

INT8Uleng =35;//
INT8UModeChangeFlg=0;
INT8U RxBuf[27]; //改为全局变量
INT8U CC1101_TxBuf[33];
数组设置的应该也不大吧

赞(0)
未经允许不得转载:TI中文支持网 » CC1101接受信号时,MSP430F149偶尔会内存溢出,导致全局变量数据错乱,请问怎么解决?
分享到: 更多 (0)