Global variables use 3115 bytes (152%) of dynamic memory, Error compiling for board Arduino Uno


#include <SPI.h>         // needed for Ethernet library communication with the W5100 (Arduino ver>0018)
#include <Ethernet2.h>
#include <utility/w5500.h>

#define RECPKTCOUNT 58
#define SNDPKTCOUNT 60

static int sbuflen=64; // length of data to send

// the MAC-address of myself
static byte myadr [6]={0xAF,0xFE,0xAF,0xFE,0xAF,0XFE};

// the MAC-address of my the linuxCNC-Master
//static byte radr [6]={0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
//static byte radr [6]={0x70,0x85,0xc2,0x89,0x68,0xb7};
//static byte radr [6]={0xb8,0x27,0xeb,0xd6,0x96,0x81};
static byte radr [6]={0xbc,0x5f,0xf4,0x7b,0xce,0x4d };

static int sendcount=0;   // packtes received 
static int reccount=0;    // packts sent
static int lastrec=0;     // last received packet-nr
static byte lastC;        // last state od imput-port C 
			  // (analog-input used as digital-input)

SOCKET s; 		  // socket that will be opened in RAW mode
static byte rbuf[1500+14];// receive buffer
static byte sbuf[1500+14];// send buffer
static int rbuflen; 	  // length of data to receive

// the setup runs once when you press reset
void setup() {                
 w5500.init();
 w5500.writeSnMR(s, SnMR::MACRAW);
 w5500.execCmdSn(s, Sock_OPEN);

	// first byte in IN packet
  pinMode(0, OUTPUT); // this is an output-pin
  pinMode(1, OUTPUT); // this is an output-pin
  pinMode(2, OUTPUT); // this is an output-pin
  pinMode(3, OUTPUT); // this is an output-pin
  pinMode(4, OUTPUT); // this is an output-pin
  pinMode(5, OUTPUT); // this is an output-pin
  pinMode(6, OUTPUT); // this is an output-pin
  pinMode(7, OUTPUT); // this is an output-pin

       // second byte in IN packet
  pinMode(8, OUTPUT); // this is an output-pin
  pinMode(9, OUTPUT); // this is an output-pin
//pinMode(10,OUTPUT); // this is an output-pin


      // first byte in OUT packet
  pinMode(A0, INPUT_PULLUP);  // set pull-up on analog pin 0 
  pinMode(A1, INPUT_PULLUP);  // set pull-up on analog pin 1 
  pinMode(A2, INPUT_PULLUP);  // set pull-up on analog pin 2 
  pinMode(A3, INPUT_PULLUP);  // set pull-up on analog pin 3 
  pinMode(A4, INPUT_PULLUP);  // set pull-up on analog pin 4 
  pinMode(A5, INPUT_PULLUP);  // set pull-up on analog pin 5 
  pinMode(A6, INPUT_PULLUP);  // set pull-up on analog pin 6 
  pinMode(A7, INPUT_PULLUP);  // set pull-up on analog pin 7 


  // put MAC-addresses into send-buffer
  for (int i=0; i<6; i++) sbuf[i]  =radr [i];
  for (int i=0; i<6; i++) sbuf[i+6]=myadr[i];
}


void send_pkt(){
  	memcpy(sbuf+SNDPKTCOUNT,&sendcount,2);
	// sbuf[20]=0x21;
 	// sending packet   // only  for DEBUGING
   	w5500.send_data_processing(s, sbuf, sbuflen);
   	w5500.execCmdSn(s, Sock_SEND_MAC);
        sendcount++;
	}


// the loop routine runs over and over again forever:
void loop() {
unsigned int     RxPacketSize;
 // check if we have received something
 rbuflen = w5500.getRXReceivedSize(s);
 if (rbuflen>0){
    w5500.recv_data_processing(s, rbuf, 2); // read the first two bytes
    w5500.execCmdSn(s, Sock_RECV);          // that tell us the lenght of the packet + 2
    RxPacketSize = rbuf[0];                 // hight byte
    RxPacketSize  <<= 8;                    //
    RxPacketSize  |=( rbuf[1] & 0x00FF);    // low byte
    RxPacketSize  -= 2;                     //  packet lenght
    w5500.recv_data_processing(s, rbuf, RxPacketSize);  // read the packet
    w5500.execCmdSn(s, Sock_RECV);

    // is this a packet for myself?
if (rbuf[0]==myadr[0])if (rbuf[1]==myadr[1])
if (rbuf[2]==myadr[2])if (rbuf[3]==myadr[3])
if (rbuf[4]==myadr[4])if (rbuf[5]==myadr[5])

if (rbuf[6] ==radr[0]) if (rbuf[7] ==radr[1])
if (rbuf[8] ==radr[2]) if (rbuf[9] ==radr[3])
if (rbuf[10]==radr[4]) if (rbuf[11]==radr[5])
{
	reccount++;    // increase number of sent packetes
        for (int i=0; i<6; i++) sbuf[i]  =radr [i];
        for (int i=0; i<6; i++) sbuf[i+6]=myadr[i];
    sbuf[23]=sendcount;
    sbuf[24]=sendcount;
    sbuf[25]=0x21;
    PORTD=rbuf[17];    // set the output-pins  (first 8 bit)
		       // now set the first 3 bits of next port
		       // (pin-nr.>10 ar used by ethernet-shield)
    digitalWrite(8, (rbuf[18]&1));  
    digitalWrite(9 ,(rbuf[18]&2));
    memcpy(sbuf+RECPKTCOUNT,&reccount,2);
         }  // packet was for me....
            // my work is done
} //sth. received
	// send acc if packet received
	if (lastrec!=reccount){ 
		send_pkt();
		lastrec=reccount;
		}
        // the pin-values of A0-A7 changed?
	if (lastC!=PINC){
                        sbuf[17]=PINC;
			lastC=PINC;
			send_pkt();
			}
}
[etheraw.ino|attachment](upload://vz8v4PTYZguDxrVohEl4wSMuhbR.ino) (4.5 KB)

Hi @virencq

Can you post your complete error message?

Your buffers are way too big for an Uno.

Yep.

You can use a max of 2048 bytes. So, you can change your buffers to a max of 966+14 for each buffer.

1 Like

@virencq, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project :wink: See About the Installation & Troubleshooting category.

I also see problems with pins.
pin0 and pin1 can't be used, because they are already used by the USB-Serial chip.
Various other pins in the sketch are used by the W5100 (W5500?) board/chip.
Leo..

Thanks, Sir,
It works my .ino compiled without errors. Let me check for further any complicacy.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.