MikroC - Ethernet Library ping demo for ENC28J60

General discussion on mikroC.
Author
Message
stefaniecg
Posts: 7
Joined: 17 Aug 2008 02:01

MikroC - Ethernet Library ping demo for ENC28J60

#1 Post by stefaniecg » 17 Aug 2008 02:40

Hi, I have Serial Ethernet Board and I'm trying out some of the examples that came with it, unfortuantly I can't get them to work. I can't PING my PIC from my computer's CMD (command).

I have a wireless ROUTER, in wich I connected the Ethernet board RJ-45 output trough an ethernet cable, the Ethernet board is connected to PORTC of my EasyPIC4, PORTC has pull downs, my PIC is 16F877A and it has a 10MHz crital oscillator (XT), the power supply of the easypic4 is external.

Could some one help me out? I can't figure out why I can't PING my PIC from windows's CMD.

MasterBlaster
Posts: 165
Joined: 25 Oct 2007 22:22
Location: Wuppertal, Germany, Earth... :-)
Contact:

Re: MikroC - Ethernet Library ping demo for ENC28J60

#2 Post by MasterBlaster » 17 Aug 2008 14:42

stefaniecg wrote:...I can't figure out why I can't PING my PIC from windows's CMD.
Hi stefaniecg,

- Do you have checked your MCU Project settings? You don't need any pullup- or pulldown resistors on PortC.... 8)

- Whats going on with the settings of the voltage Level?

- Is PortC allready set allone for using hardware on PortC connector, nowhere else?

Have a look on my EP4 board, the settings for an 'eth0:' project:

Image
so long,
MasterBlaster.

Using: EasyPIC4 HW. Rev. 1.03, LCD- & GLCD Display, NetWork and SD/MMC Adapter,
reg. MikroC Pro for PIC 2009, PIC 16F877A, 18F452 and 18F4685 with 8/20 MHz Xtal.

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

#3 Post by stefaniecg » 17 Aug 2008 20:33

Thanks for answering!

I tried removing the pull down (I had all ready tried that), not working.

About "MCU Project settings" where do I check those? I looked in MikroC and in my ROUTER for some option or something but coudn't find anything.

The voltage levels of my ethernet board are exactly as yours. My ethernet board has ~WOL and ~INT disconnected, both VCC y MISO are in the 5V position.

About "PortC allready set allone for using hardware on PortC connector", how can I configure that?

Got a question: Should the board [EP4+ethernet board] work when I connect it to the RJ-45 connector on my laptop? Because when I do so, as my laptop is not a network, LEDA and therefor LEDB never get lid. That's why I figured out, it had to be connected to a network, so I connected it to my ROUTER.

Thanks for your help, really appreciate it!

drdoug
Posts: 1074
Joined: 16 Aug 2007 03:49
Location: St. Louis, MO

#4 Post by drdoug » 17 Aug 2008 22:28

My problem was in configuring the PLL. Do you have that correct? I think 10Mhz gives spotty performance if I remember correctly.

MasterBlaster
Posts: 165
Joined: 25 Oct 2007 22:22
Location: Wuppertal, Germany, Earth... :-)
Contact:

#5 Post by MasterBlaster » 18 Aug 2008 08:19

drdoug wrote:My problem was in configuring the PLL...
Hi all,

yes, that's also will be a reason why. I think the origin example with settings
based on a 8 Mhz. xtal... :roll:

It will be help if you can post in detail your project settings from your
actually mikroC project. :wink:

Are you shure that your MCU run's? Your are using the right IP-address in
your application. Did you test it as an example with a "blinking" LED? This
is exclusively only for this "run" test:

Code: Select all

// preparing PortE for output
    TRISE = 0;
    PORTE = 0;

// ...
    PORTE.F0 = 1;
    delay_ms( 100);
    
    // Working routine in your project
    //
    Spi_Ethernet_doPacket() ;           // process incoming Ethernet packets

    PORTE.F0 = 0;
    delay_ms( 100);
// ...
So you can see if your program runs actualy. :shock:
so long,
MasterBlaster.

Using: EasyPIC4 HW. Rev. 1.03, LCD- & GLCD Display, NetWork and SD/MMC Adapter,
reg. MikroC Pro for PIC 2009, PIC 16F877A, 18F452 and 18F4685 with 8/20 MHz Xtal.

Puggs
Posts: 179
Joined: 17 Nov 2007 23:05
Location: Melbourne Australia
Contact:

Re: MikroC - Ethernet Library ping demo for ENC28J60

#6 Post by Puggs » 19 Aug 2008 07:12

stefaniecg wrote:Hi, I have Serial Ethernet Board and I'm trying out some of the examples that came with it, unfortuantly I can't get them to work. I can't PING my PIC from my computer's CMD (command).

I have a wireless ROUTER, in wich I connected the Ethernet board RJ-45 output trough an ethernet cable, the Ethernet board is connected to PORTC of my EasyPIC4, PORTC has pull downs, my PIC is 16F877A and it has a 10MHz crital oscillator (XT), the power supply of the easypic4 is external.

Could some one help me out? I can't figure out why I can't PING my PIC from windows's CMD.
Ok for starters can the 16F877A use a 10Mhz XTAL?

I use an 18F4520 for mine, using a 10Mhz XTAL and HS_PLL to bring it to 40Mhz

have you set it to use its own IP or via DHCP. if you use DHCP check the DHCP server and see if it has been allocated an IP address

Make sure you using 8.2.x.x of MikroC as earlier versions had a bug with a Gateway of 0.0.0.0

if you want you can send me a .hex file and what you have connected to your easyPIC4 and i can try it on mine.

Puggs

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

#7 Post by stefaniecg » 20 Aug 2008 06:05

Hi, thanks for all your replyes...

About the PLL configuration, I changed the 10MHz XT for a 40Mhz XT, that way I don't have to use PLL. It's not working either. But thanks, I guess that's a start of solving the problem.

The blinking LED thing, I had already tried that in order to check if my MCU was running. In fact, it is, the led blinks.

The code I'm using is posted bellow.
The IP adress I'm making 'ping' from windows CMD is 192.168.0.10
My router adress is: 192.168.0.1

About DHCP, I checked my router, and in fact it had DHCP enabled. Check the picture at the end, that's a screen shot of my routers setting software. I tried disabling DHCP, nevertheless it did't recognize my PIC. In the list of HOST NAMES at the bottom, my PIC never got listed (never got recognized) so the router didn't asigned it an IP address.

Keep in mind that this code was tested with PIC18F458 with a 10MHz XT Oscilator. HARDWARE: Ethernet board with ENC28J60 connected to PORTC without pull up/down of EP4 and external power supply.

Code: Select all

// ***********************************************
//            GENERAL USE VARIABLES
// ***********************************************

#define SPI_Ethernet_HALFDUPLEX     0
#define SPI_Ethernet_FULLDUPLEX     1

unsigned char   myMacAddr[6] = {0x00, 0x14, 0xA5, 0x76, 0x19, 0x3f} ;   // set MAC address
unsigned char   myIpAddr[4] = {192, 68, 0, 10} ;                      // set IP address

// ***********************************************
//                  FUNCTIONS
// ***********************************************

// --------------------------------------------------
// Name: SPI_Ethernet_UserTCP
// Descripcion: Deals TCP protocol packages 
// --------------------------------------------------
unsigned int    SPI_Ethernet_UserTCP(unsigned char *remoteHost, unsigned int remotePort,
                                 unsigned int localPort, unsigned int reqLength)
    {
       return 0;
    }
    
// --------------------------------------------------
// Name: SPI_Ethernet_UserTCP
// Descripton: Deals UDP protocol packages
// --------------------------------------------------
unsigned int    SPI_Ethernet_UserUDP(unsigned char *remoteHost, unsigned int remotePort,
                                 unsigned int destPort, unsigned int reqLength)
    {
       return 0;
    }
    
// ***********************************************
//                      MAIN
// ***********************************************
void main()
  {
    ADCON1 |= 0x0F;                 // turn off ADC convertors
    CMCON  |= 0x07;                 // turn off comparators
    
    TRISE = 0;                      // test config for PORTE
    PORTE = 0;

    Spi_Init();
    SPI_Ethernet_Init(&PORTC, 0, &PORTC, 1, myMacAddr, myIpAddr, SPI_Ethernet_FULLDUPLEX) ;

    while(1)                        // endless loop
            {
            PORTE.F0 = 1;
            delay_ms(50);
            
            SPI_Ethernet_doPacket() ;   // process incoming Ethernet packets

             PORTE.F0 = 0;
             delay_ms(50);
            }
}
Image

Thanks for your help!
Last edited by stefaniecg on 20 Aug 2008 06:41, edited 1 time in total.

Puggs
Posts: 179
Joined: 17 Nov 2007 23:05
Location: Melbourne Australia
Contact:

#8 Post by Puggs » 20 Aug 2008 06:39

Hi

try changing your subnet to 192.168.1.x I have seen problems with the Lib using any 0 in the subnets.

Puggs

drdoug
Posts: 1074
Joined: 16 Aug 2007 03:49
Location: St. Louis, MO

#9 Post by drdoug » 20 Aug 2008 13:38

I tried mine with a 32 and 40 Mhz crystal with no luck. I think (strongly) that you need to try the 10 Mhz crystal with the PLL.

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

Still need help

#10 Post by stefaniecg » 09 Sep 2008 06:29

Hi, I've tried lots of ways to get my PIC connected to my LAN. I have not succede. Can anyone post a program he or she has tryed out and explain how to connect it to the router and general settings. I'm using 18F4550, EasyPic4 and Ethernet Serial Board.
I would really apreciate it!
Thanks!
This is the code i'm using:

Code: Select all

/***********************************************
    Autor: Stefanie Castillo
    Proyecto: Ethernet
*************************************************/

/*
 * Project Name:
     UdpReadLcdOut (Ethernet Library udp read demo for ENC28J60 mcu)
 * Target Platform:
     PIC
 * Copyright:
     (c) mikroElektronika, 2006.
 *
 * description  :
 *      this code shows how to use the ENC28J60 mini library :
 *              the board will reply to ARP & ICMP echo requests
 *              the board will displays UDP requests onto 2x16 LCD second row
 *              and replys to sender with eho udp message (send back received data)
 *
 * target devices :
 *      any PIC with integrated SPI and more than 4 Kb ROM memory
 *      32 to 40 MHz clock is recommended to get from 8 to 10 Mhz SPI clock,
 *      otherwise PIC should be clocked by ENC clock output due to ENC silicon bug in SPI hardware
 *      if you try lower PIC clock speed, don't be surprised if the board hang or miss some requests !
 *      tested with PIC16F877A@10Mhz on EasyPIC4 board
 *
 * EP settings :
 *
 *      RC0 : !RESET    to ENC reset input pin
 *      RC1 : !CS       to ENC chip select input pin
 *      the ENC28J60 SPI bus CLK, SO, SI must be connected to the corresponding SPI pins of the PIC
 *      the INT and WOL signals from the ENC are not used
 *
 * Test configuration:
     MCU:             PIC16F877A
     Dev.Board:       EasyPIC4
     Oscillator:      HS, 10.000MHz
     Ext. Modules:    mE Serial Ethernet board, mE 2x16 lcd module
     SW:              mikroC v6.2.0.0.
 * NOTES:
     None.
 */

/******************************************
                VARIABLES
*******************************************/

#define SPI_Ethernet_HALFDUPLEX     0
#define SPI_Ethernet_FULLDUPLEX     1

unsigned char   myMacAddr[6] = {0x00, 0x14, 0xA5, 0x76, 0x19, 0x3f} ;   // my MAC address
unsigned char   myIpAddr[4] = {192, 168, 11, 111} ;                      // my IP address
unsigned char   dyna[31] ;                                              // buffer for dynamic response
char txt[16], template_msg[] = "UDP msg rcved:";

/******************************************
                FUNCIONES
*******************************************/

/*-----------------------------------------
   Nombre:       SPI_Ethernet_UserTCP()
   Descripción:  Rutina que resuelve TCP msj
   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    SPI_Ethernet_UserTCP(unsigned char *remoteHost, unsigned int remotePort, unsigned int localPort, unsigned int reqLength)
        {
        return 0 ;           // return to the library with the number of bytes to transmit
        }


  /*-----------------------------------------
   Nombre:       SPI_Ethernet_UserUDP()
   Descripción:  Rutina que resuelve UDP msj
   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    SPI_Ethernet_UserUDP(unsigned char *remoteHost, unsigned int remotePort, unsigned int destPort, unsigned int reqLength)
        {
        unsigned char len = 0;

        Lcd_Cmd(LCD_CLEAR) ;                       // clear lcd
        LCD_Out(1, 2, template_msg) ;              // display template message

        // then puts the request string into the transmit buffer
        while(reqLength--)
          txt[len++] = SPI_Ethernet_getByte() ;        // read received udp request from enc receive buffer

        txt[len] = 0;
        LCD_Out(2, 1, txt);                        // display received request on lcd 2nd row
        return (len) ;                             // back to the library with the length of the UDP reply
        }
        
/******************************************
                  MAIN
*******************************************/

void    main()
        {
        ADCON1 |= 0x0F ;                           // ADC convertors off
        CMCON  |= 0x07 ;                           // Comparators off
        TRISA = 0xFF;
        PORTA = 0;

                                                   // LCD
        Lcd_Init(&PORTD);                          // __ lcd initialization
        Lcd_Cmd(LCD_CLEAR);                        // __ lcd clear
        Lcd_Cmd(LCD_CURSOR_OFF);                   // __ lcd turn cursor off
        LCD_Out(1, 2, "Hola Stef");                // __ lcd display default message

                                                   // SPI
        Spi_Init();                                // __ spi initialization
        SPI_Ethernet_Init(&PORTC, 0, &PORTC, 1, myMacAddr, myIpAddr, SPI_Ethernet_FULLDUPLEX) ;
                                                   // __ spi in reset PORTC, reset bit RC0, CS PORTC, CS bit RC1
                                                   // __ MAC: 0x00, 0x14, 0xA5, 0x76, 0x19, 0x3f
                                                   // __ IP: 192, 168, 11, 111
                                                   // __ FULL DUPLEX MODE: both devices transmit and receive at the same time
        Spi_Ethernet_Enable(0x80);
        delay_ms(10);
        while(1)
                {
                PORTA.F0=1;
                SPI_Ethernet_doPacket() ;          // Process incoming Ethernet packets
                delay_ms(100);
                PORTA.F0=1;
                }
        }


Puggs
Posts: 179
Joined: 17 Nov 2007 23:05
Location: Melbourne Australia
Contact:

#11 Post by Puggs » 09 Sep 2008 08:00

Hi

ok, start by tacking out the delays in the main loop, you will drop packets if you don't.

SPI_Ethernet_UserUDP should return 0 as your not sending anything out the ether port.

make sure your using a network connection that can do 10Mbit (most domestic routers can do this).

I have not used Spi_Ethernet_Enable

i'll see if i can add anymore when i get home tonight...

Puggs

Puggs
Posts: 179
Joined: 17 Nov 2007 23:05
Location: Melbourne Australia
Contact:

Re: Still need help

#12 Post by Puggs » 11 Sep 2008 03:37

stefaniecg wrote:Hi, I've tried lots of ways to get my PIC connected to my LAN. I have not succede. Can anyone post a program he or she has tryed out and explain how to connect it to the router and general settings. I'm using 18F4550, EasyPic4 and Ethernet Serial Board.
I would really apreciate it!
Thanks!
This is the code i'm using:
Ohhh i just remembered that the 18F4550 has no SPI but a USB instead... thats why your program is not work....

Puggs

pwdixon
Posts: 1431
Joined: 13 Apr 2005 11:14
Location: UK

Re: Still need help

#13 Post by pwdixon » 11 Sep 2008 09:22

Puggs wrote: Ohhh i just remembered that the 18F4550 has no SPI but a USB instead... thats why your program is not work....

Puggs


There's SPI according to the datasheet.

Puggs
Posts: 179
Joined: 17 Nov 2007 23:05
Location: Melbourne Australia
Contact:

Re: Still need help

#14 Post by Puggs » 11 Sep 2008 10:49

pwdixon wrote:
Puggs wrote: Ohhh i just remembered that the 18F4550 has no SPI but a USB instead... thats why your program is not work....

Puggs


There's SPI according to the datasheet.
Ok i stand corrected... i have had it working on a 18F4520 and 18F4525

Puggs

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

#15 Post by stefaniecg » 18 Sep 2008 18:54

Finally it pinged back!

Thanks for all your help! :wink:
Last edited by stefaniecg on 18 Sep 2008 20:32, edited 1 time in total.

Post Reply

Return to “mikroC General”