Ethernet firmware on MX7

Post Reply
jools
Posts: 11
Joined: Sun Apr 12, 2015 5:53 am

Ethernet firmware on MX7

Post by jools » Sun May 28, 2017 3:29 am

I've pulled my MX7 out of hibernation and I'm trying to use the UDPSendReceiveString example in the Arduino IDE to send a UDP packet to my M/C using a Processing sketch provided. The code looks like this:

Code: Select all

/*
  UDPSendReceive.pde:
 This sketch receives UDP message strings, prints them to the serial port
 and sends an "acknowledge" string back to the sender

 A Processing sketch is included at the end of file that can be used to send
 and received messages for testing with a computer.

 created 21 Aug 2010
 by Michael Margolis

 This code is in the public domain.
 */


#include <SPI.h>         // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>         // UDP library from: bjoern@cs.stanford.edu 12/30/2008


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0x00, 0x18, 0x3E, 0x01, 0x81, 0x78
};
IPAddress ip(192, 168, 0, 177);

unsigned int localPort = 8888;      // local port to listen on

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char  ReplyBuffer[] = "acknowledged";       // a string to send back

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac, ip);
  Udp.begin(localPort);

  Serial.begin(9600);
}

void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize)
  {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i = 0; i < 4; i++)
    {
      Serial.print(remote[i], DEC);
      if (i < 3)
      {
        Serial.print(".");
      }
    }
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    // read the packet into packetBufffer
    Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
    Serial.println("Contents:");
    Serial.println(packetBuffer);

    // send a reply, to the IP address and port that sent us the packet we received
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();
  }
  delay(10);
}


/*
  Processing sketch to run with this example
 =====================================================

 // Processing UDP example to send and receive string data from Arduino
 // press any key to send the "Hello Arduino" message


 import hypermedia.net.*;

 UDP udp;  // define the UDP object


 void setup() {
 udp = new UDP( this, 6000 );  // create a new datagram connection on port 6000
 //udp.log( true ); 		// <-- printout the connection activity
 udp.listen( true );           // and wait for incoming message
 }

 void draw()
 {
 }

 void keyPressed() {
 String ip       = "192.168.1.177";	// the remote IP address
 int port        = 8888;		// the destination port

 udp.send("Hello World", ip, port );   // the message to send

 }

 void receive( byte[] data ) { 			// <-- default handler
 //void receive( byte[] data, String ip, int port ) {	// <-- extended handler

 for(int i=0; i < data.length; i++)
 print(char(data[i]));
 println();
 }
 */
I've got it all set up, but nothing seems to be going through. I scanned the Ethernet port on my laptop with WireShark to see if any packets were going through, but nothing is coming up. With that said, if the Ethernet port on the M/C isn't activated, I don't think the packets generated by Processing will ever even go across the NIC (on the laptop). I got into the docs for the MX7 and it said:

"In order to connect to and operate with an Ethernet network, the PIC32 microcontroller must be running network protocol stack firmware. Normally, the TCP/IP (Transmission Control Protocol/Internet Protocol) network protocol is used and “TCP/IP Stack” software must be used. The Microchip Applications Library, available for download from the Microchip web site, provides full protocol stack support compatible with the PIC32MX795 MAC and the LAN8720 PHY. Microchip also provides numerous example programs illustrating the use of their network protocol stack for various applications."

Does this mean I need to add/update the existing firmware (I have the most recent .hex file) in order for the Ethernet to work?

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: Ethernet firmware on MX7

Post by majenko » Sun May 28, 2017 11:22 am

It means you have to use the right library. The one you want, which is bundled with the core, is not the Ethernet library (which is for the Arduino Ethernet shield), but the (rather cryptically named) DEIPcK library.
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

jools
Posts: 11
Joined: Sun Apr 12, 2015 5:53 am

Re: Ethernet firmware on MX7

Post by jools » Sun May 28, 2017 3:20 pm

Thanks Majenko. Two things with that though, first I thought that the MX7 (and others like it) was compatible with Arduino code. The other thing, is that within the Arduino IDE, there are 3 sections, Built In Examples, Examples For Any Board, and Examples For The Cerebot MX7cK. This code came from the Examples For The Cerebot MX7cK section, so it should be good. Is that an error within the IDE (misplaced library)? Thanks again.

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: Ethernet firmware on MX7

Post by majenko » Sun May 28, 2017 3:41 pm

Not being a user of the Arduino IDE I can't say. I guess it's including all examples in all libraries included with the core and labelling them as "for the board".

Yes, your board is compatible with Arduino code. However your board does not have an Arduino Ethernet shield plugged into it. If you were to connect an Arduino Ethernet shield up to it (which you could do with jumper wires) then you could use Arduino code that is written for the Arduino Ethernet shield. However that is not what you are using.

This is not a question of whether the board you have is "compatible with Arduino code", but whether you are using the right library for the specific hardware peripherals you are using (namely the internal Ethernet peripheral in the MX795 chip and the ethernet PHY chip that is connected to it).
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

jools
Posts: 11
Joined: Sun Apr 12, 2015 5:53 am

Re: Ethernet firmware on MX7

Post by jools » Mon May 29, 2017 12:56 am

Yep the DEIPcK did the trick. A little confusing on the part of the Arduino IDE, but thanks for clearing it up! On a similar note, for anybody that may have issues getting it going, I had to manually assign a 192.168.x.x IP address in Windows in order to get it to work without going through a router (Comp. Ethernet port directly to MX7). With the router in the middle it assigned a NAT address itself and I didn't need to.

Post Reply