CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Communication Between 2 Embedded Ethernet Boards

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dorsiareservations



Joined: 16 Nov 2006
Posts: 10

View user's profile Send private message

Communication Between 2 Embedded Ethernet Boards
PostPosted: Thu Nov 16, 2006 11:38 am     Reply with quote

I am currently using the latest version of the CCS Compiler and the Ported microchip stack, along with 2 embedded ethernet boards. My goal is to simply communicate between the two boards using two UDP Sockets on each board. My program is simple, it simply sends a packet, does a stacktask(), recieves a packet, does a stacktask(), and repeats. However, the two boards will not recieve packets from one another.

Here is what is happening:

1)I can send packets back and forth from a laptop to an embedded board no problem what so ever.
2)I can view the packets being sent from each ethernet board to the other through etherreal. All the Information looks correct, MAC Addresses, ports, IP's, etc.
3)I have a timer counting how many packets per second are being transmitted, which is near 1000. If I plug in another embedded ethernet card (The one that I am trying to communicate with), the packets drop to 500 on each board. This makes sense, because it has to process the recieving packets and can not transmit as many.
4)If I unplug the board, or put in a different MAC address or IP address, the packets transmitted stay at 1000/second. This makes sense, because the board will not have to process incoming packets.

So Judging from the the fact that the packet rate drops when I transmit to the right mac and IP, I know the board is recieving packets. In the code I have narrowed it down, and I have found that it never enters the "UDPisGetReady(Socket)" loop. Can anyone offer a suggestion, or do they have working code for such a scenario? It would be much appreciated.

Code:

#define STACK_USE_ICMP  0
#define STACK_USE_ARP   0
#define STACK_USE_UDP   1

#define LOCAL_ID 7
#define REMOTE_ID   11
#define MAX_SOCKETS                     6
#define MAX_UDP_SOCKETS                 4

#include "ccstcpip.h"
#if STACK_USE_CCS_PICENS
#include "tcpip/mlcd.c"
#else
#include "tcpip/dlcd.c"
#endif

#define UDP_SOURCE_PORT 1024
#define UDP_DESTINATION_PORT  1025
#define UDP_NUM_LISTEN_SOCKETS   2
UDP_SOCKET last_rx_socket=INVALID_UDP_SOCKET;
unsigned int16 totalcount=0;
unsigned int16 totalcount2=0;

void UDPRxTask(void)
{
 static UDP_SOCKET socket=INVALID_UDP_SOCKET;
 int8 i;
 char c;
 if (socket==INVALID_UDP_SOCKET)
 {
    socket=UDPOpen(UDP_SOURCE_PORT,NULL,INVALID_UDP_SOCKET);
    if (socket==INVALID_UDP_SOCKET)
    {
      // UDPClose(socket);
       printf("\r\nUDP Rcv SOCKET Jacked Up");
    }
    else
    {
       printf("\r\nUDP SOCKET %U OPEN FOR LISTENING", socket);
    }
 }
 if (UDPIsGetReady(socket))
 {
    totalcount++;
    output_toggle(PIN_B5);
    while(UDPGet(&c))
    {
       i=c;
    }
    UDPDiscard();
 }
}

void UDPTxTask(void) {
 NODE_INFO remote_info;
 static int8 button;
 static int8 tx_socket=INVALID_UDP_SOCKET;
    // remote node mac and IP
    remote_info.IPAddr.v[0]=192;
    remote_info.IPAddr.v[1]=168;
    remote_info.IPAddr.v[2]=100;
    remote_info.IPAddr.v[3]=0x12;
    remote_info.MACAddr.v[0]=0x01;
    remote_info.MACAddr.v[1]=0x02;
    remote_info.MACAddr.v[2]=0x03;
    remote_info.MACAddr.v[3]=0x04;
    remote_info.MACAddr.v[4]=0x05;
    remote_info.MACAddr.v[5]=0x12;

 if (tx_socket==INVALID_UDP_SOCKET)
 {
    tx_socket=UDPOpen(1010, &remote_info, UDP_DESTINATION_PORT);
    printf("\r\nUDP SOCKET %U OPEN FOR sending", tx_socket);
 }
 else
 {
    if (UDPIsPutReady(tx_socket))
    {
       printf(UDPPut, "\r\nBUTTON%U  ",++button);
       UDPFlush();
      // UDPClose(tx_socket);
      output_toggle(PIN_A5);
       totalcount2++;
     }
 }
}

int16 time_ms=0;
#int_TIMER2
TIMER2_isr()
{
 time_ms++;
}

void main(void) {
int temp=0;
printf("\n\rStarting");
 setup_timer_2(T2_DIV_BY_16,195,16);// Timer2 interrupts every 5 ms
 enable_interrupts(INT_TIMER2);
 enable_interrupts(GLOBAL);
 MACAddrInit();
 IPAddrInit();
 init_user_io();
 lcd_init();
 printf(lcd_putc,"\fCCS UDP TUTORIAL\nLISTENING");
 StackInit();

 while(TRUE)
 {
    StackTask();
    UDPRxTask();
    StackTask();
    UDPTxTask();
    if (time_ms>100)
    {
       printf(lcd_putc,"\fTot Rcvd=%lu",totalcount);
       printf(lcd_putc,"\nTot Txed=%lu",totalcount2);
       output_toggle(PIN_B4);
       totalcount=0;
       totalcount2=0;
       time_ms=0;
    }
 }
}




Obviously, the ports, MAC addresses and IP's are reversed in the code that goes on the other board. Please help Im at my wits end. Im ver close to moving to realtek and hi-tecc.
Darren Rook



Joined: 06 Sep 2003
Posts: 287
Location: Milwaukee, WI

View user's profile Send private message Send e-mail

PostPosted: Thu Nov 16, 2006 1:03 pm     Reply with quote

A few things...

a.) UDP and UDPOpen() are very poorly documented in Microchip's Application Note. In fact, you take anything said with that Application Note with a grain of salt as it was written 4 years ago (and hasn't been updated as the stack has gotten updated) and contains many errors. Therefore you really do need to read the stack source code to get an idea of how it really works.

b.) The port you are using in the tx task is a different port being used in the rx task.

c.) You are not correctly using StackTask(). There should only be one StackTask() in your main loop. I thought that if there was data in the RX buffer and StackTask() was called it would clear the RX buffer to make space for the next packet, but it seems like the later versions of the stack don't do that anymore so I'm not sure if that's a valid comment.
_________________
I came, I saw, I compiled.
dorsiareservations



Joined: 16 Nov 2006
Posts: 10

View user's profile Send private message

PostPosted: Thu Nov 16, 2006 2:16 pm     Reply with quote

Darren,

In regards to the the UDPOpen function, what specifically am I doing wrong then? This is a modified version of the CCS example 12a(I think). The one that communicates with the computer.

In regards to the ports being different, I am aware of that. The code for the other ethernet board is the same thing, with the mac addresses, ips, and ports switched. Hence, the recieving port on board A is the destination port on board B, etc.

My prior code to this had the stacktask() used only once in the main loop. The results were exactly the same.
dorsiareservations



Joined: 16 Nov 2006
Posts: 10

View user's profile Send private message

PostPosted: Thu Nov 16, 2006 2:23 pm     Reply with quote

On another note, it would be nice to see this stuff built into the compiler, perhaps in the project wizard? Hint Hint.
dorsiareservations



Joined: 16 Nov 2006
Posts: 10

View user's profile Send private message

PostPosted: Thu Nov 16, 2006 2:36 pm     Reply with quote

here are 2 packets captured from etherreal. 1 from each embedded ethernet board.

Code:


No.     Time        Source                Destination           Protocol Info
      1 0.000000    192.168.100.7         192.168.100.18        UDP      Source port: 1010  Destination port: 1018

Frame 1 (60 bytes on wire, 60 bytes captured)
    Arrival Time: Nov 17, 2006 00:18:06.465293000
    Time delta from previous packet: 0.000000000 seconds
    Time since reference or first frame: 0.000000000 seconds
    Frame Number: 1
    Packet Length: 60 bytes
    Capture Length: 60 bytes
    Protocols in frame: eth:ip:udp:data
Ethernet II, Src: 01:02:03:04:05:07, Dst: 01:02:03:04:05:12
    Destination: 01:02:03:04:05:12 (01:02:03:04:05:12)
    Source: 01:02:03:04:05:07 (01:02:03:04:05:07)
    Type: IP (0x0800)
    Trailer: 00000000000000
Internet Protocol, Src Addr: 192.168.100.7 (192.168.100.7), Dst Addr: 192.168.100.18 (192.168.100.18)
    Version: 4
    Header length: 20 bytes
    Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00)
        0000 00.. = Differentiated Services Codepoint: Default (0x00)
        .... ..0. = ECN-Capable Transport (ECT): 0
        .... ...0 = ECN-CE: 0
    Total Length: 39
    Identification: 0x3a04 (14852)
    Flags: 0x00
        0... = Reserved bit: Not set
        .0.. = Don't fragment: Not set
        ..0. = More fragments: Not set
    Fragment offset: 0
    Time to live: 100
    Protocol: UDP (0x11)
    Header checksum: 0xd357 (correct)
    Source: 192.168.100.7 (192.168.100.7)
    Destination: 192.168.100.18 (192.168.100.18)
User Datagram Protocol, Src Port: 1010 (1010), Dst Port: 1018 (1018)
    Source port: 1010 (1010)
    Destination port: 1018 (1018)
    Length: 19
    Checksum: 0x0000 (none)
Data (11 bytes)

0000  01 02 03 04 05 12 01 02 03 04 05 07 08 00 45 00   ..............E.
0010  00 27 3a 04 00 00 64 11 d3 57 c0 a8 64 07 c0 a8   .':...d..W..d...
0020  64 12 03 f2 03 fa 00 13 00 00 0d 0a 42 55 54 54   d...........BUTT
0030  4f 4e 34 20 20 00 00 00 00 00 00 00               ON4  .......



No.     Time        Source                Destination           Protocol Info
      2 0.000026    192.168.100.18        192.168.100.7         UDP      Source port: 1010  Destination port: 1007

Frame 2 (60 bytes on wire, 60 bytes captured)
    Arrival Time: Nov 17, 2006 00:18:06.465319000
    Time delta from previous packet: 0.000026000 seconds
    Time since reference or first frame: 0.000026000 seconds
    Frame Number: 2
    Packet Length: 60 bytes
    Capture Length: 60 bytes
    Protocols in frame: eth:ip:udp:data
Ethernet II, Src: 01:02:03:04:05:12, Dst: 01:02:03:04:05:07
    Destination: 01:02:03:04:05:07 (01:02:03:04:05:07)
    Source: 01:02:03:04:05:12 (01:02:03:04:05:12)
    Type: IP (0x0800)
    Trailer: 0000000000
Internet Protocol, Src Addr: 192.168.100.18 (192.168.100.18), Dst Addr: 192.168.100.7 (192.168.100.7)
    Version: 4
    Header length: 20 bytes
    Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00)
        0000 00.. = Differentiated Services Codepoint: Default (0x00)
        .... ..0. = ECN-Capable Transport (ECT): 0
        .... ...0 = ECN-CE: 0
    Total Length: 41
    Identification: 0x2dc7 (11719)
    Flags: 0x00
        0... = Reserved bit: Not set
        .0.. = Don't fragment: Not set
        ..0. = More fragments: Not set
    Fragment offset: 0
    Time to live: 100
    Protocol: UDP (0x11)
    Header checksum: 0xdf92 (correct)
    Source: 192.168.100.18 (192.168.100.18)
    Destination: 192.168.100.7 (192.168.100.7)
User Datagram Protocol, Src Port: 1010 (1010), Dst Port: 1007 (1007)
    Source port: 1010 (1010)
    Destination port: 1007 (1007)
    Length: 21
    Checksum: 0x0000 (none)
Data (13 bytes)

0000  01 02 03 04 05 07 01 02 03 04 05 12 08 00 45 00   ..............E.
0010  00 29 2d c7 00 00 64 11 df 92 c0 a8 64 12 c0 a8   .)-...d.....d...
0020  64 07 03 f2 03 ef 00 15 00 00 0d 0a 42 55 54 54   d...........BUTT
0030  4f 4e 31 39 39 20 20 00 00 00 00 00               ON199  .....



Darren Rook



Joined: 06 Sep 2003
Posts: 287
Location: Milwaukee, WI

View user's profile Send private message Send e-mail

PostPosted: Thu Nov 16, 2006 3:05 pm     Reply with quote

Your UDPOpen() in the RX task is listening to UDP_SOURCE_PORT. Your UDPOpen() in the TX task is transmitting to UDP_DESTINATION_PORT. Those ports don't match, that's why your RX task doesn't receive anything.
_________________
I came, I saw, I compiled.
dorsiareservations



Joined: 16 Nov 2006
Posts: 10

View user's profile Send private message

PostPosted: Fri Nov 17, 2006 7:38 am     Reply with quote

How do they not match? Am I missing something? Can you be a little more in depth in your explination because I thought I had this worked out. Obviously I am missing something. You are aware that there are 2 different boards, right? Here is the socket/port setup.

Code:

Board A:

     Socket 1:(transmit socket)
                  Destination Port: 1018
                  Source Port:       1010(doesnt matter really)

     Socket 2:(recieve Socket)
                  Source Port:       1007
                  Destination port:  NULL


Board B:

     Socket 1:(transmit socket)
                  Destination Port: 1007
                  Source Port:       1010(doesnt matter really)

     Socket 2:(recieve Socket)
                  Source Port:       1018
                  Destination port:  NULL





Is that not right? Board A has to listen on the port that Board B is sending to, and vice versa?
dorsiareservations



Joined: 16 Nov 2006
Posts: 10

View user's profile Send private message

PostPosted: Fri Nov 17, 2006 9:28 am     Reply with quote

Disregard the port 1024 and 1025 in the first post. I changed the ports for clarity between posts....My mistake. The info from the etherreal dump is correct.
Darren Rook



Joined: 06 Sep 2003
Posts: 287
Location: Milwaukee, WI

View user's profile Send private message Send e-mail

PostPosted: Mon Nov 20, 2006 9:17 am     Reply with quote

BTW your 'remote_info' isn't static, it's possible the values got corrupted.

Edit: Never mind, that's fine.
_________________
I came, I saw, I compiled.
dorsiareservations



Joined: 16 Nov 2006
Posts: 10

View user's profile Send private message

PostPosted: Wed Nov 22, 2006 11:38 am     Reply with quote

I did some further research, and captured a Packet that the computer sends to the microcontroller board. (The ports are different again, but they are correct....)

Once again, this is an embedded baord and a computer sending and recieving packets simultaneously to each other through a switch. This is working fine. The packet that the microcontroller sends to the computer is virtual the same as the ones show above with a different MAC and IP and port, of course.

The ONLY major differences I found were the flags, and the checksum. The checksum is not zero, and the flag has the "dont fragment" flag set. Here is the packet.

Any more ideas would be greatly appreciated.
Code:

No.     Time        Source                Destination           Protocol Info
  10358 17.259944   192.168.100.11        192.168.100.7         UDP      Source port: 32768  Destination port: 1024

Frame 10358 (48 bytes on wire, 48 bytes captured)
    Arrival Time: Nov 22, 2006 00:21:11.651287000
    Time delta from previous packet: 0.000344000 seconds
    Time since reference or first frame: 17.259944000 seconds
    Frame Number: 10358
    Packet Length: 48 bytes
    Capture Length: 48 bytes
    Protocols in frame: eth:ip:udp:data
Ethernet II, Src: 00:0b:97:27:b5:ba, Dst: 01:02:03:04:05:07
    Destination: 01:02:03:04:05:07 (01:02:03:04:05:07)
    Source: 00:0b:97:27:b5:ba (00:0b:97:27:b5:ba)
    Type: IP (0x0800)
Internet Protocol, Src Addr: 192.168.100.11 (192.168.100.11), Dst Addr: 192.168.100.7 (192.168.100.7)
    Version: 4
    Header length: 20 bytes
    Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00)
        0000 00.. = Differentiated Services Codepoint: Default (0x00)
        .... ..0. = ECN-Capable Transport (ECT): 0
        .... ...0 = ECN-CE: 0
    Total Length: 34
    Identification: 0x0003 (3)
    Flags: 0x04 (Don't Fragment)
        0... = Reserved bit: Not set
        .1.. = Don't fragment: Set
        ..0. = More fragments: Not set
    Fragment offset: 0
    Time to live: 64
    Protocol: UDP (0x11)
    Header checksum: 0xf164 (correct)
    Source: 192.168.100.11 (192.168.100.11)
    Destination: 192.168.100.7 (192.168.100.7)
User Datagram Protocol, Src Port: 32768 (32768), Dst Port: 1024 (1024)
    Source port: 32768 (32768)
    Destination port: 1024 (1024)
    Length: 14
    Checksum: 0x4983 (incorrect, should be 0x2a60)
Data (6 bytes)

0000  01 02 03 04 05 07 00 0b 97 27 b5 ba 08 00 45 00   .........'....E.
0010  00 22 00 03 40 00 40 11 f1 64 c0 a8 64 0b c0 a8   ."..@[email protected]...
0020  64 07 80 00 04 00 00 0e 49 83 74 65 73 74 20 34   d.......I.test 4
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group