28j60 + pic 18f452. Test program does not work. Help

General discussion on mikroC.
Author
Message
svidok
Posts: 6
Joined: 14 Nov 2011 20:37

28j60 + pic 18f452. Test program does not work. Help

#1 Post by svidok » 14 Nov 2011 20:55

Help please. The program does not work. I will not understand where error.


#define Spi_Ethernet_HALFDUPLEX 0
#define Spi_Ethernet_FULLDUPLEX 1

unsigned char MacAddr[6] = {0x00, 0x14, 0xA5, 0x76, 0x19, 0x3f} ; // my MAC address
unsigned char IpAddr[4] = {192, 168, 1, 60 } ; // my IP address

unsigned char destIpAddr[4]; // IP address

unsigned char transmit = 0 ;
unsigned int destPortNum = 0 ;
char udpStr[16] = "PORTB=" ;

#define putConstString Spi_Ethernet_putConstString
#define putString Spi_Ethernet_putString

unsigned int Spi_Ethernet_UserTCP(unsigned char *remoteHost, unsigned int remotePort, unsigned int localPort, unsigned int reqLength)
{
return(0) ;
}


unsigned int Spi_Ethernet_UserUDP(unsigned char *remoteHost, unsigned int remotePort, unsigned int destPort, unsigned int reqLength)
{
switch(Spi_Ethernet_getByte())
{
// begin command
case 'b':
case 'B':
transmit = 1 ; // set transmission flag
memcpy(destIPAddr, remoteHost, 4) ; // save remote host IP addr
destPortNum = remotePort ; // save remote host port number
Spi_Ethernet_putByte('B') ; // reply with 'Begin' string
Spi_Ethernet_putByte('e') ;
Spi_Ethernet_putByte('g') ;
Spi_Ethernet_putByte('i') ;
Spi_Ethernet_putByte('n') ;
return(5) ; // 5 bytes to transmit

// end command
case 'e':
case 'E':
transmit = 0 ; // clear transmission flag
Spi_Ethernet_putByte('E') ; // reply with 'End'
Spi_Ethernet_putByte('n') ;
Spi_Ethernet_putByte('d') ;
return(3) ; // 3 bytes to transmit

// error
default:
Spi_Ethernet_putByte('?') ;
return(1) ;
}
}

void main()
{
ADCON1 = 0x0F; ; // ADC convertors

PORTA = 0 ;
TRISA = 0xff ; // set PORTA as input

PORTB = 0 ;
TRISB = 0xff ; // set PORTB as input

PORTD = 0 ;
TRISD = 0 ; // set PORTD as output

PORTE = 0; // Initialize PORTB
TRISE = 0;

Spi_Init();
Spi_Ethernet_Init(&PORTC, 0, &PORTC, 1, MacAddr, IpAddr, Spi_Ethernet_FULLDUPLEX) ;

while(1) // do forever
{
Spi_Ethernet_doPacket() ; // process incoming Ethernet packets
if(transmit) // transmit one UDP packet per second
{
ByteToStr(PORTB, udpStr + 6) ; // read PORTB value and convert to string
Spi_Ethernet_sendUDP(destIpAddr, 3456, destPortNum, udpStr, sizeof(udpStr)) ;
PORTE = ~PORTE;
Delay_ms(1000);
}
}
}

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: 28j60 + pic 18f452. Test program does not work. Help

#2 Post by janko.kaljevic » 15 Nov 2011 17:33

Hello,

Please can you post your entire project here, so we can inspect it.

Best regards.

svidok
Posts: 6
Joined: 14 Nov 2011 20:37

Re: 28j60 + pic 18f452. Test program does not work. Help

#3 Post by svidok » 16 Nov 2011 06:28

This is my project file.
Attachments
test_ethernet.rar
(111.21 KiB) Downloaded 247 times

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: 28j60 + pic 18f452. Test program does not work. Help

#4 Post by janko.kaljevic » 16 Nov 2011 15:29

Hello,

I strongly suggest to upgrade your compiler to latest version of compiler.
Newer version has much improved Ethernet library and also TCP/IP library.

You can use import function from new compiler and check for necessary modifications in Migration document.
This way you will get latest compiler with more features and you will be able to develop projects with those new features.

Best regards.

svidok
Posts: 6
Joined: 14 Nov 2011 20:37

Re: 28j60 + pic 18f452. Test program does not work. Help

#5 Post by svidok » 16 Nov 2011 18:08

So what went wrong? I tried the new version of the compiler - the same result. Help me please understand. I apologize in advance for my English. I live in the city of Kharkov in the Ukraine. I speak Russian. In matters related to the ethernet I started. So do not kick me greatly.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: 28j60 + pic 18f452. Test program does not work. Help

#6 Post by janko.kaljevic » 17 Nov 2011 12:23

Hello,

Have you tried our example for Ethernet?
Also can you explain what is not working at your example?

Best regards.

svidok
Posts: 6
Joined: 14 Nov 2011 20:37

Re: 28j60 + pic 18f452. Test program does not work. Help

#7 Post by svidok » 17 Nov 2011 13:09

Hello. For Ethernet I tried your example. Works, but does not suit me. I must realize questioning of port of comptroller at stated intervals and delivery in Ethernet through UDP. In my example at the input of "B" through UDP a terminal comes answer as a line of "Bigin". Nothing takes place further. Questioning of port and delivery of his value is not present. Beforehand thank you.

svidok
Posts: 6
Joined: 14 Nov 2011 20:37

Re: 28j60 + pic 18f452. Test program does not work. Help

#8 Post by svidok » 19 Nov 2011 19:40

1. Your example is a server Ethernet with my device works fine, but does not suit me.
2. I need the value of port B Pic 18F452 issue through UDP to computer with a certain period.
3. What works in the example: after the character "B" from UDP terminal MikroC, the device the response is "begin".
4. What the example does not work - nothing else works. Issuance of the port is not happening. I think, that don't work function Spi_Ethernet_sendUDP.

WHY ??????

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: 28j60 + pic 18f452. Test program does not work. Help

#9 Post by janko.kaljevic » 21 Nov 2011 17:18

Hello,

Please can you post your project here. The one that you are having troubles with.

Best regards.

svidok
Posts: 6
Joined: 14 Nov 2011 20:37

Re: 28j60 + pic 18f452. Test program does not work. Help

#10 Post by svidok » 21 Nov 2011 18:54

Hello,

My project file is posted in this thread above.

Best regards.

saas123qa
Posts: 9
Joined: 27 Nov 2011 19:05

Re: 28j60 + pic 18f452. Test program does not work. Help

#11 Post by saas123qa » 28 Nov 2011 05:32

I have problem with Spi_Ethernet_sendUDP when I am trying to use that function along with serial Ethernet Board, it do not send anything to the PC. The board is working with other functions.

Do you have any working code that implement Spi_Ethernet_sendUDP with PIC18F4550

Thanks

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: 28j60 + pic 18f452. Test program does not work. Help

#12 Post by janko.kaljevic » 29 Nov 2011 17:56

saas123qa wrote:I have problem with Spi_Ethernet_sendUDP when I am trying to use that function along with serial Ethernet Board, it do not send anything to the PC. The board is working with other functions.

Do you have any working code that implement Spi_Ethernet_sendUDP with PIC18F4550

Thanks
Hello,

Please can you tell me which Ethernet library are you using?
Can you confirm that your program exits Spi_Ethernet_sendUDP routine. You can check this in ICD.
Also are you incrementing Net_Ethernet_28j60_userTimerSec variable?

Best regards.

saas123qa
Posts: 9
Joined: 27 Nov 2011 19:05

Re: 28j60 + pic 18f452. Test program does not work. Help

#13 Post by saas123qa » 30 Nov 2011 05:11

I am using the library that come with MikroC Ver 5.3

I confirm that the program exits Spi_Ethernet_sendUDP , because it excute the commands after Spi_Ethernet_sendUDP

No, I am not useing neither Net_Ethernet_28j60_userTimerSec nor SPI_Ethernet_userTimerSec

saas123qa
Posts: 9
Joined: 27 Nov 2011 19:05

Re: 28j60 + pic 18f452. Test program does not work. Help

#14 Post by saas123qa » 04 Dec 2011 05:16

What is the benifit of using Net_Ethernet_28j60_userTimerSec or SPI_Ethernet_userTimerSec?

it is not much clear in the Help

do you have any full example of using Spi_Ethernet_sendUDP

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: 28j60 + pic 18f452. Test program does not work. Help

#15 Post by janko.kaljevic » 05 Dec 2011 16:43

Hello,

Those two variables are same and their function is same.
The only difference between them is that one is from new Ethernet library and other is from old SPI_Ethernet library.

Best regards.

Post Reply

Return to “mikroC General”