首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 嵌入开发 > 单片机 >

DM9000EP接收有关问题

2013-06-19 
DM9000EP接收问题DM9000EP为何每次接收时总产生接收FIFO缓存溢出错误,且接收数据包长度总大于1526[解决办

DM9000EP接收问题
DM9000EP为何每次接收时总产生接收FIFO缓存溢出错误,且接收数据包长度总大于1526
[解决办法]
这个就不好判断了,这里给你我原来用DM9000的初始化代码参考一下





//==================================================================================================
// DM9000寄存器的初始化
//==================================================================================================
void dm9000_register_init(void)
{
    dm9000_write_index(0, 0);                               // NCR
    dm9000_write_index(2, 0);                               // TX Control Register
    dm9000_write_index(0x2d, 0x10);                         // Transmit Ctrol Register 2
    dm9000_write_index(0x08, 0x3f);                         // Back Pressure Threshold Register
    dm9000_write_index(0x2f, 0x00);                         // Special Mode Control Register
    dm9000_write_index(0x01, 0x2e);                         // Network Status Register, 写1清除
    dm9000_write_index(0xfe, 0x0f);                         // Interrupt Status Register
    dm9000_write_index(0x31, 0x07);                         // Check Sum Control Register, 允许UDP, TCP, IP协议包产生校验和
    dm9000_write_index(0x32, 0x00);                         // Receive Check Sum Status Register
}


//==================================================================================================
// 初始化DM9000
//==================================================================================================

unsigned char dm9000_init(void)
{
    volatile unsigned short count;
    unsigned char ch;
    
    if((dm9000_read_index(0x2b) != 0x90) 
[解决办法]
 dm9000_read_index(0x2a) != 0x00)


    {// 不是DM9000返回
        return 0;
    }
    ch = dm9000_read_index(0x1f);
    dm9000_write_index(0x1f, ch
[解决办法]
0x01);                      // 关网口
    for(count=0; count<600; count++);
    dm9000_write_index(0x1f, ch&0xfe);                      // 重新打开
    for(count=0; count<600; count++);
    dm9000_write_index(0x00, 0x01);                         // 软件复位DM9000
    for(count=0; count<600; count++);
    dm9000_register_init();
    dm9000_write_mac_addr(m_self_ethaddr.mac);              // 
    dm9000_write_index(0xff, 0x83);                         // 使能包收发中断
    dm9000_write_index(0x05, 0x39);                         // Rx Control Register - 使能WATCHDOG, 抛弃长帧,抛弃CRC错帧, 启动收
    mbit_net_reinit = 0;                                    // 
    return 1;
}
//==================================================================================================
// 查询网口收
//==================================================================================================
void net_rx_poll(void)
{
    unsigned char temp, index;
    unsigned short length, count;
    unsigned short i;
    unsigned char xdata *pdest;
    
    temp = dm9000_read_index(0x05);
    if(temp != 0x39)    mbit_net_reinit = 1;                // 如果没有打开网口收模块,则需要初始化
    if(mbit_net_reinit)
    {
        mbit_net_reinit = 0;
        temp = dm9000_read_index(0x1f);
        dm9000_write_index(0x1f, temp&0x01);                // 关闭网口
        for(i=0; i<600; i++);
        dm9000_write_index(0x1f, temp
[解决办法]
0xfe);                // 启动网口
        for(i=0; i<600; i++);


        dm9000_write_index(0x00, 0x01);                     // 软件复位DM9000
        for(i=0; i<600; i++);
        dm9000_register_init();
        dm9000_write_mac_addr(m_self_ethaddr.mac);
        dm9000_write_index(0xff, 0x83);                     // 使能DM9000收发中断, 但不意味单片机使用中断方式
        dm9000_write_index(0x05, 0x39);                     // 使能收模块
    }
    else
    {
        temp = dm9000_read_index(0xfe);                     // 读中断寄存器状态
        if(temp & 0x02)                                     // 数据包传输完毕
        {
            dm9000_write_index(0xfe, 0x02);                 // 清除标志
        }
        if(temp & 0x04)                                     // 收溢出
        {
            dm9000_write_index(0xfe, 0x04);
        }
        if(temp & 0x08)                                     // 收溢出计数器溢出
        {
            dm9000_write_index(0xfe, 0x08);
        }
        if(temp & 0x10)                                     // transmit underrun
        {
            dm9000_write_index(0xfe, 0x10);
        }
        if(temp & 0x20)                                     // Link Status Change
        {
            dm9000_write_index(0xfe, 0x20);


        }
        if(temp & 0x01)                                     // 收到数据包
        {
            //mbit_reading_light1 = 1;
            dm9000_read_index(0xf0);                        // 首先读一个空周期
            _nop_();
            _nop_();
            temp = (DM9000_DATA_ADDR)&0x03;
            if(temp == 1)                                 
            {
                dm9000_read_index(0xf2);
                _nop_();
                _nop_();
                temp = DM9000_DATA_ADDR;                    // 状态
                length = (DM9000_DATA_ADDR);                // 帧数据长度
                length 
[解决办法]
= ((unsigned short)(DM9000_DATA_ADDR))<<8;
                if(length > 192 
[解决办法]
 length < 32)
                {// 不合法的数据, 丢掉
                    for(count=0; count<length; count++)
                    {// 
                        temp = DM9000_DATA_ADDR;
                    }
                }
                else 
                {
                    


                        pdest = xxxxx_buf;
                        for(count=0; count<length; count++)
                        {
                            *pdest++ = DM9000_DATA_ADDR;
                        }
                        .........
            }
            else
            {
                if(temp == 0)
                {
                    dm9000_write_index(0xfe, 0x01);
                }
                else
                {
                    mbit_net_reinit = 1;
                }
            }
        }
    }
}

热点排行