Академический Документы
Профессиональный Документы
Культура Документы
1 trong 7
Login
http://www.mikroe.com/forum/viewtopic.php?f=147&t=59839
Register
FAQ
Search
Author
sameersaraf
Message
Post subject: ENC28J60 and PIC18F4550 ethernet communication.
Hi everyone,
I seem to have problems working with enc28j60 and pic18f4550.
I am using an external 8MHz oscillator, I have selected 'divide by 2' option in the PLL Prescalar selection and
have enabled HSPLL to achieve 48MHz clock output.
I am connecting the ethernet board directly to the PC. I am using a cross ethernet cable.
Following are the pins used for the communication:
RC0(pin 15): Reset
RC1(pin 16): CS
RB1(pin 34): SCK
RB0(pin 33): SDI
RC7(pin 26): SDO.
I am unable to ping my ethernet board. I've been trying for a couple of days now, and its getting really
frustrating since i am not able to debug what and where the problem is exactly.
I am attaching my code below. Kindly help me in this matter.
"__EthEnc28j60.h"
#define Spi_Ethernet_HALFDUPLEX
0x00
// half duplex
#define Spi_Ethernet_FULLDUPLEX
0x01
// full duplex
at LATC1_bit;
at TRISC1_bit;
/************************************************************
* ROM constant strings
*/
const code unsigned char httpHeader[] = "HTTP/1.1 200 OK\nContent-type: " ;
// HTTP header
11/28/2014 9:07 AM
2 trong 7
http://www.mikroe.com/forum/viewtopic.php?f=147&t=59839
* when coming short of ROM, fragmented data is handled more efficiently by linker
*
* this HTML page calls the boards to get its status, and builds itself with javascript
*/
const code
char
*indexPage =
const code
char
*indexPage2 =
"</table></td><td>\
/***********************************
* RAM variables
*/
unsigned char
= {158, 144,
57, 173 } ;
= {158, 144,
57, 1 } ;
0 } ;
1 } ;
// my MAC address
// my ip addr
unsigned char
getRequest[15] ;
unsigned char
dyna[29] ;
unsigned long
httpCounter = 0 ;
/*******************************************
* functions
*/
11/28/2014 9:07 AM
3 trong 7
http://www.mikroe.com/forum/viewtopic.php?f=147&t=59839
/*
* put the constant string pointed to by s to the ENC transmit buffer.
*/
/*unsigned int
{
unsigned int ctr = 0 ;
while(*s)
{
Spi_Ethernet_putByte(*s++) ;
ctr++ ;
}
return(ctr) ;
}*/
/*
* it will be much faster to use library Spi_Ethernet_putConstString routine
* instead of putConstString routine above. However, the code will be a little
* bit bigger. User should choose between size and speed and pick the implementation that
* suites him best. If you choose to go with the putConstString definition above
* the #define line below should be commented out.
*
*/
#define putConstString
SPI_Ethernet_putConstString
/*
* put the string pointed to by s to the ENC transmit buffer
*/
/*unsigned int
putString(char *s)
{
unsigned int ctr = 0 ;
while(*s)
{
Spi_Ethernet_putByte(*s++) ;
ctr++ ;
}
return(ctr) ;
}*/
/*
* it will be much faster to use library Spi_Ethernet_putString routine
* instead of putString routine above. However, the code will be a little
* bit bigger. User should choose between size and speed and pick the implementation that
* suites him best. If you choose to go with the putString definition above
* the #define line below should be commented out.
*
*/
#define putString
SPI_Ethernet_putString
/*
* this function is called by the library
* the user accesses to the HTTP request by successive calls to Spi_Ethernet_getByte()
* the user puts data in the transmit buffer by successive calls to Spi_Ethernet_putByte()
* the function must return the length in bytes of the HTTP reply, or 0 if nothing to transmit
*
* if you don't need to reply to HTTP requests,
* just define this function with a return(0) as single statement
*
*/
unsigned int
11/28/2014 9:07 AM
4 trong 7
http://www.mikroe.com/forum/viewtopic.php?f=147&t=59839
len;
// my reply length
if(localPort != 80)
{
return(0) ;
}
// get 10 first bytes only of the request, the rest does not matter here
for(len = 0 ; len < 10 ; len++)
{
getRequest[len] = SPI_Ethernet_getByte() ;
}
getRequest[len] = 0 ;
len = 0;
{
return(0) ;
}
httpCounter++ ;
if(getRequest[5] == 's')
len = putConstString(httpHeader) ;
// HTTP header
len += putConstString(httpMimeTypeScript) ;
11/28/2014 9:07 AM
5 trong 7
http://www.mikroe.com/forum/viewtopic.php?f=147&t=59839
bitMask = 0 ;
if(isdigit(getRequest[6]))
}
}
if(len == 0)
// what do to by default
{
len =
putConstString(httpHeader) ;
// HTTP header
len += putConstString(httpMimeTypeHTML) ;
len += putConstString(indexPage) ;
len += putConstString(indexPage2) ;
return(len) ;
of bytes to transmit
}
/*
* this function is called by the library
* the user accesses to the UDP request by successive calls to Spi_Ethernet_getByte()
* the user puts data in the transmit buffer by successive calls to Spi_Ethernet_putByte()
* the function must return the length in bytes of the UDP reply, or 0 if nothing to transmit
*
* if you don't need to reply to UDP requests,
* just define this function with a return(0) as single statement
*
*/
unsigned int
return(0);
}
/*
* main entry
*/
void
main()
{
ADCON1 = 0x0B;
CMCON = 7;
PORTA = 0 ;
TRISA = 0xff ;
11/28/2014 9:07 AM
6 trong 7
http://www.mikroe.com/forum/viewtopic.php?f=147&t=59839
PORTB = 0 ;
TRISB = 0xff ;
LATD
= 0 ;
TRISD = 0 ;
/*
* starts ENC28J60 with :
* reset bit on RC0
* CS bit on RC1
* my MAC & IP address
* full duplex
*/
SPI1_Init();
//SPI_Rd_Ptr = SPI1_Read;
SPI_Ethernet_Init(myMacAddr, myIpAddr, Spi_Ethernet_FULLDUPLEX) ;
while(1)
// do forever
{
/*
* if necessary, test the return value to get error code
*/
SPI_Ethernet_doPacket() ;
/*
* add your stuff here if needed
* Spi_Ethernet_doPacket() must be called as often as possible
* otherwise packets could be lost
*/
}
}
Thanks in advance.
Top
dejan.odabasic
Hello,
mikroElektronika team
Top
sameersaraf
11/28/2014 9:07 AM
7 trong 7
http://www.mikroe.com/forum/viewtopic.php?f=147&t=59839
Hi,
Thanks dejan.odabasic for your quick response.
Joined: 26 Feb 2014
06:26
Posts: 3
Top
dejan.odabasic
Hello,
mikroElektronika team
hello again..
I went through the topic you suggested.. Found it informative..
I have a question..
I am directly connecting my ethernet board to the pc (I'm using a cross cable for this purpose), so can i not
just set any ip address from any of the three classes A, B or C?
I know this is too basic, but I'm new to all this stuff.
Top
Display posts from previous: All posts
Ascending
Go
Page 1 of 1 [ 5 posts ]
Who is online
Users browsing this forum: No registered users and 2 guests
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Search for:
Go
Jump to:
User Projects
Go
11/28/2014 9:07 AM