As a result of large research, I found this source code for STM32f1 this link and I changed it for STM32f3. And the build and install to my STM32. My ethernet cable connect between my computer and enc28j60 module. If I debugging this code my code stack in main.c
and while loop:
while (1)
{
eMBPoll();
led_poll();
/* 从网络设备读取一个IP包,返回数据长度 */
uip_len = tapdev_read();
/* 收到数据 */
**if (uip_len > 0)**
{
/* 处理IP数据包 */
if (BUF->type == htons(UIP_ETHTYPE_IP))
{
uip_arp_ipin();
uip_input();
if (uip_len > 0)
{
uip_arp_out();
tapdev_send();
}
}
/* 处理ARP报文 */
else if (BUF->type == htons(UIP_ETHTYPE_ARP))
{
uip_arp_arpin();
if (uip_len > 0)
{
tapdev_send();
}
}
}
I stuck if (uip_len > 0) line because uip_len return 0 for this line:
(My code same as bellow github link so i dont share all of code )
enc28j_60.c in the unsigned int enc28j60_packet_receive(unsigned char *packet, unsigned int maxlen) function:
unsigned int enc28j60_packet_receive(unsigned char *packet, unsigned int maxlen)
{
unsigned int rxstat;
unsigned int len;
if (enc28_read(EPKTCNT) == 0)
{
return (0);
}
enc28_write(ERDPTL, (next_pack_ptr));
enc28_write(ERDPTH, (next_pack_ptr) >> 8);
next_pack_ptr = enc28_readOp(ENC28J60_READ_BUF_MEM, 0);
next_pack_ptr |= enc28_readOp(ENC28J60_READ_BUF_MEM, 0) << 8;
len = enc28_readOp(ENC28J60_READ_BUF_MEM, 0);
len |= enc28_readOp(ENC28J60_READ_BUF_MEM, 0) << 8;
len -= 4;
rxstat = enc28_readOp(ENC28J60_READ_BUF_MEM, 0);
rxstat |= enc28_readOp(ENC28J60_READ_BUF_MEM, 0) << 8;
if (len > maxlen - 1)
{
len = maxlen - 1;
}
**if ((rxstat & 0x80) == 0)
{
GPIO_SetBits(GPIOE, GPIO_Pin_9);
len = 0;
}**
else
{
des_enc28_readBuffer(packet, len);
}
enc28_write(ERXRDPTL, (next_pack_ptr));
enc28_write(ERXRDPTH, (next_pack_ptr) >> 8);
enc28_writeOp(ENC28J60_BIT_FIELD_SET, ECON2, ECON2_PKTDEC);
return (len);
}
Why is the rxstat & 0x80) == 0? I do not understand.