Pages: [1]   Go Down
Author Topic: Ethernet shield V3 + Mega 2560 HTTP server freezes randomly  (Read 1452 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I've been trying to get my arduino to reliably act as a micro controller for a robot that I've built.  I communicate with it via ethernet to send it commands for the stepper motors and dynamixels on it.

I have an interrupt toggling LED's every second to see if the robot is crashing, and the crash causes the interrupt to freeze as well.

Here is my main code:
V2 - Less reliable.  Should crash less than V1
Code:
void loop()
{
client = server.available();
if(client)
{
while(client.connected())
{
while(client.available()>0)
{
if(i > BUFFER_SIZE - 2)
{
i = 0;
}
packetBuffer[i] = client.read();
i++;
dataRead = true;

}
if(dataRead)
{
returnError(1); // Return via ethernet that data has been received
findPayload();
}
//client.flush();
delay(5);
//Serial.write(1);
}
delay(5);
client.stop();
}
}
}

V1 - More reliable than V2, but it isn't intuitive as to why that would be the case, since it lacks the while(client.connected()) loop.
Code:
void loop()
{
client = server.available();
if(client)
{
while(client.available()>0)
{
packetBuffer[i] = client.read();
i++;
dataRead = true;
}
if(dataRead)
{
returnError(1);
findPayload();
}
}
delay(5);
}

i and packetBuffer and global variables to handle buffering of the incoming packets.  The parsing function resets i whenever a full packet is received.
V1 crashes after the dataRead = true; line.
V2 crashes after the packetBuffer = client.read(); line

I ran one test where I output the value of i everytime I wrote to the packetBuffer, and it indicated that I was not receiving complete packets.

Any input would be appreciated.
btw: I've tried two ethernet shields.
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9698
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I suspect bad code, either by the code as written or by code design. perhaps you should start with more simple code and gradually add to it until it fails.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In both versions of the code you react very strange to buffer overflows. In V1 you simply ignore it and overwrite other stuff. In V2 you overwrite the beginning of your buffer if there is more data in the request than your buffer has in size. Why not just ignoring the rest of the request data if your buffer is full?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My buffer is set to 64bytes, which should be sufficient considering the largest packets that I send are 16 bytes.
Below is my parsing code, as you can see it resets i to 0 and clears the buffer.

Code:
void findPayload()
{
for(int j = 0; j != i; j++)
{
if(packetBuffer[j]=='V' && packetBuffer[j+1] == 'T')
{
if(i > j+ 2)
{
length = packetBuffer[j+2];
packetSize = i - j;
if(length < packetSize - 2)
{
packetType = packetBuffer[j + 3];
packetStart = j;
for(int k = 0; k < length; k ++)
{
payLoad[k] = packetBuffer[k+j+3]; // Payload includes everything AFTER length
}
for(int k = 0; k < j + length; k ++)
{
packetBuffer[k] = 0;
}
packetLoaded = true;
dataRead = false;
j=0;
i=0;
returnError(4);// Return that the packet was loaded
parsePacket();
break;
}
returnError(3); // Return that an incomplete packet was received
}
break;
}
returnError(2); // Return that the sync chars were not received.
}
}

This could possibly be the issue so suggestions would be great.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 150
Posts: 6130
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It appears you may not be reading the entire request. You should read characters until a double cr/lf for a GET request. The request could come in more than one packet. If you leave characters in the socket rx buffer, the connection will not close and the socket is lost.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe I've been unclear about what I am doing.
I realize that HTTP server would be the incorrect term for what I am doing, (sorry it was a long day when I posted this).

My computer hosts a labview environment where I send packets to the arduino to control the computer.
I send a complete packet over ethernet to the arduino. 
My arduino acts as a server that my computer connects to.
I basically want to send a short message from my computer to the arduino, have it read that message, parse it, and run the code.

The packet is formatted as such
Header - length - payload - checksum
Logged

0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9698
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I basically want to send a short message from my computer to the arduino, have it read that message, parse it, and run the code.

Have you made some simple server code and successfully sent request to the arduino and had the arduino send the request to the serial monitor for debugging?
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, this code actually works perfectly for what I want it to do. Until it crashes.
The crashes can occur anywhere from 1min after booting to 30min after booting.

My instinct tells me it is a hardware problem, but I've replaced the ethernet shield so I thought that might fix it.
My team is replacing the power system with one that will hopefully provide cleaner DC power, and we are attaching a heatsink to the Wiznet chip in case it is over heating.

I recently did a debug run that indicates that when a crash occurs, the arduino believes it is getting data but the data is corrupt / malformed.
I believe this because I did a Serial.write of the 'i' iterator that I use with my buffer and at the crash, it increased past expected values. 
IE: I send it a bunch of 16 byte packets, and its value is 126.  To me this indicates that the packet parsing code never received a full packet; thus why i kept increasing without resetting.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Show us the whole code not just excerpts.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I was hoping to avoid that since it is so extensive, but here it is.

Code:
/*
TODO:
Find why it crashes
DONE:
*Change all counts to unsigned longs
*Add parsing of stepper motor packets
*Add pulsing of a digital pin
*Add selection of direction via a digital pin
*Add control to step period via packets
*Locate scizzor lift by reed switches
Return command list:
00 - No error
01 - Data Received
02 - Sync char not found
03 - Incomplete packet
04 - Packet Loaded
05 - Stepper udpated
06 - Dynamixel updated
07 - Drive camera toggled
Command List:
00 - Check status
01 - Update Scizzor lift
02 - Update dynamixels
03 - Toggle Drive Camera
04 - Toggle Light source
*/
//#include <avr/io.h>
//#include <avr/wdt.h>
#include <SPI.h>
#include <Ethernet.h>
#include "TimerOne.h"
#include "TimerThree.h"

#define BUFFER_SIZE 64
#define DYNA_TOGGLE_PIN 53
#define SCIZZOR_STEP_PIN 38
#define SCIZZOR_DIR_PIN 39
#define REED_TOP_PIN 22
#define REED_BOTTOM_PIN 23
#define LIGHT_CONTROL_PIN 13
#define DRIVE_CAMERA_PIN 25
#define DYNA_DELAY 1 // Delay in MS

//********************* Ethernet stuff **************
//byte mac[] = {0x90, 0xa2, 0xda, 0x0d, 0x7d, 0xb8}; // Board 1
byte mac[] = {0x90, 0xa2, 0xda, 0x0d, 0x7f, 0x5e}; // Board 2
IPAddress ip(192,168,1, 177);
IPAddress gateway(192,168,1, 1);
IPAddress subnet(255, 255, 0, 0);
EthernetServer server = EthernetServer(23);// telnet defaults to port 23
EthernetClient client;
// ***************** Packet stuff *****************
char packetBuffer[BUFFER_SIZE] = {' '};
int i = 0;
unsigned int temp;
unsigned int checksum;
bool packetLoaded = false;
char bufReturn[BUFFER_SIZE] = {' '};
int itReturn = 0;
boolean alreadyConnected = false;
char payLoad[BUFFER_SIZE] = {' '};
int packetStart = 0;
int packetType = -1;
bool clientFirstConnected = false;
char dynamixelReturnData[BUFFER_SIZE] = {0x00};
int itDyna = 0;
//*********************** Stepper motor stuff *********************
unsigned long ScizzorSteps = 500000; // 0 Is the bottom of the lift
bool scizzorOn = false;
unsigned long scizzorBotUnlatch = 27391; // 29532
unsigned long scizzorBotLatch = 21421;   // 23372
unsigned long maxScizzorSteps = 440687;
char x = ' ';
char z = ' ';
char p = ' ';
char o = ' ';
long int period = 100;
int length = 0;
int packetSize = 0;
bool dataRead = false;
bool dynamixelLED = false;

void setup()
{
Ethernet.begin(mac, ip, gateway, subnet);// initialize the ethernet device
server.begin();// start listening for clients
Serial.begin(57600);
Serial3.begin(57600);
pinMode(DYNA_TOGGLE_PIN, OUTPUT); // When pin is high, can write data, when pin is low, read data,
digitalWrite(DYNA_TOGGLE_PIN, HIGH);
char initialPacket[16] =  { 0x02, 0x02, 0x06, 0x06,
0x01, 0x05, 0x03, 0x1E, 0x07, 0x08,
0x00, 0x05, 0x03, 0x1E, 0xFD, 0x05};
for(int i = 0; i < 16; i++)
{
payLoad[i] = initialPacket[i];
}
updateDynamixels();
pinMode(SCIZZOR_STEP_PIN, OUTPUT); // Scizzor Step
pinMode(SCIZZOR_DIR_PIN, OUTPUT); // Scizzor Dir when LOW raises lift, when HIGH lowers lift
pinMode(REED_TOP_PIN, INPUT); // Reed top
pinMode(REED_BOTTOM_PIN, INPUT); // Reed bottom
pinMode(DRIVE_CAMERA_PIN, OUTPUT);
pinMode(LIGHT_CONTROL_PIN, OUTPUT);
pinMode(10,OUTPUT);
digitalWrite(10,HIGH);

// ***************** Set scizzor lift absolute position based on reed switches ***********************
if(digitalRead(REED_BOTTOM_PIN)) // Scizzor lift is at bottom, need to move it up to determine unlatching point
{
digitalWrite(SCIZZOR_DIR_PIN,LOW);
while(digitalRead(REED_BOTTOM_PIN))
{
digitalWrite(SCIZZOR_STEP_PIN,!digitalRead(SCIZZOR_STEP_PIN));
delayMicroseconds(50);
}
ScizzorSteps = scizzorBotUnlatch; // Sets the location to the known unlatching point
}
else
{
digitalWrite(SCIZZOR_DIR_PIN,HIGH);
while(!digitalRead(REED_BOTTOM_PIN))
{
digitalWrite(SCIZZOR_STEP_PIN,!digitalRead(SCIZZOR_STEP_PIN));// Lower until switch latches
delayMicroseconds(50);
}
ScizzorSteps = scizzorBotLatch;
}
scizzorOn = true;
dropScizzor();
scizzorOn = false;
Timer1.initialize(500000);
Timer1.attachInterrupt(interruptScizzor);
//wdt_enable(WDTO_8S);
Timer3.initialize(1000000);
Timer3.attachInterrupt(blinkDynamixel);
}
void blinkDynamixel()
{
if(!dynamixelLED)
{
payLoad[0] = 1;
payLoad[1] = 1; // One Packet
payLoad[2] = 5; //Length
payLoad[3] = 254;
payLoad[4] = 04;
payLoad[5] = 03;
payLoad[6] = 25;
payLoad[7] = 01;
dynamixelLED = !dynamixelLED;
}
else
{
payLoad[0] = 1;
payLoad[1] = 1; // One Packet
payLoad[2] = 5; //Length
payLoad[3] = 254;
payLoad[4] = 04;
payLoad[5] = 03;
payLoad[6] = 25;
payLoad[7] = 00;
dynamixelLED = !dynamixelLED;
}
updateDynamixels();
}
void packetTimeout() // Packet has timed out, reset packet buffer
{
i = 0;
for(int j = 0; j < BUFFER_SIZE; j++)
{
payLoad[j] = 0;
packetBuffer[j] = 0;
}
}
void dropScizzor()
{
digitalWrite(SCIZZOR_DIR_PIN,HIGH);
while(ScizzorSteps > 1)
{
//wdt_reset();
interruptScizzor();
delayMicroseconds(50);
}
}
void interruptScizzor()
{
if(scizzorOn)
{
digitalWrite(SCIZZOR_STEP_PIN,!digitalRead(SCIZZOR_STEP_PIN)); // Toggle pin
if(!digitalRead(SCIZZOR_DIR_PIN)) ScizzorSteps = ScizzorSteps + 1; // If set to raise lift, increment upwards
else ScizzorSteps = ScizzorSteps - 1;
}
if(ScizzorSteps == 1) scizzorOn = false;
if(ScizzorSteps == maxScizzorSteps -1) scizzorOn = false;
}
void overrideInterruptScizzor()
{
digitalWrite(SCIZZOR_STEP_PIN,!digitalRead(SCIZZOR_STEP_PIN)); // Toggle pin
if(!digitalRead(SCIZZOR_DIR_PIN)) ScizzorSteps = ScizzorSteps + 1; // If set to raise lift, increment upwards
else ScizzorSteps = ScizzorSteps - 1;
}
void manualScizzorCallibration()
{
if(payLoad[1] == 0x00) // Set to move downards with no limits
{
Timer1.attachInterrupt(overrideInterruptScizzor);
Timer1.setPeriod(600);
}
if(payLoad[1] == 0x01) // Reached the bottom, now increment upwards until the scizzor latch location is found
{
ScizzorSteps = 0;
digitalWrite(SCIZZOR_DIR_PIN,LOW);
while(digitalRead(REED_BOTTOM_PIN))
{
digitalWrite(SCIZZOR_STEP_PIN,!digitalRead(SCIZZOR_STEP_PIN));
delayMicroseconds(50);
ScizzorSteps = ScizzorSteps + 1;
} // Found the new unlatching point
unsigned long ScizzorUnlatch=ScizzorSteps;
digitalWrite(SCIZZOR_DIR_PIN,HIGH);
while(!digitalRead(REED_BOTTOM_PIN))
{
digitalWrite(SCIZZOR_STEP_PIN,!digitalRead(SCIZZOR_STEP_PIN));
delayMicroseconds(50);
ScizzorSteps = ScizzorSteps - 1;
}
client.write('V');
client.write('T');
client.write(0x09);
client.write(0x09);
x = 0xFF;
x = x&ScizzorUnlatch; // Return Unlatching point
z = ScizzorUnlatch >> 8;
p = ScizzorUnlatch >> 16;
o = ScizzorUnlatch >> 24;
client.write(o);
client.write(p);
client.write(z);
client.write(x);
x = x&ScizzorSteps; // Return latching point
z = ScizzorSteps >> 8;
p = ScizzorSteps >> 16;
o = ScizzorSteps >> 24;
client.write(o);
client.write(p);
client.write(z);
client.write(x);
Timer1.attachInterrupt(interruptScizzor); // Re-attach the correct interrupt for normal operation
Timer1.setPeriod(2000);
}
}
void readReturnData()
{
digitalWrite(DYNA_TOGGLE_PIN,LOW);
delay(DYNA_DELAY);
while(Serial3.available()>0)
{
bufReturn[itReturn] = Serial3.read();
itReturn++;
}
digitalWrite(DYNA_TOGGLE_PIN,HIGH);
}

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Part 2

Code:
void returnDynamixelData()
{
client.write('V');
client.write('T');
client.write(itReturn +1);
client.write(0x06);
for(int j = 0; j < itReturn; j++)
{
client.write(bufReturn[j]);
}
itReturn = 0;
}
void updateDynamixels()
{
int numPackets = payLoad[1];
packetStart = 2+ numPackets; // May need to adjust this to make sure this points to the beginning of a packet
for(int k= 0; k < numPackets; k++)
{
int packetLength = payLoad[2+k]; // Packet length includes serial length, and the paylaod
temp=0;
checksum = 0;
digitalWrite(DYNA_TOGGLE_PIN,HIGH);
Serial3.write(0xFF);
Serial3.write(0xFF);
//Serial.write(0xFF);
//Serial.write(0xFF);
for(int j = 0; j < packetLength; j++)
{
Serial3.write(payLoad[j + packetStart]);
//Serial.write(payLoad[j+packetStart]);
temp = temp + payLoad[j+packetStart];
}
checksum = 0xFF - (temp % 256);
Serial3.write(checksum);
//Serial.write(checksum);
packetStart = packetStart + packetLength;
readReturnData();
}
//returnDynamixelData();

}
void returnError(char error)
{
client.write('V');
client.write('T');
client.write(0x01);
client.write(error);
}
void returnError(char error, unsigned long ScizzorUnlatch, unsigned long ScizzorLatch)
{
if(error == 0x09)
{
client.write('V');
client.write('T');
client.write(9);
client.write(9);
x = 0xFF;
x = x&ScizzorUnlatch; // Return Unlatching point
z = ScizzorUnlatch >> 8;
p = ScizzorUnlatch >> 16;
o = ScizzorUnlatch >> 24;
client.write(o);
client.write(p);
client.write(z);
client.write(x);
x = x&ScizzorLatch; // Return latching point
z = ScizzorLatch >> 8;
p = ScizzorLatch >> 16;
o = ScizzorLatch >> 24;
client.write(o);
client.write(p);
client.write(z);
client.write(x);
}
}
void updateScizzor()
{
if(payLoad[1] == 0)
{
if(ScizzorSteps !=maxScizzorSteps -1) // If already at max position for this direction, do nothing
{
scizzorOn = true;
digitalWrite(SCIZZOR_DIR_PIN,LOW);
}
}
if(payLoad[1] ==1)
{
if(ScizzorSteps != 1) // If already at max position for this direction, do nothing
{
scizzorOn = true;
digitalWrite(SCIZZOR_DIR_PIN,HIGH);
}
}
if(payLoad[1] ==2)
{
scizzorOn = false;
Timer1.setPeriod(2000);
}
if(payLoad[2] < 30) period = (long int) 30;
else period = (long int) payLoad[2];
Timer1.setPeriod(period);

x = 0xFF;
x = x&ScizzorSteps;
z = ScizzorSteps >> 8;
p = ScizzorSteps >> 16;
o = ScizzorSteps >> 24;

client.write(86);
client.write(84);
client.write(5); // Length
client.write(5); // Packet Type (stepper return data)
client.write(o);
client.write(p);
client.write(z);
client.write(x);

//Serial.write(o);
//Serial.write(p);
//Serial.write(z);
//Serial.write(x);
}
void toggleDriveCamera()
{
digitalWrite(DRIVE_CAMERA_PIN,!digitalRead(DRIVE_CAMERA_PIN));
}
void toggleLightSource()
{
digitalWrite(LIGHT_CONTROL_PIN,!digitalRead(LIGHT_CONTROL_PIN));
}
void togglePin()
{
digitalWrite(payLoad[1],!digitalRead(payLoad[1]));
returnError(10);
}
void analogOutput()
{
pinMode(payLoad[1],OUTPUT);
analogWrite(payLoad[1],payLoad[2]);
returnError(11);
}
void updateScizzorOffset()
{
unsigned long tempScizzor = 0;
unsigned long tmp = 0;
tempScizzor = payLoad[4];
tempScizzor += (payLoad[3]+1) *256;
ScizzorSteps = ScizzorSteps + tempScizzor;
x = 0xFF;
x = x&ScizzorSteps;
z = ScizzorSteps >> 8;
p = ScizzorSteps >> 16;
o = ScizzorSteps >> 24;

client.write(86);
client.write(84);
client.write(5); // Length
client.write(5); // Packet Type (stepper return data)
client.write(o);
client.write(p);
client.write(z);
client.write(x);

}
void parsePacket()
{
//Verify checksum
char tmpChecksum = 0;
for(int i = 0; i < length -1; i++)
{
tmpChecksum = tmpChecksum + payLoad[i];
}
//Serial.write(payLoad[length-1]);
if(tmpChecksum == payLoad[length-1])
{
if(payLoad[0] == 0x00) returnError(0);
if(payLoad[0] == 0x01) updateScizzor();
if(payLoad[0] == 0x02)
{
updateDynamixels();
returnError(6);
}
if(payLoad[0] == 0x03) toggleDriveCamera();
if(payLoad[0] == 0x04) toggleLightSource();
if(payLoad[0] == 0x05) togglePin();
if(payLoad[0] == 0x06) analogOutput();
if(payLoad[0] == 0x07) manualScizzorCallibration();
if(payLoad[0] == 0x08) updateScizzorOffset();
}
else
{
returnError(255);
}
}
void findPayload()
{
for(int j = 0; j != i; j++)
{
if(packetBuffer[j]=='V' && packetBuffer[j+1] == 'T')
{
if(i > j+ 2)
{
length = packetBuffer[j+2];
packetSize = i - j;
if(length < packetSize - 2)
{
packetType = packetBuffer[j + 3];
packetStart = j;
for(int k = 0; k < length; k ++)
{
payLoad[k] = packetBuffer[k+j+3]; // Payload includes everything AFTER length
}
for(int k = 0; k < j + length; k ++)
{
packetBuffer[k] = 0;
}
packetLoaded = true;
dataRead = false;
j=0;
i=0;
returnError(4);// Return that the packet was loaded
parsePacket();
break;
}
returnError(3); // Return that an incomplete packet was received
}
break;
}
returnError(2); // Return that the sync chars were not received.
}
}
void loop()
{
client = server.available();
int setting = 2;
if(setting == 0)
{
if(client)
{
while(client.connected())
{
while(client.available()>0)
{
if(i > BUFFER_SIZE - 2) // Something has gone wrong in writing to i, maybe bad data over the network?  Reset i to 0 will prevent crashing.  Need to implement circular buffer.
{
i = 0;
j = 0;
}
packetBuffer[i] = client.read();
i++;
dataRead = true;

}
if(dataRead)
{
returnError(1); // Return via ethernet that data has been received
findPayload();
}
//client.flush();
delay(5);
//Serial.write(1);
}
delay(5);
client.stop();
}
}
if(setting == 1)
{
if(client)
{
while(client.available()>0)
{
Serial.write(i);
//delayMicroseconds(100);
packetBuffer[i] = client.read();
i++;
dataRead = true;
}
if(dataRead)
{
returnError(1);
findPayload();
}
Serial.flush();
}
delay(5);
}
if(setting == 2)
{
Serial.write(0);
if(client)
{
Serial.write(1);
while(client.available()>0)
{
Serial.write(2);
packetBuffer[i] = client.read();
Serial.write(3);
i++;
Serial.write(4);
dataRead = true;
Serial.write(5);
}
Serial.write(6);
if(dataRead)
{
Serial.write(7);
returnError(1);
Serial.write(8);
findPayload();
Serial.write(9);
}
Serial.write(10);
}
delay(5);
Serial.write(11);
}
}
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5242
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i and packetBuffer and global variables to handle buffering of the incoming packets.  The parsing function resets i whenever a full packet is received.
V1 crashes after the dataRead = true; line.
V2 crashes after the packetBuffer = client.read(); line

How do you know that the different version crash at that line? Are you saying that because you use the Serial.write()s for that? What program do you use to monitor the serial interface on the PC?

What do you use Serial3 for?

Is my guess correct that you're running that code on a Arduino Mega2560?

You don't declare variables shared between interrupt context and normal program execution as volatile. You should!

You write the buffer "payload" in interrupt context (blinkDynamixel) and you use it for parsing you command message. You don't take precautions that the interrupt is not called during the parsing of your message. This is called a Race Condition.

During the interrupt handler (updateDynamixels in blinkDynamixel) your calling Serial3.write(). This call tries to insert the byte parameter in the serial buffer. If the buffer is full, it waits for the buffer to be emptied. The buffer gets only emptied if the interrupt of the USART is called to get one byte of the buffer. This interrupt gets never called because you are inside an interrupt handler where all interrupts a disabled. That's a classical race condition.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I used Serial.write() outputs to determine where each program is crashing.  I used realTerm to do this.
Serial3 is used for communicating with the dynamixels.
Yes the code is on a Mega 2560.

Thank you for your programming input, this is actually my first experience with embedded coding.  I will work on implementing the fixes that you mentioned.
Logged

Colorado, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I will work on implementing the fixes.

I was watching the original thread with great interest and wondered if you got this situation worked out.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 150
Posts: 6130
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@sellonoid: Try this server sketch. See if it does any better.
http://playground.arduino.cc/Code/WebServerST
It was tested on a Mega 2560 V2 with ethernet shield V2.
Logged

Pages: [1]   Go Up
Jump to: