Listing 2—This code builds an ARP request packet in the ENC28J60 transmit buffer and sends it on its way. The target MAC address returned in the ARP reply is picked out and stored for use by the ZigBee bridge application in the round-robin process. (This is only a portion of the listing. The entire listing is posted on the Circuit Cellar FTP site.)


void arp_request(void)
{
	char temp;
	unsigned int i,tx_end;	
	clr_arpflag;
	tx_end = TXSTART;
	//load beginning page for transmit buffer
	banksel(EWRPTL);
	wr_reg(EWRPTL,LOW_BYTE(TXSTART));
	wr_reg(EWRPTH,HIGH_BYTE(TXSTART));
	//write control byte
	wr_sram(tx_control_byte);
	++tx_end;
	//build destination MAC address	
	for(i=0;i<6;++i)
	{
   	wr_sram(0xFF);
	++tx_end;
	}
	//build source MAC address	
 	for(i=0;i<6;++i)
	{
  	wr_sram(macaddrc[i]);
	++tx_end;
	}
	wr_sram(0x08);	//ARP packet type
	wr_sram(0x06);		
	tx_end +=2;
	wr_sram(0x00);	//Hardware type = 10Mb Ethernet
	wr_sram(0x01);		                        (continued)
	tx_end +=2;
	wr_sram(0x08);	//IP protocol
	wr_sram(0x00);		
	tx_end +=2;
	wr_sram(0x06); 	//hardware addr len (06)
	wr_sram(0x04); 	//hardware protocol addr len(04)
	tx_end +=2;
	wr_sram(0x00);	//ARP request
	wr_sram(0x01);		
	tx_end += 2;
	//build source MAC address	
	for(i=0;i<6;++i)
	{
   	wr_sram(macaddrc[i]);
	++tx_end;
	}
	//build source IP address	
	for(i=0;i<4;++i)
	{
   	wr_sram(ipaddrc[i]);
	++tx_end;
	}
	//build unknown target MAC address area	
	for(i=0;i<6;++i)
	{
   	wr_sram(0x00);
	++tx_end;
	}
	.
	.
	.