搜索
bottom↓
回复: 0

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

[复制链接]

出130入0汤圆

发表于 2014-7-8 18:23:21 | 显示全部楼层 |阅读模式
最近再调试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 Control  register
  
  //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*/
  //set  cap. 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[i] = SI4432_readReg(0x7F);//读取FIFO访问寄存器
    }
    return len;
  }
  else
  {
    return 0xFF;
  }
}


这是我的初始化以及发送接收函数

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-8-25 22:17

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表