EmbDev.net

Forum: µC & Digital Electronics Ethernet with PIC18F67J60


von Pasjul (Guest)


Rate this post
useful
not useful
Hey guys,

im having trouble with my PIC18F67J60 µC. Im trying to send an 
ethernetpacket every second or so. To record any packets on the ethernet 
im using wireshark, i pluged the network cable from the develpment board 
directly into my computer. I just get some DHCP-discover packets from my 
computer but no packets from the PIC18 at all! I read the documentation 
4times already and my resulting code looks like this:
1
 
2
#include <xc.h>                 // XC8 General Include File 
3
#include <stdint.h>             // For uint8_t definition 
4
#include <stdbool.h>            // For true/false definition 
5
6
#pragma config WDT = OFF        // WDT disabled (control is placed on SWDTEN bit) 
7
#pragma config XINST = OFF      // Turn off support for extended instruction set 
8
#pragma config FOSC = HS        // HS oscillator 
9
10
unsigned int counter1 = 0; 
11
int x = 0; 
12
unsigned char packetDest [6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // Multicast 
13
unsigned char packetSource [6] = {0xD8,0xD3,0x85,0x1F,0x11,0x01}; 
14
unsigned char packetTypeIP [2] = {0x08,0x00}; 
15
unsigned char packetIPHeader [12] = {0x45, 0x00, 0x00, 0x32, 0x11, 0xF7, 0x00, 0x00, 0x01, 0x11, 0x00, 0x00}; 
16
unsigned char packetIPSource [4] = {0xC0, 0xA8, 0x01,0x06}; 
17
unsigned char packetIPDest [4] = {0xE0, 0x00, 0x00,0xFC }; //broadcast 
18
  
19
  
20
21
void interrupt high_isr(void) 
22
{ 
23
    counter1++;                  //flash LED 
24
    if(counter1 == 20000) 
25
    { 
26
        ETXSTH = 0x00; 
27
        ETXSTL = 0x40; 
28
        EDATA = 0; 
29
        for (x=0; x<6 ;x++){ 
30
            EDATA = packetDest[x]; 
31
        } 
32
        for (x=0; x<6 ;x++){ 
33
            EDATA = packetSource[x]; 
34
        } 
35
        for (x=0; x<2 ;x++){ 
36
            EDATA = packetTypeIP[x]; 
37
        } 
38
        for (x=0; x<12 ;x++){ 
39
            EDATA = packetIPHeader[x]; 
40
        } 
41
        for (x=0; x<4 ;x++){ 
42
            EDATA = packetIPSource[x]; 
43
        } 
44
        for (x=0; x<4 ;x++){ 
45
            EDATA = packetIPDest[x]; 
46
        } 
47
        for (x=0; x<30 ;x++){ 
48
            EDATA = 0x01; 
49
        } 
50
        ECON1bits.TXRST = 1; 
51
        PORTBbits.RB4 = !PORTBbits.RB4;     //toggle LED        counter1 = 0; 
52
53
    } 
54
    INTCONbits.TMR0IF = 0;      // clear interrupt-flag 
55
} 
56
57
void low_priority interrupt low_isr(void){ 
58
    // will never happen 
59
} 
60
61
void main(void) 
62
{ 
63
64
    INTCONbits.GIE = 1;        // enable global interrupts 
65
    INTCONbits.TMR0IF = 0;     // clear interrupt-flag 
66
    INTCONbits.TMR0IE = 1;     // enable interrupt for timer0 
67
    T0CONbits.T0CS = 0;        // clock source: 0 = internal clock, 1 = external clock 
68
    T0CONbits.TMR0ON = 1;       // switch timer0 on 
69
  
70
    //Ethernet Setup 
71
     ECON2bits.ETHEN = 1; 
72
     ERXST = 0; 
73
     ERXND = 0x3F; 
74
     ERXRDPTL = 0x3F; 
75
     ERXRDPTH = 0x00; 
76
77
    ECON2bits.AUTOINC = 1; 
78
    ECON1bits.TXRST = 0; 
79
    ECON1bits.RXRST = 0; 
80
    ECON1bits.CSUMEN = 0; 
81
    ECON1bits.RXEN = 0;    // dont receiv, i just wanna send 
82
    while(!ESTATbits.PHYRDY); 
83
    TRISBbits.RB4 = 0;                 // init LED 
84
    PORTBbits.RB4 = 0;                  // 
85
    PORTBbits.RB4 = !PORTBbits.RB4;     // 
86
87
    MACON1bits.MARXEN = 1; 
88
    MACON3bits.PADCFG0 = 1; 
89
    MACON3bits.PADCFG1 = 1; 
90
    MACON3bits.PADCFG2 = 1; 
91
    MACON3bits.TXCRCEN = 1; 
92
    MACON3bits.FULDPX = 0; 
93
    MACON3bits.FRMLNEN = 1; // ? 
94
    MACON4bits.DEFER = 1; 
95
    MAMXFL = 1518; 
96
    MABBIPG = 0x12; 
97
    MAIPGL = 0x12; 
98
    MAIPGH = 0xC; 
99
    MAADR1 = 0x01; 
100
    MAADR2 = 0x11; 
101
    MAADR3 = 0x1F; 
102
    MAADR4 = 0x85; 
103
    MAADR5 = 0xD3; 
104
    MAADR6 = 0xD8; 
105
106
107
108
    while(1);}

Im using a development board created by Olimex. Here is the datasheet if 
needed:
https://www.olimex.com/Products/PIC/Proto/PIC-P67J60/resources/PIC-P67J60.pdf

Please help!

von fchk (Guest)


Rate this post
useful
not useful
Use the Microchip TCP/IP Stack! No need to duplicate work.

von Pasjul (Guest)


Rate this post
useful
not useful
I could not finde the TCP/IP Stack in the Datasheet from the 
PIC18F97J60.
Could you maybe give me link or so?

von fchk (Guest)


Rate this post
useful
not useful

von Pasjul (Guest)


Rate this post
useful
not useful
Thank you for the link. I googled before but couldnt find anything.

But im still not able to send a package via TCP or UDP after several 
hours of try and error...

I tried to flash a precompiled demo-app like discribed in the 
documentation i found with your link. But there the first problem 
arises; There isnt ANY demo-app or demo-code for the pic18f67J60, the 
closest match i found was pic18f97f60 (this demo-app didnt work of 
course...).
Then i tried to program it all by myself using the udp.h and tcp.h. I 
got nothing but errors, i wasnt able to even compile my code. The 
biggest problem was a file called "tcpipconfig.h", which should be 
generated by the "tcpip configuration wizard" (like described in the 
documentation). But still no luck...

Then i again started to search for some simple examples, but i just cant 
find anything!

Any ideas where i can find a simple project for my pic18f67j60 which 
creates a simple packet? I just want to send one lousy packet, it cant 
be this hard!

Im really desperate... :-(

von fchk (Guest)


Rate this post
useful
not useful
1. PIC18F97J60, PIC18F87J60, and PIC18F67J60 only differ in the package 
(100/80/64 pins), the bigger packages have more io ports and more UART 
and MSSP units. Otherwise it's basically the same chip.

2. Use known-good hardware! Buy or borrow a Microchip Eval board and try 
the demo app on that hardware.

3. I've used the stack with MPLAB 8 (the old one, not the newer MPLAB X) 
and C18 compiler version 3.34. (which is NOT the newest one). I can't 
tell you if the stack works at all with Hitech or the new XC8 compiler. 
In doubt, use the mature, well-tested environment.

4. Try to strip down the code, remove everything you don't need, and 
have a look at the UDP client and UDP server example code.

5. When you have working code on the Microchip eval board, move on to 
your custom hardware.

6. Use the microchip.com forum if you can't get beyond step 4. They 
obviously only can help you if you are using a Microchip devboard 
(preferrably an PICDEM.net 2).

fchk

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.