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.
I'm going to get a 10Mhz crystal soon, i hope that is the problem.
thanks for any ideas.
Niels