搜索
bottom↓
回复: 11

Si4432的04H寄存器的问题

[复制链接]

出0入0汤圆

发表于 2010-7-22 20:56:54 | 显示全部楼层 |阅读模式
rt

我的发射确定应该是没问题的

使用FIFO模式,09H也配置好了

接收也调好了

每次接收上电04H的值均为12

查手册   超过RSSI接收门限   

ichiprdy  芯片预备XTAL

当发射端一旦上电 04H的值迅速恢复为00

然后03H一点反应都没有

接收不到数据~~~

请各位高手指点下

多谢

出0入0汤圆

 楼主| 发表于 2010-7-23 23:12:58 | 显示全部楼层
小垃圾,51 的,大侠绕道,菜鸟无视,小白可看。ourdev_570341.rar(文件大小:139K) (原文件名:最新版本.rar)

搞定,自己做个标记~~~

明天上正式程序~~~

出0入0汤圆

发表于 2010-7-30 09:47:33 | 显示全部楼层
楼主是美女吗?
还是说你喜欢美女?

我也正在看si4432,期待你的代码

出0入0汤圆

 楼主| 发表于 2010-8-1 16:46:17 | 显示全部楼层
偶爷们

还有人要我的代码

先说前面

看了不许吐

Keil编译,MCU 51

#include "at89x52.h"       
#include "si4432.h"       
#include "string.h"       


       
U8 sss,fff,ccc,ddd;

//f发射,s ACK,c CRC,d



void WriteDataLCM(unsigned char WDLCM);
void WriteCommandLCM(unsigned char WCLCM,BuysC);
unsigned char ReadDataLCM(void);
unsigned char ReadStatusLCM(void);
void LCMInit(void);
void LCD_cls(void);
void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData);
void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData);
void Delay5Ms(void);
void Delay400Ms(void);
void jc(q,w,d);


void delay(unsigned char delaytime);
void SpiRfWrite8Bit(unsigned char byte);
unsigned char SpiRfRead8Bit(void);
void SpiWriteRegister(unsigned char add, unsigned char reg);
unsigned char SpiReadRegister(unsigned char add);
void RF_init(void);
void RFSetRxMode(void);
void RFSetTxMode(void);
void RFSetIdleMode(void);
void RFFIFOSendData(U8 length, U8 *payload);
void RFWriteFIFO(U8 length, U8 *payload);
void RFSendOutData(void);
void RFResetRxFIFO(void);
void RFResetTxFIFO(void);
unsigned char wendu();
unsigned char jieshou();


void RFIN(void)
{
        U8 ItStatus1,ItStatus2;
        U16 delay;
        U8 temp8;
                                               
        //Turn on the radio by pulling down the PWRDN pin
        SDN = 0;
        //Wait at least 15ms befory any initialization SPI commands are sent to the radio
        // (wait for the power on reset sequence)
        for (temp8=0;temp8<15;temp8++)
        {
                for(delay=0;delay<10000;delay++);
        }         

        LCMInit();
        LCD_cls();


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

        //SW reset   
           SpiWriteRegister(0x07, 0x80);                                                                                                                //write 0x80 to the Operating & Function Control1 register
        //wait for chip ready interrupt from the radio (while the nIRQ pin is high)
        while ( NIRQ == 1);  
        //read interrupt status registers to clear the interrupt flags and release NIRQ pinzigbee
        ItStatus1 = SpiReadRegister(0x03);                                                                                                        //read the Interrupt Status1 register
        ItStatus2 = SpiReadRegister(0x04);                                                                                                        //read the Interrupt Status2 register
                                               
                                                        /*set the physical parameters*/
        //set the center frequency to 915 MHz
        SpiWriteRegister(0x75, 0x53);                                                                                                                        //write data to the Frequency Band Select register            
        SpiWriteRegister(0x76, 0x4B);                                                                                                                        //write data to the Nominal Carrier Frequency1 register
        SpiWriteRegister(0x77, 0x00);                                                                                                                          //write data to the Nominal Carrier Frequency0 register
        //发射频率

        SpiWriteRegister(0x6D, 0x1F);                                                                                                                        //write 0x1F to the TX Power register
        //发射功率
                                               
        SpiWriteRegister(0x34, 0x0C);//0x0C                                                                                                                //write 0x14 to the Preamble Length register        
        //前导码长度

        //set preamble detection threshold to 20bits
        SpiWriteRegister(0x35, 0x2A);
        //xxxxx 处理半字节数  5  xxx允许不连续错误数        2       
        //00101  010                                                                                                        //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
        SpiWriteRegister(0x33, 0x02);//0x02       
        //帧头控制2
        //同步字 2 和 3                                                                                                                //write 0x02 to the Header Control2 register   
       
        //Set the sync word pattern to 0x2DD4
        SpiWriteRegister(0x36, 0x2D);                                                                                                                        //write 0x2D to the Sync Word 3 register
        SpiWriteRegister(0x37, 0xD4);
        //同步字2 和 3
        //36H同步字3为2D,37H同步字为D4                                                                                                                         //write 0xD4 to the Sync Word 2 register

        //enable the TX & RX packet handler and CRC-16 (IBM) check
        SpiWriteRegister(0x30, 0x8D);//0x8D       
        //数据存数控制
        //使能数据包FIFO的发射与接收的的自动处理
        //使能CRC并设置为16位CRC                                        ///////重大配置!!!!!!////////                                                                        //write 0x8D to the Data Access Control register
        //Disable the receive header filters
           SpiWriteRegister(0x32, 0x00 );                                                                                                                        //write 0x00 to the Header Control1 register            
        //帧头控制1
        //无广播地址,没有接收到帧头检测
        //enable FIFO mode and GFSK modulation
        SpiWriteRegister(0x71, 0x63);//0x63                                                                                                                        //write 0x63 to the Modulation Mode Control 2 register
        //FIFO模式,GFSK                                                                                       

           SpiWriteRegister(0x0B, 0xCA);                                                                                                                        //Set GPIO0 output
           SpiWriteRegister(0x0C, 0xCA);                                                                                                                        //Set GPIO1 output
           SpiWriteRegister(0x0D, 0xCA);                                                                                                                        //Set GPIO2 output
        //3个GPIO配置成直接数字输出
        //Set Crystal Oscillator Load Capacitance register, the user should change the value of this register while use different crystal.
        SpiWriteRegister(0x09, 0xB8);
        //晶体谐振电容,厂家给出0xB8

                SpiWriteRegister(0x6E, 0x09);                                                                                                                        //write data to the TXDataRate 1 register
                SpiWriteRegister(0x6F, 0xD5);                                                                                                                        //write data to the TXDataRate 0 register
                //发射波特率       
                SpiWriteRegister(0x58, 0x80);
                //默认电荷泵对PLL的修正,芯片默认                                                       //set the Tx deviation register (+-20kHz)
                SpiWriteRegister(0x72, 0x20);                                                                                                                        //write data to the Frequency Deviation register
                //频偏
                SpiWriteRegister(0x70, 0x2C);//0x2C                                                                                                                        //write data to the Modulation Mode Control 1 register
                //曼彻斯特反演???????????????????
                                                                        /*set the modem parameters according to the exel calculator(parameters: 1.2 kbps, deviation: 20 kHz*/
                SpiWriteRegister(0x1C, 0x2C);                                                                                                                        //write data to the IF Filter Bandwidth register               
                //IF滤波器带宽
                SpiWriteRegister(0x20, 0x41);//0x41                                                                                                                        //write data to the Clock Recovery Oversampling Ratio register               
                //时钟恢复过抽采样
                SpiWriteRegister(0x21, 0x60);                                                                                                                        //write data to the Clock Recovery Offset 2 register               
                //时钟恢复偏差2
                SpiWriteRegister(0x22, 0x27);                                                                                                                        //write data to the Clock Recovery Offset 1 register               
                //时钟恢复偏差1
                SpiWriteRegister(0x23, 0x52);                                                                                                                        //write data to the Clock Recovery Offset 0 register               
                //时钟恢复偏差0
                SpiWriteRegister(0x24, 0x00);                                                                                                                        //write data to the Clock Recovery Timing Loop Gain 1 register               
                //时钟恢复定时循环增益1
                SpiWriteRegister(0x25, 0x04);                                                                                                                        //write data to the Clock Recovery Timing Loop Gain 0 register               
                //时钟恢复定时循环增益0
                SpiWriteRegister(0x1D, 0x40);                                                                                                                        //write data to the AFC Loop Gearshift Override register               
                //AFC循环变速加速  仅AFC使能
                SpiWriteRegister(0x1E, 0x0A);
                //AFC定时
                SpiWriteRegister(0x2A, 0x0F);                                                                                                                        //write data to the AFC Limiter register               
                //AFC显幅
                SpiWriteRegister(0x1F, 0x03);
                //时钟恢复变速超速    时钟恢复慢变速值
                SpiWriteRegister(0x69, 0x60);
                //自动增益 (AGC)

                                                                                        /*enable receiver chain*/
        RFSetRxMode();                                                                                                                        //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'
        SpiWriteRegister(0x05, 0x03);                                                                                                                 //write 0x03 to the Interrupt Enable 1 register
        SpiWriteRegister(0x06, 0x00);                                                                                                                 //write 0x00 to the Interrupt Enable 2 register
        //read interrupt status registers to release all pending interrupts
        ItStatus1 = SpiReadRegister(0x03);                                                                                                        //read the Interrupt Status1 register
        ItStatus2 = SpiReadRegister(0x04);                                                                                                        //read the Interrupt Status2 register

        /*MAIN Loop*/

         DisplayListChar(0,3,"RX + TX");

}

void main(void)
{
       
        U8 ItStatus1,ItStatus2;
        U16 delay;
        U8 length,temp8;
        U8 payload[10];


    RFIN();


while(1)
        {
                //Poll the port pins of the MCU to figure out whether the push button is pressed or not
                if(PB == 0)
                {       
                        //Wait for releasing the push button
                        while( PB == 0 );
                        //disable the receiver chain (but keep the XTAL running to have shorter TX on time!)
                        RFSetIdleMode();                                                                                                //write 0x01 to the Operating Function Control 1 register                       

                        //turn on the LED to show the packet transmission
                        //TX_LED = 1;                                                                                                                                                        
                        //The Tx deviation register has to set according to the deviation before every transmission (+-45kHz)
                        SpiWriteRegister(0x72, 0x20);                                                                                                //write 0x48 to the Frequency Deviation register
                        /*SET THE CONTENT OF THE PACKET*/
                        //set the length of the payload to 8bytes       
                        SpiWriteRegister(0x3E, 8);                                                                                                        //write 8 to the Transmit Packet Length register               
                        //fill the payload into the transmit FIFO
                        SpiWriteRegister(0x7F, 0x42);                                                                                                //write 0x42 ('B') to the FIFO Access register       
                        SpiWriteRegister(0x7F, 0x55);                                                                                                //write 0x55 ('U') to the FIFO Access register       
                        SpiWriteRegister(0x7F, 0x54);                                                                                                //write 0x54 ('T') to the FIFO Access register       
                        SpiWriteRegister(0x7F, 0x54);                                                                                                //write 0x54 ('T') to the FIFO Access register       
                        SpiWriteRegister(0x7F, 0x4F);                                                                                                //write 0x4F ('O') to the FIFO Access register       
                        SpiWriteRegister(0x7F, 0x4E);                                                                                                //write 0x4E ('N') to the FIFO Access register       
                        SpiWriteRegister(0x7F, 0x31);                                                                                                //write 0x31 ('1') to the FIFO Access register       
                        SpiWriteRegister(0x7F, 0x0D);                                                                                                //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
                        SpiWriteRegister(0x05, 0x04);                                                                                                //write 0x04 to the Interrupt Enable 1 register       
                        SpiWriteRegister(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.
                        ItStatus1 = SpiReadRegister(0x03);                                                                                        //read the Interrupt Status1 register
                        ItStatus2 = SpiReadRegister(0x04);                                                                                        //read the Interrupt Status2 register

                        /*enable transmitter*/
                        //The radio forms the packet and send it automatically.
                        RFSetTxMode();                                                                                                //write 0x09 to the Operating Function Control 1 register
                        DisplayListChar(0,0,"TX Transmit");
                        jc(13,0,++fff);
                        /*wait for the packet sent interrupt*/
                        //The MCU just needs to wait for the 'ipksent' interrupt.
                        while(NIRQ == 1);
                        //read interrupt status registers to release the interrupt flags
                        ItStatus1 = SpiReadRegister(0x03);                                                                                        //read the Interrupt Status1 register
                        ItStatus2 = SpiReadRegister(0x04);                                                                                        //read the Interrupt Status2 register

                        //wait a bit for showing the LED a bit longer
                        for(delay = 0; delay < 10000;delay++);
                        //turn off the LED
                        //TX_LED = 0;
                       
                        //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'
                        SpiWriteRegister(0x05, 0x03);                                                                                                 //write 0x03 to the Interrupt Enable 1 register
                        SpiWriteRegister(0x06, 0x00);                                                                                                 //write 0x00 to the Interrupt Enable 2 register
                        //read interrupt status registers to release all pending interrupts
                        ItStatus1 = SpiReadRegister(0x03);                                                                                        //read the Interrupt Status1 register
                        ItStatus2 = SpiReadRegister(0x04);                                                                                        //read the Interrupt Status2 register
                        //set the Frequency Deviation register according to the AFC limiter                                                                                               
                        //SpiWriteRegister(0x72, 0x1F);                                                                                                //write 0x1F to the Frequency Deviation register               

                        /*enable receiver chain again*/
                        RFSetRxMode();                                                                                                //write 0x05 to the Operating Function Control 1 register                               
                }

               
            //wait for the interrupt event
                //If it occurs, then it means a packet received or CRC error happened
                if( NIRQ == 0 )
                {
                        //disable the receiver chain
                        SpiWriteRegister(0x07, 0x01);                                                                                                //write 0x01 to the Operating Function Control 1 register
                        //read interrupt status registers
                        ItStatus1 = SpiReadRegister(0x03);                                                                                        //read the Interrupt Status1 register
                        ItStatus2 = SpiReadRegister(0x04);                                                                                        //read the Interrupt Status2 register

                        /*CRC Error interrupt occured*/
                        if( (ItStatus1 & 0x01) == 0x01 )
                        {
                                DisplayListChar(0,1,"CRC Error");
                                jc(10,1,++ccc);
                                //reset the RX FIFO
                                  SpiWriteRegister(0x08, 0x02);                                                                                        //write 0x02 to the Operating Function Control 2 register
                    SpiWriteRegister(0x08, 0x00);                                                                                        //write 0x00 to the Operating Function Control 2 register
                                //blink all LEDs to show the error
               
                                for(delay = 0; delay < 10000;delay++);
                       
                        }

                        /*packet received interrupt occured*/
                        if( (ItStatus1 & 0x02) == 0x02 )
                        {
                                //Read the length of the received payload
                                length = SpiReadRegister(0x4B);                                                                                        //read the Received Packet Length register
                                //check whether the received payload is not longer than the allocated buffer in the MCU
                                if(length < 11)
                                {
                                        //Get the reeived payload from the RX FIFO
                                        for(temp8=0;temp8 < length;temp8++)
                                        {
                                                payload[temp8] = SpiReadRegister(0x7F);                                                        //read the FIFO Access register
                                        }
                       
                                        //check whether the acknowledgement packet received
                                        if( length == 4 )
                            {
                                    if( memcmp(&payload[0], "ACK", 3) == 0 )
                                                   {
                                          //blink LED2 to show that ACK received
                                                     DisplayListChar(0,2,"ACK OK");
                                                        jc(7,2,++sss);
                                                        for(delay = 0; delay < 10000;delay++);
                                                            
                                                }
                                        }

                                        //check whether an expected packet received, this should be acknowledged
                                        if( length == 8 )
                            {
                                    if( memcmp(&payload[0], "BUTTON1", 7) == 0 )
                                                   {
                                                        DisplayListChar(10,2,"DATA OK");
                                                        jc(18,2,++ddd);
                                          //blink LED2 to show that the packet received
                                                      //RX_LED = 1;
                                                        for(delay = 0; delay < 10000;delay++);
                                                             //RX_LED = 0;

                                                        /*send back an acknowledgement*/
                                                        //turn on LED1 to show packet transmission
                                                        //TX_LED = 1;                                
                                                        //The Tx deviation register has to set according to the deviation before every transmission (+-45kHz)
                                                        SpiWriteRegister(0x72, 0x20);                                                                //write 0x48 to the Frequency Deviation register
                                                        /*set packet content*/
                                                        //set the length of the payload to 4bytes       
                                                        SpiWriteRegister(0x3E, 4);                                                                        //write 4 to the Transmit Packet Length register               
                                                        //fill the payload into the transmit FIFO
                                                        SpiWriteRegister(0x7F, 0x41);                                                                //write 0x42 ('A') to the FIFO Access register       
                                                        SpiWriteRegister(0x7F, 0x43);                                                                //write 0x55 ('C') to the FIFO Access register       
                                                        SpiWriteRegister(0x7F, 0x4B);                                                                //write 0x54 ('K') to the FIFO Access register       
                                                        SpiWriteRegister(0x7F, 0x0D);                                                                //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
                                                        SpiWriteRegister(0x05, 0x04);                                                                //write 0x04 to the Interrupt Enable 1 register       
                                                        SpiWriteRegister(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.
                                                        ItStatus1 = SpiReadRegister(0x03);                                                        //read the Interrupt Status1 register
                                                        ItStatus2 = SpiReadRegister(0x04);                                                        //read the Interrupt Status2 register

                                                        /*enable transmitter*/
                                                        //The radio forms the packet and send it automatically.
                                                        RFSetTxMode();                                                        //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.
                                                        while(NIRQ == 1);
                                                        //read interrupt status registers to release the interrupt flags
                                                        ItStatus1 = SpiReadRegister(0x03);                                                        //read the Interrupt Status1 register
                                                        ItStatus2 = SpiReadRegister(0x04);                                                        //read the Interrupt Status2 register

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

                                                        //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'
                                                        SpiWriteRegister(0x05, 0x03);                                                                 //write 0x03 to the Interrupt Enable 1 register
                                                        SpiWriteRegister(0x06, 0x00);                                                                 //write 0x00 to the Interrupt Enable 2 register
                                                        //read interrupt status registers to release all pending interrupts
                                                        ItStatus1 = SpiReadRegister(0x03);                                                        //read the Interrupt Status1 register
                                                        ItStatus2 = SpiReadRegister(0x04);                                                        //read the Interrupt Status2 register
                                                        //set the Frequency Deviation register according to the AFC limiter                                                                                               
                                                        //SpiWriteRegister(0x72, 0x1F);                                                                //write 0x1F to the Frequency Deviation register               
                                                }
                                        }
                                }
                       }
                        /*enable receiver chain again*/
                        RFSetRxMode();                                                                                                //write 0x05 to the Operating Function Control 1 register
                }        
        }



}

出0入0汤圆

 楼主| 发表于 2010-8-6 15:53:09 | 显示全部楼层
点击此处下载 ourdev_573282.rar(文件大小:77K) (原文件名:72H20RX+TX通调03.rar)


51+Si4432

4楼到1楼斜对收发摆好天线,成功率100%

50多m平方+4楼高平方  的开方 =  距离

出0入0汤圆

发表于 2010-8-7 10:08:49 | 显示全部楼层
还是个高数天才!
因为大家(我)不知道“50多m平方+4楼高平方  的开方 =  距离 ”  怎么算!

出0入0汤圆

 楼主| 发表于 2010-8-8 13:30:49 | 显示全部楼层
这勾股定理嘛

~~~~~

出0入0汤圆

发表于 2010-12-22 18:04:44 | 显示全部楼层
回复【3楼】format
-----------------------------------------------------------------------

问个问题,如果是多机通讯的话,那个寄存器是设置ID的,感谢啊

出0入0汤圆

发表于 2011-4-13 13:21:28 | 显示全部楼层
mark

出0入0汤圆

发表于 2011-4-26 18:12:23 | 显示全部楼层
请问楼主,用的是哪个版本的芯片

出0入0汤圆

发表于 2011-9-20 08:32:14 | 显示全部楼层
距离太近,起码要搞个400米以上,我现在测了才100米左右,郁闷啊

出0入0汤圆

发表于 2011-9-23 12:41:50 | 显示全部楼层
回复【3楼】format
-----------------------------------------------------------------------

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

本版积分规则

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

GMT+8, 2024-5-2 21:41

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

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