|
小弟近日在网上买了一个ENC28J60的模块,搭配自己手上的MEGA64芯片,从各位前辈分享的代码进行了少许改写。
现在接收完全正常。但是在发送数据,本身知道自己PC的MAC和IP地址,我直接固定了写了一个数据包:
unsigned char ENC28J60_ARP_SEND[42]={0x00,0x1D,0x09,0x7F,0x64,0x8F,0x00,0x60,0x97,0x48,0xF4,0xA8,0x08,0x06,0x00,0x01,0x08,0x00,0x06,0x04,0x00,0x02,0x00,0x60,0x97,0x48,0xF4,0xA8,0xC0,0xA8,0x02,0x6B,0x00,0x1D,0x09,0x7F,0x64,0x8F,0xC0,0xA8,0x02,0x65};
在主程序中,对接收到数据进行分析,发现是PC ping的ARP请求包,直接调用:
length=42;
ENC28J60_SendPacket(length,ENC28J60_ARP_SEND);
void ENC28J60_SendPacket(unsigned int PacketLenth, unsigned char *PacketText)
{
unsigned int Temp;
if( (ENC28J60_ReadReg(EIR) & EIR_TXERIF) ){
ENC28J60_WriteOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_TXRTS);
}
//-----------设置写入条件-------------------------------------
Temp=TXSTART_INIT&0xFF;
ENC28J60_WriteReg(EWRPTL,(unsigned char)(Temp)); //发送缓冲区起地址
Temp=TXSTART_INIT>>8;
ENC28J60_WriteReg(EWRPTH,(unsigned char)(Temp));
Temp=TXSTART_INIT+PacketLenth; //计算写入结束地址
ENC28J60_WriteReg(ETXNDL,(unsigned char)(Temp&0xFF)); //发送缓冲区结束地址
ENC28J60_WriteReg(ETXNDH,(unsigned char)(Temp>>8));
ENC28J60_WriteOp(ENC28J60_WRITE_BUF_MEM, 0, 0x00); //写入数据命令
ENC28J60_WriteBuffer(PacketLenth,PacketText);
ENC28J60_WriteOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_TXRTS);//启动发送
if((ENC28J60_ReadReg(ESTAT)&ESTAT_TXABRT)){printf("failed");}; //确认是否发送成功
}
我在发送代码最后对datasheet中提到的发送出错标志位ESTAT_TXABRT进行了检查,发现发送也是成功的,但是PC端就是侦测不到发出来的数据。
我电脑发出的ARP包我用mega64将它打印出来如下:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
0x0000: FF FF FF FF FF FF 00 1D 09 7F 64 8F 08 06 00 01
0x0010: 08 00 06 04 00 01 00 1D 09 7F 64 8F C0 A8 02 65
0x0020: 00 00 00 00 00 00 C0 A8 02 6B 00 00 00 00 00 00
0x0030: 00 00 00 00 00 00 00 00 00 00 00 00 BC F1 4B FF
请各位帮忙分析下,是我返回的数据包写错了,还是哪个细节没注意?谢谢! |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|