MikroC - Ethernet Library ping demo for ENC28J60

General discussion on mikroC.
Author
Message
Puggs
Posts: 179
Joined: 17 Nov 2007 23:05
Location: Melbourne Australia
Contact:

#16 Post by Puggs » 18 Sep 2008 22:04

stefaniecg wrote:Finally it pinged back!

Thanks for all your help! :wink:
Since this module seems to cause lots of people trouble, can you tell us what got it working so others can try it as well?

Puggs

stefaniecg
Posts: 7
Joined: 17 Aug 2008 02:01

#17 Post by stefaniecg » 30 Sep 2008 05:40

Hi! Sure, welll I changed a lot of stuff, so I really don't know specifically what was the problem, but...

- make sure the USB jumpers on EP4 are all to the left (I was working on another project of USB so I had changed them)
- external power supply
- check continuity betwen lines, sometimes jumpers aren't working
- you don't have to PLL your clock, use internall clock 8MHz

if using a router:
- disable DHCP from your router
- asign the router a know ip address

if not, make sure to use a cross over cable,
- asign to your pic an IP address in the same domain
- asign an IP to your machine in the same domain
- in your machine configure de default gateway to your router's ip

I think those were the most important changes I made.

Any problems, I'd be glad to help!

jeffreyce
Posts: 1
Joined: 04 Nov 2008 11:50

#18 Post by jeffreyce » 04 Nov 2008 12:09

Hi i am having problems with my eithernet board also.

My situation is having to ping the board using my PC with the following settings;
IP: 149.223.115.12
subnet mask: 255.255.255.0
gateway:149.223.115.254

at the moment i am only using the HEX that was given from the webpage, from the posts i've been reading i assume that becuase the subnet is the same as the MCU (and therefore part of the same network) i shouldn't have a problem pinging it. how much difference would changing the IP give? and what IP should i choose?

My LEDA is on and the LEDB is binking, does this mean that MCU has connected or just the ENC28J60 has found a closed loop?

Alex321
Posts: 5
Joined: 11 Jun 2013 12:31

Re: MikroC - Ethernet Library ping demo for ENC28J60

#19 Post by Alex321 » 11 Jun 2013 12:38

Hello, my project name is Serial Ethernet Board- communication between PC and MCU trough Ethernet and ENC28J60 but I don't know how to start it. I have to write code in MikroC so if anyone can help me or send mi some code it would be great :)

User avatar
milos.vicentijevic
Posts: 965
Joined: 23 Apr 2013 08:09

Re: MikroC - Ethernet Library ping demo for ENC28J60

#20 Post by milos.vicentijevic » 12 Jun 2013 10:22

Hello,

ENC28J60 is used on ETH Click board, so you have already written examples as well as schematics in user manual of ETH Click board.

Please visit this page: http://www.mikroe.com/click/eth/

Best Regards,
Milos Vicentijevic

Alex321
Posts: 5
Joined: 11 Jun 2013 12:31

Re: MikroC - Ethernet Library ping demo for ENC28J60

#21 Post by Alex321 » 12 Jun 2013 14:00

Thank you a lot! I will try! :)

Alex321
Posts: 5
Joined: 11 Jun 2013 12:31

Re: MikroC - Ethernet Library ping demo for ENC28J60

#22 Post by Alex321 » 12 Jun 2013 20:22

Thank you very much!

Alex321
Posts: 5
Joined: 11 Jun 2013 12:31

Re: MikroC - Ethernet Library ping demo for ENC28J60

#23 Post by Alex321 » 12 Jun 2013 20:30

I opened this link that you sent me, I have already read this code in MikroC SPI_Ethernet library. Is there any importan difference if I use PIC18F4550?

User avatar
milos.vicentijevic
Posts: 965
Joined: 23 Apr 2013 08:09

Re: MikroC - Ethernet Library ping demo for ENC28J60

#24 Post by milos.vicentijevic » 18 Jun 2013 10:32

Hello,

So does it work now?

Best Regards,
Milos Vicentijevic

pinalamrutiya
Posts: 8
Joined: 01 Aug 2013 11:00

Re: MikroC - Ethernet Library ping demo for ENC28J60

#25 Post by pinalamrutiya » 16 Sep 2013 07:31

hello enerybody...,
im new to ethernet and enc28j60 and i want to build a project using ethernet and enc28j60 module (http://www.embeddedmarket.com/products/ ... et-Module/) this is my enc28j60 module. im using PIC18F4520 controller with 4Mhz crystal when i load the code hex in it and run it i cant ping that from my PC plz help me...
here is my code

Code: Select all

#define SPI_Ethernet_HALFDUPLEX     0x00
#define SPI_Ethernet_FULLDUPLEX     0x01

// mE ehternet NIC pinout
sfr sbit SPI_Ethernet_Rst at RC0_bit;
sfr sbit SPI_Ethernet_CS  at RC1_bit;
sfr sbit SPI_Ethernet_Rst_Direction at TRISC0_bit;
sfr sbit SPI_Ethernet_CS_Direction  at TRISC1_bit;
// end ethernet NIC definitions



const char httpHeader[] = "HTTP/1.1 200 OK\nContent-type: "; // HTTP header
const char httpMimeTypeHTML[] = "text/html\n\n";             // HTML MIME type
const char httpMimeTypeScript[] = "text/plain\n\n";          // TEXT MIME type


// default html page
char    indexPage[] =
"<html><head><title>mikroElektronika</title></head><body>\
<h3 align=center>MikroElektronika Home Automatization System</h3>\
<form name=\"input\" action=\"/\" method=\"get\">\
<table align=center width=200 bgcolor=#4974E2 border=2><tr>\
<td align=center colspan=2><font size=4 color=white><b>Heat Control</b></font>\
</td></tr><tr><td align=center bgcolor=#4974E2><input name=\"tst1\" width=60 \
type=\"submit\" value=\"ON\"></td><td align=center bgcolor=#FFFF00>\
<input name=\"tst2\" type=\"submit\" value=\"OFF\"></td></tr></table>\
</form></body></html>";

// network parameters
char   myMacAddr[6] = {0x00, 0x04, 0xA3, 0x00, 0x5D, 0x44}; // my MAC address
char   myIpAddr[4]  = {192, 168, 20, 60};                   // my IP address
char   gwIpAddr[4]  = {192, 168, 20, 6};                 // gateway IP address
char   dnsIpAddr[4] = {192, 168, 20, 1};                   // dns IP address
char   ipMask[4]    = {255, 255, 255, 0};                   // subnet mask
// end network parameters

unsigned char   getRequest[20];                        // HTTP request buffer

typedef struct {
  unsigned canCloseTCP: 1;  // flag which closes socket
  unsigned isBroadcast: 1;  // flag which denotes that the IP package has been received via subnet broadcast address (not used for PIC16 family)
} TEthPktFlags;

unsigned int SPI_Ethernet_UserTCP(   char *remoteHost, unsigned int remotePort,
                               unsigned int localPort, unsigned int reqLength,TEthPktFlags *flags)
{
  unsigned int    len;                            // my reply length
  if(localPort != 80)
  return(0);             // I listen only to web request on port 80

  // get 10 first bytes only of the request, the rest does not matter here
  for(len = 0 ; len < 15 ; len++)
  
  getRequest[len] = SPI_Ethernet_getByte();
  
  getRequest[len] = 0;

  if(memcmp(getRequest, "GET /", 5))           //  GET /value=ON
 return(0);  // only GET method

  if(!memcmp(getRequest+11, "ON", 2))        // do we have ON command
    PORTB.F0 = 1;                // set PORTB bit0
  else
    if(!memcmp(getRequest+11, "OFF", 3))        // do we have OFF command
      PORTB.F0 = 0;        // clear PORTB bit0

  if (PORTB.F0)
    {
     memcpy(indexPage+340, "#FFFF00", 6);        // highlight (yellow) ON
     memcpy(indexPage+431, "#4974E2", 6);        // clear OFF
    }
  else
    {
     memcpy(indexPage+340, "#4974E2", 6);        // clear ON
     memcpy(indexPage+431, "#FFFF00", 6);        // highlight (yellow) OFF
    }

  len =  SPI_Ethernet_putConstString(httpHeader);               // HTTP header
  len += SPI_Ethernet_putConstString(httpMimeTypeHTML);  // with HTML MIME type
  len += SPI_Ethernet_putString(indexPage);             // HTML page first part
  return len; // return to the library with the number of bytes to transmit
}
unsigned int SPI_Ethernet_UserUDP(   char *remoteHost, unsigned int remotePort,
                                unsigned int destPort, unsigned int reqLength,TEthPktFlags *flags)
{
  return 0; // back to the library with the length of the UDP reply
}
void main()
{
  ADCON1 |= 0x0F ;        // no analog inputs
  CMCON  |= 0x07 ;        // turn off comparators

  PORTB.F0 = 0;
  TRISB.F0 = 0;                // set PORTB.B0 as output (rele control pin)

  // starts ENC28J60 with: reset bit on PORTC.F0, CS bit on PORTC.F1,
  //                             my MAC & IP address,  full duplex
  Spi1_Init();
  // full duplex, CRC + MAC Unicast + MAC Broadcast filtering

   Spi_Ethernet_Init (myMacAddr, myIpAddr,SPI_Ethernet_FULLDUPLEX) ;
  // dhcp will not be used here, so use preconfigured addresses
  SPI_Ethernet_confNetwork(ipMask, gwIpAddr, dnsIpAddr);

  while(1)
  {                 // do forever
    SPI_Ethernet_doPacket();           // process incoming Ethernet packets
  }
}

User avatar
milos.vicentijevic
Posts: 965
Joined: 23 Apr 2013 08:09

Re: MikroC - Ethernet Library ping demo for ENC28J60

#26 Post by milos.vicentijevic » 16 Sep 2013 13:02

Hello pinalamrutiya,

Please, visit this page: http://www.mikroe.com/click/eth/. It is page for ETH Click board. It is board that uses SPI. So hardware is the same as your board. You can use this code as a reference so you can write your own code.

Note that ENC28J60 has to be supplied from +3.3V source. Please test your MCU at speed you are going to use with your ETH board at +3.3V (LED blinking or something similar easy to write). Even it says that MCU is capable of working at +3.3V it might make some problems. specially at higher speeds so please test it first.

Best Regards,
Milos Vicentijevic

pinalamrutiya
Posts: 8
Joined: 01 Aug 2013 11:00

Re: MikroC - Ethernet Library ping demo for ENC28J60

#27 Post by pinalamrutiya » 17 Sep 2013 14:50

Thanks for reply buddy...
@Milos Vicentijevic

pinalamrutiya
Posts: 8
Joined: 01 Aug 2013 11:00

Re: MikroC - Ethernet Library ping demo for ENC28J60

#28 Post by pinalamrutiya » 01 Nov 2013 07:22

milos.vicentijevic wrote:Hello pinalamrutiya,

Please, visit this page: http://www.mikroe.com/click/eth/. It is page for ETH Click board. It is board that uses SPI. So hardware is the same as your board. You can use this code as a reference so you can write your own code.

Note that ENC28J60 has to be supplied from +3.3V source. Please test your MCU at speed you are going to use with your ETH board at +3.3V (LED blinking or something similar easy to write). Even it says that MCU is capable of working at +3.3V it might make some problems. specially at higher speeds so please test it first.

Best Regards,
Milos Vicentijevic
hey i had tried that thing as you suggest but still have the same problem.
this time i buy the new module PICtail plus daughter board http://www.microchip.com/stellent/idcpl ... e=en027750

can you please suggest some ways to get is worked ..i have the same code as i mentioned in the previous post this time i m using 8MHz crystal.

thanks in advance

User avatar
milos.vicentijevic
Posts: 965
Joined: 23 Apr 2013 08:09

Re: MikroC - Ethernet Library ping demo for ENC28J60

#29 Post by milos.vicentijevic » 01 Nov 2013 10:50

Hello Pinalamrutiya,

as I can see this board you have has pretty much the same as ETH Cick. Please compare this schematics:

http://ww1.microchip.com/downloads/en/D ... 51602b.pdf

to ETH Click schematics, so you can find out how to connect it properly.

Best Regards,
Milos Vicentijevic

pinalamrutiya
Posts: 8
Joined: 01 Aug 2013 11:00

Re: MikroC - Ethernet Library ping demo for ENC28J60

#30 Post by pinalamrutiya » 01 Nov 2013 11:11

milos.vicentijevic wrote:Hello Pinalamrutiya,

as I can see this board you have has pretty much the same as ETH Cick. Please compare this schematics:

http://ww1.microchip.com/downloads/en/D ... 51602b.pdf

to ETH Click schematics, so you can find out how to connect it properly.

Best Regards,
Milos Vicentijevic
hello..!!
i think i have connected that board properly but i think there is problem in my code.
is that possible??
but the code is compilled without errors so ....i dont know where is the problem..
when i type ip in my url then the link activity led shows activity on link and also link status led shows connection is there...
but still im not able to ping it from my pc soo plz suggest some ways to debug it
or you can send me your schematics if you have it and code too...

Post Reply

Return to “mikroC General”