It is currently 27 Jun 2017 17:14

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: 19 Jun 2017 09:12 
Offline

Joined: 08 Sep 2016 14:17
Posts: 19
Hi all,

Am using dsPIC33EP128GM604 controller to connect Ethernet with the help of Network Ethernet Library and ENC28J60.

I tried SPI without network library and its working fine. (Generating Clock and Data signal on CRO).

But when i add Network Ethernet library of dsPIC, the network stack Initialization getting failed and mcu getting hang.

afterwards I checked the clock pulse on CRO and its not generating clock signal to communicate with ENC module.

My code has been attached here.. please check and let me know if i missed or mistaked any codes.

_nikhil


Attachments:
TCP_Demo.rar [417.37 KiB]
Downloaded 19 times
Top
 Profile  
 
PostPosted: 22 Jun 2017 16:45 
Offline
User avatar

Joined: 21 Mar 2017 16:57
Posts: 196
Hello,

The ENC28J60 Ethernet library is not supported by default for that MCU. Selecting it for the MCU you are trying to use it on, might lead to unpredicted results.
You can try adapting the given example for your MCU first, without changing it too much, before you try to write your own code. Of course, make sure that the SPI pins are set accordingly to the physical connection with the ENC IC itself.

Best regards


Top
 Profile  
 
PostPosted: 23 Jun 2017 07:46 
Offline

Joined: 08 Sep 2016 14:17
Posts: 19
Hi,

Thank you for your support.

I have checked the UART1 , I2C1 and SPI before and all are working fine.
By checking SPI clocks and data confirmed that SPI pins are properly configured.

if the library not support micro, can you kindly suggest another mcu which has same pin config and also support ENC28J60. Because i already developed the PCB and firmware also tested in PIC33FJ.

Thanks,
Nikhil


Top
 Profile  
 
PostPosted: 25 Jun 2017 18:49 
Offline
User avatar

Joined: 21 Mar 2017 16:57
Posts: 196
Hello,

You might want to try initializing the SPI with lower baudrate, try using higher value for the divider on the SPI advanced init function. The function uses the SPI which is initialized by the user, so I don't really see why it wouldn't work besides the baudrate (or wrong connections). I will look into the appropriate substitution for that MCU in the next few days, if the problem is really incompatibility with the library, but I'll see if I can get my hands on that MCU and test it myself.

Best regards


Top
 Profile  
 
PostPosted: 26 Jun 2017 07:28 
Offline

Joined: 08 Sep 2016 14:17
Posts: 19
Hi,

Here showing my stack and SPI initialization routine.


#include "__NetEthEnc28j60.h"
#include "recources.h"

#define Net_Ethernet_28j60_HALFDUPLEX 0
#define Net_Ethernet_28j60_FULLDUPLEX 1


// mE ehternet NIC pinout
sfr sbit Net_Ethernet_28j60_Rst at LATB1_bit; // for writing to output pin always use latch
sfr sbit Net_Ethernet_28j60_CS at LATB0_bit; // for writing to output pin always use latch
sfr sbit Net_Ethernet_28j60_Rst_Direction at TRISB1_bit;
sfr sbit Net_Ethernet_28j60_CS_Direction at TRISB0_bit;



unsigned char myMacAddr[6] = {0x00, 0x14, 0xA5, 0x76, 0x19, 0x3f}; // my MAC address
unsigned char myIpAddr[4] = {192, 168, 1, 150 }; // my IP address
unsigned char gwIpAddr[4] = {192, 168, 1, 1 }; // gateway (router) IP address
unsigned char ipMask[4] = {255, 255, 255, 0 }; // network mask (for example : 255.255.255.0)
unsigned char dnsIpAddr[4] = {8, 8, 8, 8 }; // DNS server IP address

unsigned char getRequest[15]; // HTTP request buffer
unsigned char dyna[31] ; // buffer for dynamic response


////////////////////////////////////////////////////////////////////////////////
// Values of global variables in _Lib_NetEthEnc28j60_Defs.c file.
/*
NUM_OF_SOCKET_28j60 = 7; // Max number of socket We can open.
TCP_TX_SIZE_28j60 = 1024; // Size of Tx buffer in RAM.
MY_MSS_28j60 = 30; // Our maximum segment size.
SYN_FIN_WAIT_28j60 = 3; // Wait-time (in second) on remote SYN/FIN segment.
RETRANSMIT_WAIT_28j60 = 3; // Wait-time (in second) on ACK which we expect.
*/
////////////////////////////////////////////////////////////////////////////////




void TCP_Init(void) {
Net_Ethernet_28j60_stackInitTCP();

SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, _SPI_PRESCALE_SEC_1, _SPI_PRESCALE_PRI_4,
_SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_IDLE_2_ACTIVE);

Net_Ethernet_28j60_Init(myMacAddr, myIpAddr, 1); // init ethernet board
// dhcp will not be used here, so use preconfigured addresses
Net_Ethernet_28j60_confNetwork(ipMask, gwIpAddr, dnsIpAddr);
Delay_ms(1000);
}


And i did not specify SPI1 mapping anywhere else.

So as u mentioned i will check with higher baud rate by changing pre-scale value.
Kindly check the library, i assume that may be some minor changes in library or code will solve the issue.


Regards,
Nikhil


Top
 Profile  
 
PostPosted: 27 Jun 2017 10:24 
Offline
User avatar

Joined: 21 Mar 2017 16:57
Posts: 196
Hello,

I was suggesting you to use lower baud rate, not higher. You can do this by increasing the divider in your SPI INIT function:

SPI1_Init_Advanced(_SPI_MASTER, _SPI_8_BIT, _SPI_PRESCALE_SEC_1, _SPI_PRESCALE_PRI_16,
_SPI_SS_DISABLE, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_IDLE_2_ACTIVE);


...instead of the original SPI_Init which contains _SPI_PRESCALE_PRI_4, dividing the SPI clock with 4. You can try even bigger values for the divider (64), experiment a bit with the primary and secondary prescale as the SPI tends to be sensitive to long signal paths, poorly designed paths, so if it's too fast it might simply fail. After all I told you that I can't guarantee you it will work, since the library doesn't include that MCU by default - so it's either not supported fully, or it's not tested. I will ask our developers to look into that, but in the meanwhile, we should try out few different settings for the SPI and see if that helps.

Finally - do you use a custom made PCB, or you some factory-made product with the dsPIC33EP ? If so - which one ? When I was speaking about routing the SPI lines, I was talking about physical paths of the SPI signals - I wanted to make sure that the ENC chip is properly connected to the MCU's SPI pins, in case you were making your own PCB. Also if you did your own PCB, I'd like to take a look at the schematics, if possible...

I hope some of this will work for you, looking forward to your answer,

Best regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


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:
Jump to: