我用430和si4432做的点对点无线通信,为什么我的程序跑到接收数据模式的时候就跑飞了。下面是我的代码希望高手多多指教。我做了个发送模式的,可以正常发送。但是就是进入接收模式的时候程序跑飞了,
void SI4432_Init(void)
{
//等待软件复位....................//
while (P1IN&BIT6);
ItStatus1 = SI4432_ReadReg(0x03);
ItStatus2 = SI4432_ReadReg(0x04);
//...............................//
/*设置物理传输数据*/
//set the center frequency to 470 MHz
SI4432_WriteReg(0x75,0x57);
SI4432_WriteReg(0x76,0x00);
SI4432_WriteReg(0x77,0x00);
//set the desired TX data rate (9.6kbps)
SI4432_WriteReg(0x6E, 0x4E); //write 0x4E to the TXDataRate 1 register
SI4432_WriteReg(0x6F, 0xA5); //write 0xA5 to the TXDataRate 0 register
SI4432_WriteReg(0x70, 0x2C); //write 0x2C to the Modulation Mode Control 1 register
//set the desired TX deviatioin (+-45 kHz)
SI4432_WriteReg(0x72, 0x48); //write 0x48 to the Frequency Deviation register
//set the TX power to MAX +20dBM
SI4432_WriteReg(0x6D, 0x1F); //write 0x1F to the TX Power register
//set the modem parameters according to the exel calculator(parameters: 9.6 kbps, deviation: 45 kHz, channel filter BW: 112.1 kHz
SI4432_WriteReg(0x1C, 0x05); //write 0×05 to the IF Filter Bandwidth register
SI4432_WriteReg(0x20, 0xA1); //write 0xA1 to the Clock Recovery Oversampling Ratio register
SI4432_WriteReg(0x21, 0x20); //write 0×20 to the Clock Recovery Offset 2 register
SI4432_WriteReg(0x22, 0x4E); //write 0x4E to the Clock Recovery Offset 1 register
SI4432_WriteReg(0x23, 0xA5); //write 0xA5 to the Clock Recovery Offset 0 register
SI4432_WriteReg(0x24, 0x00); //write 0×00 to the Clock Recovery Timing Loop Gain 1 register
SI4432_WriteReg(0x25, 0x13); //write 0×13 to the Clock Recovery Timing Loop Gain 0 register
SI4432_WriteReg(0x1D, 0x40); //write 0×40 to the AFC Loop Gearshift Override register
SI4432_WriteReg(0x72, 0x1F); //write 0x1F to the Frequency Deviation register
/*设置数据包*/
//设置天线分集或者非天线分集//
//#ifdef ANTENNA_DIVERSITY
//SI4432_WriteReg(0x34, 0x14); //write 0x14 to the Preamble Length register
//#else
//SI4432_WriteReg(0x34, 0x0A); //write 0x0A to the Preamble Length register
//#endif
//设置非天线分集
SI4432_WriteReg(0x34, 0x0A);
//设置检测阈值20bits
SI4432_WriteReg(0x35, 0x28); //write 0×28 to the Preamble Detection Control register
/*禁用标头字节可变长度分组;设置(有效载荷的长度的定义是
收到的包长度字段);设置同步字的两个字节长*/
SI4432_WriteReg(0x33, 0x02); //write 0x02 to the Header Control2 register
//设置同步字模式 0x2DD4
SI4432_WriteReg(0x36, 0x2D); //write 0x2D to the Sync Word(同步字) 3 register
SI4432_WriteReg(0x37, 0xD4); //write 0xD4 to the Sync Word(同步字) 2 register
//使能发送数据包的处理程序和CRC-16校验(IBM)
SI4432_WriteReg(0x30, 0x0D); //write 0x0D to the Data Access Control register
//启用FIFO模式和GFSK调制
SI4432_WriteReg(0x71, 0x63); //write 0x63 to the Modulation Mode Control 2 register
//#ifdef ANTENNA_DIVERSITY
//enable the antenna diversity mode
// SI4432_WriteReg(0x08, 0x80); //write 0x80 to the Operating Function Control 2 register
// #endif
/*根据天线类型设置GPIO的*/
//#ifdef ANTENNA_DIVERSITY
// SI4432_WriteReg(0x0B, 0x17); //write 0x17 to the GPIO0 Configuration(set the Antenna 1 Switch used for antenna diversity )
// SI4432_WriteReg(0x0C, 0x18); //write 0x18 to the GPIO1 Configuration(set the Antenna 2 Switch used for antenna diversity )
//#endif
//#ifdef ONE_SMA_WITH_RF_SWITCH
// SI4432_WriteReg(0x0B, 0x12); //write 0x12 to the GPIO0 Configuration(set the TX state)
// SI4432_WriteReg(0x0C, 0x15); //write 0x15 to the GPIO1 Configuration(set the RX state)
//#endif
//非天线分集
SI4432_WriteReg(0x0B, 0x12);
SI4432_WriteReg(0x0C, 0x15);
/*set the non-default(非默认) Si4432 registers*/
//set the VCO and PLL
SI4432_WriteReg(0x5A, 0x7F); //write 0x7F to the VCO Current Trimming register
SI4432_WriteReg(0x58, 0x80); //write 0×80 to the ChargepumpCurrentTrimmingOverride register
SI4432_WriteReg(0x59, 0x40); //write 0×40 to the Divider Current Trimming register
//set the AGC
SI4432_WriteReg(0x6A, 0x0B); //write 0x0B to the AGC Override 2 register
//set ADC reference voltage to 0.9V
SI4432_WriteReg(0x68, 0x04); //write 0x04 to the Deltasigma ADC Tuning 2 register
SI4432_WriteReg(0x1F, 0x03); //write 0x03 to the Clock Recovery Gearshift Override register
/*set Crystal Oscillator Load Capacitance register*/
SI4432_WriteReg(0x09, 0xD7);
}
//***************************************************//
//函数名称: SI4432_SetRxMode(void) //
//函数功能: SI4432接收模式 //
//***************************************************//
void SI4432_SetRxMode(void)
{
ItStatus1=SI4432_ReadReg(0x03);
ItStatus2=SI4432_ReadReg(0x04);
SI4432_WriteReg(0x0E, 0x01);
SI4432_WriteReg(0x07, 0x05); //使能接收连接;
}
就是在使能接收连接的时候跑飞了。我担心是不是初始化出了问题。请各位大侠帮帮忙,小弟不胜感激。 |