ENC28J60 Ethernet Library V3.6

General discussion on mikroPascal for dsPIC30/33 and PIC24.
Post Reply
Author
Message
yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

ENC28J60 Ethernet Library V3.6

#1 Post by yo2lio » 26 Jan 2008 19:22

Hi,

ENC28J60 library for 16 bit MCU family, with full source code, available here : http://www.microelemente.ro/MikroPascal ... source.zip

Tested on Explorer16 board, MCU PIC24FJ128GA010, home made ENC28J60 ethernet board, MCU clock 32 MHz(16 Mips), Spi bus speed 16 Mbps.

Default Ip is 192.193.194.12 , you can change this from unit enc_lib_user.

Code: Select all

{Ethernet library V3.6 and example for ENC28J60.

 ARP, ICMP, UDP, NTP, TCP, HTTP

 Author of this project : Florin Andrei Medrea
 Copyright (c) 2008 - YO2LIO - All Rights Reserved
 26-Jan-2008

User Functions and Procedures:

 Available types :
   IpHeader : array[4] of byte;
   MacHeader : array[6] of byte;

(AddrPacket is address of received packet, TXSTART is start address of transmited packet)

- Procedure Eth_SetParameters;
  // Set your IP, Mac, Mask, Gateway ... etc... here.
  // Str2Ip('192.168.1.253',eth_ip_addr);
  // Str2Ip('85.120.220.254',eth_ntp_addr);
  // Str2Ip('192.168.1.1',eth_gateway);
  // Str2Ip('255.255.255.0',eth_mask);
  // Str2Mac('0004A300809A',eth_mac);
  // Str2Ip('192.168.1.4',user_ip_addr);
  // eth_port := 10001;
  // dest_port := 10001;

- Procedure Eth_Init_(ENC_Port,CS,Reset);
  // Init Ethernet.

- Procedure Eth_Reset;
  // Reset Ethernet.

- Procedure Eth_DoPacket;
  // Process incoming packets.

- Function Eth_UserTCP(var dest_ip_addr_T : IpHeader; var source_port_T, dest_port_T, len_T : word) : word;
  // This function is called by library. Put your TCP response for WEB server parameters here. See example.

- Function Eth_UserUDP(var dest_ip_addr_U : IpHeader; var dest_port_U, source_port_U, len_U : word) : word;
  // This function is called by library. Put your UDP response here. See example. ( ECHO example )

- Function CopyFlashToEthMem_CP(start_Flash_address : longint): word;
  // Copy Const from flash to Eth Memory and return length of Const data.
  // Const data must be defined as STRING. (and must be zero terminated)
  // Ex. len := CopyFlashToEthMem_CP(@httpHeader);

- Function Eth_SendARP(var ip_dest : IpHeader) : Boolean;
  // Get ARP request. Return True if Mac exist.
  // Return dest. mac address in var dest_mac : MacHeader;.
  // Return dest. ip address in var dest_ip_addr : IpHeader;.
  // Ex. bol := Eth_SendARP(user_ip_addr);
  // First function search in ArpCache (size of 9) ...

- Procedure SendUDP(dest_port_S, source_port_S, len_data : word; var data_udp : array[1472] of byte);
  // Send UDP mesage. Max 1472 bytes.
  // Ex. If Eth_SendARP(user_ip_addr) then SendUDP(dest_port, eth_port, 10, 'Test Test ');

- Procedure Eth_SendPing(SlotState : boolean; PingSlot : Byte);
  // Have 8 Slots available 0 .. 7 and PingCache size of 8.
  // Ex. Eth_SendPing(Eth_SendARP(user_ip_addr),0); Send Ping at user_ip_addr and put result in Slot 0.
  // PingCache format :
  // PingCache_IpP[Slot] : IpHeader;
  // PingCache_MacP[Slot] : MacHeader;
  // PingCache_Time[Slot] : word;
  // PingCache_TTL[Slot] : byte.

- Function Send_Ping(var ip_address : IpHeader) : word;
  // Send ping at specified ip_address and return response time.
  // Ex. PingTimeResponse := Send_Ping(user_ip_address);

- Function Send_UDP(var ip_address : IpHeader; dest_port_S, source_port_S, len_data : word; var data_udp : array[1472] of byte) : boolean;
  // Send UDP mesage, max 1472 bytes, at specified ip_address and return true if success.
  // Ex. Success := Send_UDP(user_ip_addr, 10001, 9999, 10, 'data data ');

- Function Send_ARP(var ip_address : IpHeader; var mac_address : MacHeader) : boolean;
  // Get MAC for specified ip_address, put result in mac_address variable and return true if success.
  // Ex. Success := Send_ARP(user_ip_addr,reply_mac_addr);

- Procedure Firewall(ICMP, TCP, UDP : boolean);
  // Default all false, allow all type of packets.
  // If ICMP = true, ignore ICMP request. Ex. Firewall(true, false, false);
  // If TCP = true, ignore TCP packets. Ex. Firewall(false, true, false);
  // If UDP = true, ignore UDP packets. Ex. Firewall(false, false, true);

- Function Ntp_query : Boolean;
  // Syncronize time.
  // Ntp address must me stored in eth_ntp_addr (see Eth_SetParameters)
  // If syncronization was successfully Ntp_sync flag will be true.

- Procedure Get_Time;
  // Transform NTP time in day/month/year ...
  // Data will be stored in :
  // TTime_Rfc   = Time in RFC format
  // TTime_Unix  = Time in UNIX format
  // TTime_Year  = Year (ex. 2007)
  // TTime_Month = Month (ex. 07)
  // TTime_Day   = Day (ex. 31)
  // TTime_Hour  = Hour(ex. 12)
  // TTime_Min   = Min (ex. 59)
  // TTime_Sec   = Sec (ex. 32)
  // TTime_Str   = String format max. 32 ('2007-11-24 14:25:00')

- Procedure Eth_PutByte(value : byte);
  // Put one byte in ETH memory.

- Function Eth_GetByte : byte;
  // Get one byte from ETH memory.

- Procedure CopyEthMemToRam(start_eth_address, dest_ram_address, length_w : word);
  // Ex. CopyEthMemToRam(AddrPacket+6,@dest_mac_addr,6);

- Procedure CopyEthMemToRam_Inv(start_eth_address, dest_ram_address, length_w : word);
  // Ex. CopyEthMemToRam(AddrPacket+6,@data_dWord,4);

- Procedure CopyEthMemToEthMem(start_eth_address, dest_eth_address, length_w : word; where : byte);
  // where = 0 copy from Eth RxBuf to Eth TxBuf
  // where = 1 copy from Eth TxBuf to Eth TxBuf
  // Ex. CopyEthMemToEthMem(AddrPacket+38,TXSTART+28,4,0);

- Procedure CopyRamToEthMem(start_ram_address, dest_eth_address, length_w : word);
  // Ex. CopyRamToEthMem(@eth_mac,TXSTART+22,6);

- Procedure CopyRamToEthMem_Inv(start_ram_address, dest_eth_address, length_w : word);
  // Ex. CopyRamToEthMem(@data_dWord,TXSTART+22,4);

- Procedure CopyRamToEthMem_CP(start_ram_address, length_w : word);
  // Copy var data to Eth Memory.
  // Ex. CopyRamToEthMem_CP(@data,46);

- Procedure CopyRamToEthMem_CP_Inv(start_ram_address, length_w : word);
  // Ex. CopyRamToEthMem_CP(@data_dWord,4);

- Function CopyRamStringToEthMem_CP(var s : string[255]): word;
  // Copy var data to Eth Memory and return length of var data.
  // Var data must be defined as String. (must be zero terminated)
  // Ex. len := CopyRamStringToEthMem_CP('data data data');

- Procedure CopyFlashToEthMem(start_Flash_address : longint; dest_eth_address, length_w : word);
  // Ex. CopyFlashToEthMem(@httpHeader,TXSTART+54,30);

- Procedure CopyFlashToEthMem_CP(start_Flash_address : longint; length_w : word);
  // Ex. CopyFlashToEthMem(@httpHeader,30);

- Function CopyFlashStringToEthMem(start_Flash_address : longint; dest_eth_address : word): word;
  // Copy Const from flash to Eth Memory and return length of Const data.
  // Const data must be defined as STRING. (must be zero terminated)
  // Ex. len := CopyFlashToEthMem_CP(@httpHeader,TXSTART+54);

- Function CopyFlashStringToEthMem_CP(start_Flash_address : longint): word;
  // Copy Const from flash to Eth Memory and return length of Const data.
  // Const data must be defined as STRING. (must be zero terminated)
  // Ex. len := CopyFlashToEthMem_CP(@httpHeader);

- Procedure WriteToEthMem(dest_eth_address : word; value : byte);
  // Ex. WriteToEthMem(TXSTART+12,$08);

- Function ReadFromEthMem(start_eth_address : word) : byte;
  // Ex. data := ReadFromEthMem(AddrPacket+38);

- Function EthMemCompareWithRam(start_eth_address, start_ram_address, length_w : word) : boolean;
  // Ex. bol := EthMemCompareWithRam(AddrPacket+30,@eth_ip_addr,4);

- Function EthMemCompareWithFlash(start_eth_address : word; start_Flash_address : longint; length_w : word) : boolean;
  // Ex. bol := EthMemCompareWithFlash(AddrPacket+54, @httpHeader, 30);
}
Live software , few days, http://ip-watcher.dyndns.info/
Last edited by yo2lio on 29 Jan 2008 20:37, edited 1 time in total.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#2 Post by yo2lio » 29 Jan 2008 17:50

Library updated !!!

Now you can chose between SPI1, SPI2, Mikroe SPI and LIO_SPI routines.

You must made this chose in DSPIC_lib1_enc28j60_V3_6.dpas. Default values : SPI1 and LIO_SPI routines.

If you want to use Mikroe standard SPI routine, just comment this part :

Code: Select all

{$DEFINE LIO_SPI}
If you want to use SPI2 also you must change Spi1_Init_Advanced... with Spi2_Init_Advanced... routine.

Library tested also with MCU dsPIC33FJ256GP710, 40 Mips, SPI1 10 Mbps and work great.

With PIC24FJ128GA010, 16 Mips, SPI module and ENC28J60 work up to 16 Mbps.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#3 Post by yo2lio » 04 Feb 2008 22:43

Library updated !

Resolved small BUG in CopyEthMemToEthMem routine. When length of data copy was 0 or 1, MCU frozen.
This BUG was submitted by guyfoc.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#4 Post by yo2lio » 08 Mar 2008 16:08

Hi,

Library updated. Resolved small bug in Get_Time routine.

You can download source code from : http://www.microelemente.ro/MikroPascal ... source.zip

Old files : http://www.microelemente.ro/MikroPascal ... ce_old.zip
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

mbluethunder7000
Posts: 17
Joined: 28 Apr 2008 12:16
Location: Egypt / Cairo

#5 Post by mbluethunder7000 » 10 Jul 2008 17:57

Hi Yo2lio

Do you have more examples for dsPIC (Like UDP send, UDP Receive, etc) as you did in MikroPascal?

BR

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#6 Post by yo2lio » 10 Jul 2008 18:32

Sorry, at this moment NO !
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

toobajaved
Posts: 12
Joined: 13 Nov 2008 08:55

dsPIC and Ethernet

#7 Post by toobajaved » 24 Feb 2009 17:23

Hi yo2lio!!
I need ur help regarding dsPIC and ethernet proto board.
I am using mikroC., EasydsPIC4 board with dsPIC30F4013, and Mikroe Ethernet Proto board.

I just want to send/recieve few bytes from my dsPIc to Ethernet, but am not able to do so using mikroe libraries.

Can you please tell me how to use your library? Do you have any examples for dsPIC now??
Please .. I want to complete my project by mid of March.
Thanks!

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#8 Post by yo2lio » 24 Feb 2009 19:39

Hello,

MikroC ... hmmm, I work in MIkroPascal and MikroBasic.

It's impossible for me to cover all MCU in all languages ! It's too much ...

I have ENC_V3_7, I will try to make few example ant put this on forum. MikroPascal language.
Last edited by yo2lio on 25 Feb 2009 07:31, edited 1 time in total.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

toobajaved
Posts: 12
Joined: 13 Nov 2008 08:55

#9 Post by toobajaved » 25 Feb 2009 05:27

Hello ...
thnx for ur reply..
ok!.. then plz give me examples in MikroPascal for dsPIC.

Thnx once again.

Post Reply

Return to “mikroPascal for dsPIC30/33 and PIC24 General”