Network Ethernet ENC28J60 Library connect to server problem

Discuss with MikroElektronika software developers about current library development.
Post Reply
Author
Message
bios85
Posts: 62
Joined: 05 Jan 2014 11:14

Network Ethernet ENC28J60 Library connect to server problem

#1 Post by bios85 » 04 Mar 2014 15:53

Hello, I'm using the library to object to a project with enc28j60 .. I have to connect to a server to send bytes but I have problems! This is the code summary:

Code: Select all

void main() {
   unsigned char   IP[4]  = {160,97,25,149};
   unsigned short c=0;
   inizializza(); //Inizializzo tutte le periferiche
    i= 0;
  while(i!=1) {
    i = Net_Ethernet_28j60_connectTCP(IP, 50000, 40000, &socket_global);
    UART1_Write(socket_global->state + 48);
    UART1_Write_Text("Connessione...");
    UART1_Write_Text("I= ");
    UART1_Write(i + 48);
    UART1_Write(0x0D);
    UART1_Write(0x0A);
    //Net_Ethernet_28j60_doPacket();
  }
  c = 1;
  while( (socket_global->state != 3)){
     Net_Ethernet_28j60_doPacket();
  }

  UART1_Write_Text("Connesso..");
  UART1_Write(socket_global->state + 48);
  delay_ms(1000);
  while(1) {                           // do forever

    if( (socket_global->state == 3) && (c == 1) ) {
      server = 1;
      Net_Ethernet_28j60_startSendTCP(socket_global);
      c = 2;
    }
    //UART1_Write(socket_global->state + 48);
    Net_Ethernet_28j60_doPacket();
  }
}


void Net_Ethernet_28j60_UserTCP(SOCKET_28j60_Dsc *socket) {
     unsigned int len=0, size=0;
     unsigned short fine=0;

     char packetC = 0;
     char dat[]="Ciao ";
     unsigned int dat_pos = 0;
     size = (sizeof(dat))/(sizeof(dat[0]));
  
    while(1) {  /*
             UART1_Write_Text("sto inviando: ");
             UART1_Write(dat[dat_pos]);
             UART1_Write(0x0D);
             UART1_Write(0x0A);*/
             if(Net_Ethernet_28j60_putByteTCP(dat[dat_pos++], socket) == 0) {
             // Overflow occur, decrement dat_pos, because last byte not written
               dat_pos--;
               break;
             }
      if(dat_pos >= size-1) {
       //Net_Ethernet_28j60_disconnectTCP(socket);
       //server =0;
       //return;
       packetC++;
       dat_pos=0;
      }
      if(packetC >= 50){
        packetC = 0;
        Net_Ethernet_28j60_disconnectTCP(socket_28j60);
        break;
      }
     }
    }

The server responds to the connection but does not receive the data sent, where am I doing wrong?
I need your help, how to solve?

bios85
Posts: 62
Joined: 05 Jan 2014 11:14

Re: Network Ethernet ENC28J60 Library connect to server prob

#2 Post by bios85 » 10 Mar 2014 20:02

Thanks for your help ansewers!
i regret having purchased your product beacuse, the support is very bad.
The help file for the "network ethernet library" is not good, infact all example are not functionally!
thanks for all, have a nice day

User avatar
dejan.odabasic
mikroElektronika team
Posts: 2649
Joined: 30 Apr 2012 14:20

Re: Network Ethernet ENC28J60 Library connect to server prob

#3 Post by dejan.odabasic » 19 Mar 2014 17:38

Hello,

Network Ethernet library is provided with example project, I suggest testing those project first and use them as guide for your project.
Project are available in ..compiler\Packages\Network_Ethernet_PIC\Examples\HTTP_Demo_28j60\ folder.

Also I suggest reading this forum topic as a guide how to configure network parameters:
http://www.mikroe.com/forum/viewtopic.php?f=164&t=49793

Here are the problems present in your code snippet:
IP array should be global variable, not local.
ENC28J60 module needs to be initialized firs, use Net_Ethernet_28j60_Init() function.
Stack should be initialized with Net_Ethernet_28j60_stackInitTCP() function.
Network parameters are configured with Net_Ethernet_28j60_confNetwork() function.

Best regards.

prakob
Posts: 187
Joined: 24 Nov 2012 07:05
Location: Thailand

Re: Network Ethernet ENC28J60 Library connect to server prob

#4 Post by prakob » 24 Mar 2014 08:19

Hello,

I have success to use Network Ethernet ENC28J60 library but the spi frequency can not up to 16 MHz.

I have tested with easypic fusion7 + eth click with no success. If i reduce spi speed between 8-10MHz , the enc28j60 work well.

The question is Network Ethernet ENC28J60 library can use spi speed up to 16 MHz or not? If the answer is not, the next question is why Microship library can up spi speed to 16 MHz.

Best Regards

prakob.

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: Network Ethernet ENC28J60 Library connect to server prob

#5 Post by marina.petrovic » 25 Mar 2014 10:48

Hi,

Please, can you tell me which microcontroller you use?
Also, please, can you tell me which example you tried?

According to datasheet ENC28J60 feature SPI interface with Clock Speeds up to 20 MHz,
so you should be able to use Network Ethernet Library with 16 MHz SPI clock.

Please, if you can, try to watch the signal on clock line with oscilloscope, to see how much listening you have on the line?

Best regards,
Marina

prakob
Posts: 187
Joined: 24 Nov 2012 07:05
Location: Thailand

Re: Network Ethernet ENC28J60 Library connect to server prob

#6 Post by prakob » 26 Mar 2014 10:50

Hi Marina,

I am using PIC32MX795F512L + Ethernet Click.

With this SPI Speed Setting(8MHz), The ENC28J60 work as expected.

Code: Select all

SPI3_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, 10,
                            _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_IDLE_2_ACTIVE);
But when i speed up spi bus with this setting(16MHz), The ENC28J60 don't work .

Code: Select all

SPI3_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, 5,
                            _SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_IDLE_2_ACTIVE);
Please test on your lab and tell me if it work.

Best Regards
prakob

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: Network Ethernet ENC28J60 Library connect to server prob

#7 Post by marina.petrovic » 28 Mar 2014 15:09

Hi,

If you can, check the signals that you have with oscilloscope.
A problem may occur if the signals are distorted due to higher frequencies.

The most common cause is a very connection.
You can try to use different Ethernet cable to see whether you have the same problem in that situation.

Best regards,
Marina

prakob
Posts: 187
Joined: 24 Nov 2012 07:05
Location: Thailand

Re: Network Ethernet ENC28J60 Library connect to server prob

#8 Post by prakob » 28 Mar 2014 15:36

Hi Marina,

Thanks for your response. As my previous comment, i am using mikroe's development board and i also have tested the same hardware with microchip tcp/ip stack and it work well at 16MHz SPI speed.

I also have tested mi library with other board and have the same behavior that the enc28j60 can not run at 16MHz SPI speed.


Best regards

prakob

User avatar
marina.petrovic
Posts: 2986
Joined: 18 Apr 2013 08:11

Re: Network Ethernet ENC28J60 Library connect to server prob

#9 Post by marina.petrovic » 01 Apr 2014 11:09

Hi,

We will certainly investigate the behavior that you describe a little bit further
and try to find where the problem occurs.

I am very sorry for the inconvenience.

Best regards,
Marina

Post Reply

Return to “Library Development Discussion”