Я особо не насиловал, но народ не жаловался ни разу. Взято из проекта mynet
myencSoftReset();//програмный сброс
if((myencCmdRead(ENC_RCR | ESTAT)&0xF7)!=0x1)return 0;//проверка наличия чипа
// if(!myencIsReady())return 0;//проверка наличия чипа
myencSetBank(0);
// initialize receive buffer
RPH.NextPacketPtr = RXSTART_INIT;
myencCmdWrite(ENC_WCR|ERXSTL, RXSTART_INIT&0xFF);// 16-bit transfers, must write low byte first
myencCmdWrite(ENC_WCR|ERXSTH, RXSTART_INIT>>8);
// set receive pointer address
myencCmdWrite(ENC_WCR|ERXRDPTL, RXSTOP_INIT&0xFF);
myencCmdWrite(ENC_WCR|ERXRDPTH, RXSTOP_INIT>>8);
// set receive buffer end
// ERXND defaults to 0x1FFF (end of ram)
myencCmdWrite(ENC_WCR|ERXNDL, RXSTOP_INIT&0xFF);
myencCmdWrite(ENC_WCR|ERXNDH, RXSTOP_INIT>>8);
// set transmit buffer start
// ETXST defaults to 0x0000 (beginnging of ram)
myencCmdWrite(ENC_WCR|ETXSTL, TXSTART_INIT&0xFF);
myencCmdWrite(ENC_WCR|ETXSTH, TXSTART_INIT>>8);
myencSetBank(2);
// enable MAC receive
myencCmdWrite(ENC_WCR|MACON1, MACON1_MARXEN|MACON1_TXPAUS|MACON1_RXPAUS);
// bring MAC out of reset
//myencCmdWrite(ENC_WCR|MACON2, 0x00);
// enable automatic padding and CRC operations
myencCmdWrite(ENC_WCR|MACON3, MACON3_PADCFG0|MACON3_TXCRCEN|MACON3_FRMLNEN);
// Allow infinite deferals if the medium is continuously busy
// (do not time out a transmission if the half duplex medium is
// completely saturated with other people's data)
myencCmdWrite(ENC_WCR|MACON4, MACON4_DEFER);
// Late collisions occur beyond 63 bytes (default for 802.3 spec)
myencCmdWrite(ENC_WCR|MACLCON2, 63);
// set inter-frame gap (non-back-to-back)
myencCmdWrite(ENC_WCR|MAIPGL, 0x12);
myencCmdWrite(ENC_WCR|MAIPGH, 0x0C);
// set inter-frame gap (back-to-back)
//myencCmdWrite(ENC_WCR|MABBIPG, 0x12);
// Set the maximum packet size which the controller will accept
myencCmdWrite(ENC_WCR|MAMXFLL, MAX_FRAMELEN&0xFF);
myencCmdWrite(ENC_WCR|MAMXFLH, MAX_FRAMELEN>>8);
myencSetBank(3);
// write MAC address
// NOTE: MAC address in ENC28J60 is byte-backward
myencCmdWrite(ENC_WCR|MAADR5, CommParam.MAC.addr[0]);
myencCmdWrite(ENC_WCR|MAADR4, CommParam.MAC.addr[1]);
myencCmdWrite(ENC_WCR|MAADR3, CommParam.MAC.addr[2]);
myencCmdWrite(ENC_WCR|MAADR2, CommParam.MAC.addr[3]);
myencCmdWrite(ENC_WCR|MAADR1, CommParam.MAC.addr[4]);
myencCmdWrite(ENC_WCR|MAADR0, CommParam.MAC.addr[5]);
myencPhyWrite(PHCON2, PHCON2_HDLDIS);// no loopback of transmitted frames
myencPhyWrite(PHIE, PHIE_PLNKIE|PHIE_PGEIE);// прерывание по LINK CHANGE
myencCmdWrite(ENC_WCR|EIE, EIE_INTIE|EIE_PKTIE|EIE_LINKIE);// enable interrutps
myencCmdWrite(ENC_WCR|ECON1, ECON1_RXEN);// enable packet reception
В этот проект не заглядывал пару лет, ничего не помню, но изделия потихоньку продаются.
-
- Спасибо. Тоже остановился на полудуплексе. Пока завалить не удалось... - Гудвин(15.04.2013 19:16)