主楼一区401 发表于 2014-7-8 18:23:21

请教大家SI4432 接收 出错 的问题

最近再调试SI4432,发送端发送8个1,接收端接收到的是1 1 1 0 0 1 1 1,大家有遇到过这个问题吗?
按道理说,能收到数据应该就是对的啊~
//初始化SI4432
void SI4432_init_M(void)//初始化SI4432为:433.5MHz、1200bps、GFSK、11dBm
{
/* ======================================================== *
*                                                Initialize the Si443x ISM chip                                *
* ======================================================== */
//Turn on the radio by pulling down the PWRDN pin
SI4432_SDN_H;
delay_ms(200);
SI4432_SDN_L;
delay_ms(200);

interruptState = SI4432_readReg(0x03);
interruptState = SI4432_readReg(0x04);
//软件复位
SI4432_writeReg(0x07, 0x80);
while ( SI4432_IRQ_IN);
interruptState = SI4432_readReg(0x03);
interruptState = SI4432_readReg(0x04);
while ( !(SI4432_IRQ_IN) );
interruptState = SI4432_readReg(0x03);
interruptState = SI4432_readReg(0x04);

//read interrupt status registers to clear the interrupt flags and release NIRQ pin
interruptState = SI4432_readReg(0x03);                                                                                                        //read the Interrupt Status1 register
interruptState = SI4432_readReg(0x04);                                                                                                        //read the Interrupt Status2 register

/*set the physical parameters*/
//set the center frequency to 915 MHz
//SI4432_writeReg(0x75, 0x75);                                                                                                                        //write 0x75 to the Frequency Band Select register            
//SI4432_writeReg(0x76, 0xBB);                                                                                                                        //write 0xBB to the Nominal Carrier Frequency1 register
//SI4432_writeReg(0x77, 0x80);
//write 0x80 to the Nominal Carrier Frequency0 register

SI4432_writeReg(0x75, 0x53);                                                                                                                        //write 0x75 to the Frequency Band Select register            
SI4432_writeReg(0x76, 0x64);                                                                                                                        //write 0xBB to the Nominal Carrier Frequency1 register
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 data rate (1.2kbps)
SI4432_writeReg(0x2a, 0x14);       
SI4432_writeReg(0x6E, 0x09);                                                                                                                        //write 0x4E to the TXDataRate 1 register
SI4432_writeReg(0x6F, 0xd5);                                                                                                                        //write 0xA5 to the TXDataRate 0 register
SI4432_writeReg(0x70, 0x2C);       
//set the Tx deviation register (+-45kHz)
//SI4432_writeReg(0x72, 0x48);        //(9.6kbps)                                                                                                                //write 0x48 to the Frequency Deviation register
SI4432_writeReg(0x72, 0x38);        //(1.2kbps)       

/*set the modem parameters according to the exel calculator(parameters: 9.6 kbps, deviation: 45 kHz, channel filter BW: 102.2 kHz*/
SI4432_writeReg(0x1C, 0x1b);                                                                                                                        //write 0x1E to the IF Filter Bandwidth register               
SI4432_writeReg(0x20, 0x83);                                                                                                                        //write 0xD0 to the Clock Recovery Oversampling Ratio register               
SI4432_writeReg(0x21, 0xc0);                                                                                                                        //write 0x00 to the Clock Recovery Offset 2 register               
SI4432_writeReg(0x22, 0x13);                                                                                                                        //write 0x9D to the Clock Recovery Offset 1 register               
SI4432_writeReg(0x23, 0xa9);                                                                                                                        //write 0x49 to the Clock Recovery Offset 0 register               
SI4432_writeReg(0x24, 0x00);                                                                                                                        //write 0x00 to the Clock Recovery Timing Loop Gain 1 register               
SI4432_writeReg(0x25, 0x03);                                                                                                                        //write 0x24 to the Clock Recovery Timing Loop Gain 0 register               
SI4432_writeReg(0x1D, 0x40);                                                                                                                        //write 0x40 to the AFC Loop Gearshift Override register               
SI4432_writeReg(0x1E, 0x0A);                                                                                                                        //write 0x0A to the AFC Timing Control register               
SI4432_writeReg(0x2A, 0x14);                                                                                                                        //write 0x20 to the AFC Limiter register               

/*set the packet structure and the modulation type*/
//set the preamble length to 5bytes
SI4432_writeReg(0x34, 0x0A);                                                                                                                        //write 0x0A to the Preamble Length register
//set preamble detection threshold to 20bits
SI4432_writeReg(0x35, 0x2A);                                                                                                                 //write 0x2A to the Preamble Detection Controlregister

//Disable header bytes; set variable packet length (the length of the payload is defined by the
//received packet length field of the packet); set the synch word to two bytes long
SI4432_writeReg(0x33, 0x02);                                                                                                                        //write 0x02 to the Header Control2 register   

//Set the sync word pattern to 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

//enable the TX & RX packet handler and CRC-16 (IBM) check
SI4432_writeReg(0x30, 0x8D);                                                                                                                        //write 0x8D to the Data Access Control register
//Disable the receive header filters
SI4432_writeReg(0x32, 0x00 );                                                                                                                //write 0x00 to the Header Control1 register            
//enable FIFO mode and GFSK modulation
SI4432_writeReg(0x71, 0x63);                                                                                                                        //write 0x63 to the Modulation Mode Control 2 register

/*set the GPIO's according to the RF switch */
//SI4432_writeReg(0x0C, 0x12);                                                                                                                        //write 0x12 to the GPIO1 Configuration(set the TX state)
//SI4432_writeReg(0x0b, 0x15);                                                                                                                        //write 0x15 to the GPIO2 Configuration(set the RX state)
SI4432_writeReg(0x0C, 0x15);                                                                                                                        //write 0x15 to the GPIO1 Configuration(set the rX state)
SI4432_writeReg(0x0b, 0x12);                                                                                                                        //write 0x12 to the GPIO0Configuration(set the tX state)

/*set the non-default Si443x registers*/
//setcap. bank
SI4432_writeReg(0x09, 0xD7);                                                                                                                        //write 0xD7 to the Crystal Oscillator Load Capacitance register
// Set AGC Override1 Register
SI4432_writeReg(0x69, 0x60);                                                                                                                        //write 0x60 to the AGC Override1 register       

//set tx power 20dbm max
//SI4432_writeReg(0x6d, 0x1f);       
SI4432_writeReg(0x6d, 0x1e);       

/*enable receiver chain*/
SI4432_writeReg(0x07, 0x05);                                                                                                                        //write 0x05 to the Operating Function Control 1 register
//Enable two interrupts:
// a) one which shows that a valid packet received: 'ipkval'
// b) second shows if the packet received with incorrect CRC: 'icrcerror'
SI4432_writeReg(0x05, 0x03);                                                                                                                 //write 0x03 to the Interrupt Enable 1 register
SI4432_writeReg(0x06, 0x00);                                                                                                                 //write 0x00 to the Interrupt Enable 2 register
//read interrupt status registers to release all pending interrupts
interruptState = SI4432_readReg(0x03);                                                                                                        //read the Interrupt Status1 register
interruptState = SI4432_readReg(0x04);                                                                                                        //read the Interrupt Status2 register
//while((key1)&&(key2))
//{
/*enable receiver chain*/          
SI4432_writeReg(0x07, 0x05);       

SI4432_writeReg(0x0d, 0xf4);       

}//end of init

void sending()
{
unsigned long delay =0;
SI4432_writeReg(0x07, 0x01);                                                                                                        //write 0x01 to the Operating Function Control 1 register                       

                                                                                                                                               
/*SET THE CONTENT OF THE PACKET*/
//set the length of the payload to 8bytes       
SI4432_writeReg(0x3E, 8);                                                                                                                //write 8 to the Transmit Packet Length register               
//fill the payload into the transmit FIFO
SI4432_writeReg(0x7F, 1);                                                                                                        //write 0x42 ('B') to the FIFO Access register       
SI4432_writeReg(0x7F, 1);                                                                                                        //write 0x55 ('U') to the FIFO Access register       
SI4432_writeReg(0x7F, 1);                                                                                                        //write 0x54 ('T') to the FIFO Access register       
SI4432_writeReg(0x7F, 1);                                                                                                        //write 0x54 ('T') to the FIFO Access register       
SI4432_writeReg(0x7F, 1);                                                                                                        //write 0x4F ('O') to the FIFO Access register       
SI4432_writeReg(0x7F, 1);                                                                                                        //write 0x4E ('N') to the FIFO Access register       
SI4432_writeReg(0x7F, 1);                                                                                                        //write 0x31 ('1') to the FIFO Access register       
SI4432_writeReg(0x7F, 1);                                                                                                        //write 0x0D (CR) to the FIFO Access register       

//Disable all other interrupts and enable the packet sent interrupt only.
//This will be used for indicating the successfull packet transmission for the MCU
SI4432_writeReg(0x05, 0x04);                                                                                                        //write 0x04 to the Interrupt Enable 1 register       
SI4432_writeReg(0x06, 0x00);                                                                                                        //write 0x03 to the Interrupt Enable 2 register       
//Read interrupt status regsiters. It clear all pending interrupts and the nIRQ pin goes back to high.
interruptState = SI4432_readReg(0x03);                                                                                        //read the Interrupt Status1 register
interruptState = SI4432_readReg(0x04);                                                                                        //read the Interrupt Status2 register

/*enable transmitter*/
//The radio forms the packet and send it automatically.
SI4432_writeReg(0x07, 0x09);                                                                                                        //write 0x09 to the Operating Function Control 1 register

/*wait for the packet sent interrupt*/
//The MCU just needs to wait for the 'ipksent' interrupt.
//read interrupt status registers to release the interrupt flags
interruptState = SI4432_readReg(0x03);                                                                                        //read the Interrupt Status1 register
interruptState = SI4432_readReg(0x04);                                                                                        //read the Interrupt Status2 register

//wait a bit for showing the LED a bit longer
for(delay = 0; delay < 10000;delay++);
//for(delay = 0; delay < 60000;delay++);
//turn off the LED

//after packet transmission set the interrupt enable bits according receiving mode
//Enable two interrupts:
// a) one which shows that a valid packet received: 'ipkval'
// b) second shows if the packet received with incorrect CRC: 'icrcerror'
SI4432_writeReg(0x05, 0x03);                                                                                                 //write 0x03 to the Interrupt Enable 1 register
SI4432_writeReg(0x06, 0x00);                                                                                                 //write 0x00 to the Interrupt Enable 2 register
//read interrupt status registers to release all pending interrupts
interruptState = SI4432_readReg(0x03);                                                                                        //read the Interrupt Status1 register
interruptState = SI4432_readReg(0x04);                                                                                        //read the Interrupt Status2 register

/*enable receiver chain again*/
// SI4432_writeReg(0x07, 0x05);          
}

unsigned char getPkt(void)//将受到的数据放到si4432RxBuf
{
unsigned char len;
unsigned char i;
len = SI4432_readReg(0x4B);// 读取接收到的数据帧长度
   interruptState = SI4432_readReg(0x03);                                                                                        //read the Interrupt Status1 register
interruptState = SI4432_readReg(0x04);       
if (len < 12)//检查以确保数据帧长度小于缓冲长度//现在是11字节有效数据
{
    for (i=0;i < len;i++)//从RX FIFO获取数据帧
    {
      si4432RxBuf = SI4432_readReg(0x7F);//读取FIFO访问寄存器
    }
    return len;
}
else
{
    return 0xFF;
}
}


这是我的初始化以及发送接收函数
页: [1]
查看完整版本: 请教大家SI4432 接收 出错 的问题