ENC28J60 Library V3.3 full source code

General discussion on mikroBasic.
Author
Message
niels
Posts: 38
Joined: 11 Jul 2007 23:01

#61 Post by niels » 02 Aug 2008 17:51

hi,

Tried to get your library working for me, but i didn't manage.

I'm using PIC18F4520 and tried udp send, but it seems the program does not get past Eth_Init_(PORTC, 1, 0). The last thing i see on the display is "set parameters done".

I'm using an 8Mhz cristal and run the pic on 32Mhz so i changed the TMR2 postscaller to 8. i tested the delay and is exactly 5seconds, so config word and clock speed is ok...

tried MASTER_OSC_DIV64, MASTER_OSC_DIV4, MASTER_OSC_DIV16..never gets past Eth_Init_(PORTC, 1, 0).

If I don't connect anything to the ethernet port of the ENC, should the lib get past Eth_Init_(PORTC, 1, 0) ? Or can my network hardware also be the problem?

Code: Select all

program UDP_Send

'Ethernet library V3.3 and example for ENC28J60.

' ARP, ICMP, UDP, NTP, TCP, HTTP

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

' Send UDP data to computer ....

' Attention !!!! This program uses TMR1 or TMR2 interrupt at 1 ms !!!!!!!!!
'  User can select between TMR1 and TMR2 interrupt '

'#DEFINE TMR1_Interrupt
#DEFINE TMR2_Interrupt

include "mb_aditional_string_util" ' Don't touch this lines !!!!!
include "lib1_ENC28J60_V3_3"
include "enc_lib_user"
include "lib2_ENC28J60_V3_3"
include "subprocedures"

dim  user_ip_addr as byte[4]
     counter1 as word
     Success as boolean
     data_user as string[100]

#IFDEF TMR2_Interrupt
sub procedure interrupt ' with TMR2 timer
  if TestBit(PIR1,TMR2IF) = 1 then      ' 1 ms TMR2 Q=40 MHz
    PIR1.TMR2IF=0
    CounterTask  ' must called at 1ms
    inc(counter1)
  end if
end sub

Sub Procedure Init ' with TMR2 timer interrupt
  ClrWdt
'  WDTCON = 1
  PIE1 = %00000010
  PR2 = 250
  '40Mhz'''T2CON = %01001001          ' prescaler 4, poscaler 10
  T2CON = %00111001              ' '32Mhz:  prescaler 4, poscaler 8
  TMR2 = 0
  T2CON.TMR2ON = 1           ' start TMR2
  INTCON = %11000000         ' intrerupere TMR2 la 1 ms
End Sub
#ENDIF

Sub Procedure Eth_SetParameters   ' set your parameters here
  Str2Ip("192.168.1.253",eth_ip_addr)
  Str2Ip("192.168.1.1",eth_gateway)
  Str2Ip("255.255.255.0",eth_mask)
  Str2Mac("0004A3008080",eth_mac)
  Str2Ip("192.168.1.2",user_ip_addr)

  eth_port = 10001
  dest_port = 10001
end sub

main:
'  CMCON = CMCON or $07                 ' turn off comparators
'  ADCON1 = $0F                         ' all pins digital
'  MEMCON.EBDIS = 1                     ' disable external memory bus
  Init
  trisB=0
  portB=0
  
  Init_scherm 'initialize screen


  TRISA.5 = 0 'possible bug in SPI Microchip
  nop
  PORTA.5 = 0 'possible bug in SPI Microchip
  nop
  TRISC.3 = 0
  nop
  TRISC.4 = 1
  nop
  TRISC.5 = 0
  nop
  
  Spi_Init_Advanced(MASTER_OSC_DIV64, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH)
  LCD440_CMD(1,192)   'rij 2
  LCD440_OUT_CP("spi init done      ")

  Eth_SetParameters
  LCD440_CMD(1,192)   'rij 2
  LCD440_OUT_CP("set parameters done")

  Eth_Init_(PORTC, 1, 0)'(ENC_Port, CS, Reset)
  LCD440_CMD(1,192)   'rij 2
  LCD440_OUT_CP("eth init done      ")
'  Firewall(true,false,false)

  Wait_For_Lan
  LCD440_CMD(1,192)   'rij 2
  LCD440_OUT_CP("Wait_For_Lan done      ")

  data_user = "Some data ..... here ...."
  counter1 = 5000
  while true
    Eth_DoPacket ' process incoming packets
    if counter1 > 5000 then  'repeat at 5000 ms
      counter1 = 0
      Success = Send_UDP(user_ip_addr, dest_port, eth_port, Str_Len(data_user), data_user)
      ' Send UDP data ...
    end if
  wend
end.
anyone managed to get the lib working on a slower speed then 40Mhz?
I'm going to get a 10Mhz crystal soon, i hope that is the problem.

thanks for any ideas.
Niels

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

#62 Post by yo2lio » 02 Aug 2008 22:01

Must work !

My original code have WDT enable ! Maybe you must disable this in configuration bits.

Or it's possible to be a problem with your hardware.

Eth_Init_ is a blocking routine and don't work without ENC28J60 ....
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:

#63 Post by yo2lio » 03 Aug 2008 12:45

Hi,

New version of ENC28J60 library available.

Eth_init_ routine was changed :

Code: Select all

Sub Procedure Eth_Init_(ENC_Port_CS,CS,ENC_Port_Reset,Reset)
You can download example library from here :
http://www.microelemente.ro/MikroBasic/ ... amples.zip

Source code library available only in MikroPascal language.

Enjoy !
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

niels
Posts: 38
Joined: 11 Jul 2007 23:01

#64 Post by niels » 05 Aug 2008 13:03

ok, found the problem.

The USB jumpers in the easypic board were on the wrong side, so the SPI port wasn't connected properly. I checked all the jumpers on the board but these. Since i'm used to working with PIC18F4550 i didn't notice this :roll: . Took me 2 days to figure this out, man i feel stupid..well, this won't happen again next time!

Thank you very much for making this beatifull library public, it works perfect now. I really appriciate your work.

Niels

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

#65 Post by yo2lio » 20 Aug 2008 12:34

Library updated !

Added hw_cksum flag, default state false (Ethernet checksum in software)
User can modify this flag on the fly, (can chose between software checksum and hardware checksum)
Regarding ERRATA, hardware checksum is not recommended !

You can download example library from here :
http://www.microelemente.ro/MikroBasic/ ... amples.zip

Source code library available only in MikroPascal language.

Enjoy !
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

hanen123456
Posts: 6
Joined: 22 Aug 2008 11:37

#66 Post by hanen123456 » 22 Aug 2008 12:32

how to transmit donnneé to pc with protocole tcp/ip

i'am download example library from here :
http://www.microelemente.ro/MikroBasic/ ... amples.zip

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

#67 Post by yo2lio » 22 Aug 2008 12:33

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

hanen123456
Posts: 6
Joined: 22 Aug 2008 11:37

TCP SEND

#68 Post by hanen123456 » 22 Aug 2008 13:22

PLEASE
HOW CAN SEND DATA WITH THE PROTOCOL TCP / IP to PC in the same network
i'am working with download example library from here :
http://www.microelemente.ro/MikroBasic/ ... amples.zip

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

#69 Post by yo2lio » 22 Aug 2008 13:39

You can't do this !

Library is OPEN SOURCE , feel free to modify this library and add TCP/IP stack and fragmentation if you want.
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

Bytex
Posts: 459
Joined: 23 Jun 2008 00:58
Location: Palmanova (UD), Italy
Contact:

#70 Post by Bytex » 15 Oct 2008 10:39

Hi Florin,
:D GREAT WORK :D

I tried out your last enc_3_4 library for UDP_SEND function using a P18F452 running @10 MHz and TMR1 timer.

For communication test I used this:
http://www.aggsoft.com/tcpip-data-logger/download.htm

:D :D :D :D
Kind regards,
Max

Best regards,
Max

http://www.b-vu.com

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

#71 Post by yo2lio » 15 Oct 2008 11:56

Thank you,

I work now at Firewall rules, DNS, DHCP and SNMP.

Probably this will be done until the end of this year .

After this the next step will be TCP/IP stack and fragmentations, but I waiting for the new compiler ....
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

Bytex
Posts: 459
Joined: 23 Jun 2008 00:58
Location: Palmanova (UD), Italy
Contact:

#72 Post by Bytex » 15 Oct 2008 12:03

OK have a nice work.

So, what about the stand alone NTP server ?
Nobody answere to your post.


Max

Best regards,
Max

http://www.b-vu.com

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

#73 Post by yo2lio » 15 Oct 2008 12:10

Bytex wrote:So, what about the stand alone NTP server ?
Nobody answere to your post.


Max
I waiting for the GPS module and probably will be ready in one month , I hope ....
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

mando
Posts: 23
Joined: 28 May 2008 05:48

#74 Post by mando » 15 Oct 2008 17:26

yo2lio wrote:Thank you,

I work now at Firewall rules, DNS, DHCP and SNMP.

Probably this will be done until the end of this year .

After this the next step will be TCP/IP stack and fragmentations, but I waiting for the new compiler ....
This means we can connect the PIC directly to internet? :o

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

#75 Post by yo2lio » 15 Oct 2008 18:26

mando wrote:This means we can connect the PIC directly to internet? :o
You can connect NOW the PIC to the INTERNET !!!
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

Post Reply

Return to “mikroBasic General”