Go Down

Topic: Ethernet shield: Library problem? (Read 1 time) previous topic - next topic

marsangoa

Jun 02, 2011, 09:33 am Last Edit: Jun 02, 2011, 09:41 am by marsangola Reason: 1
Hi,

in the last weeks I played with the "official" Arduino ethernet shield and Arduino "uno".
My program works for some times then it crashes.

I looked inside the library and I found that problems arise always after the same write instruction.
This happen after a random number of iterations.

Here's the library code with the "write" function:

Code: [Select]

void W5100Class::send_data_processing(SOCKET s, uint8_t *data, uint16_t len)
{

 uint16_t ptr = readSnTX_WR(s);
 uint16_t offset = ptr & SMASK;
 uint16_t dstAddr = offset + SBASE[s];

 if (offset + len > SSIZE)
 {
   // Wrap around circular buffer
   uint16_t size = SSIZE - offset;
   write(dstAddr, data, size);
   write(SBASE[s], data + size, len - size);
 }
 else {
   write(dstAddr, data, len); [b]// <-- LOOK HERE ! this write is always the last correct instruction[/b]
 }
 
  ptr += len;
  writeSnTX_WR(s, ptr);
}


When the problem arise all register are wrong and they seems to change very fast.

I have been trying to solve this problem for some days, but without any success.

I post a minimal code:

Code: [Select]

/*
       * A simple sketch that uses Ethernet Shield to send some values (via POST) to GoogleDocs
       * Minimal code for debugging, run for some minutes and it crashes.
       * google file https://spreadsheets.google.com/spreadsheet/ccc?key=0ApEwiUcF9-9rdEV4NnNUekZNTFdRNjJGejhZZTd1SEE&hl=it#gid=0
       * compiled with arduino 022
*/


#include "Ethernet.h"
#include "SPI.h"


//Ip configuration parameters ----------------------------------------
byte mac[] = {  0x90, 0xA2, 0xDA, 0x00, 0x2C, 0x42 };
byte ip[] = { 192,168,1,0 };
byte gateway[] = { 192, 168, 1, 254 };
byte subnet[] = { 255, 255, 255, 0 };

// IP Address for spreadsheets.google.com
byte ipGoogle[] = {74,125,67,102};

// create a client that connects to Google
Client clientGoogle(ipGoogle,80);

void setup()
{  
 pinMode(10, OUTPUT);  
}


void loop()
{
   Ethernet.begin(mac, ip, gateway, subnet);
   delay(1000);
   clientGoogle.connect();
   if (clientGoogle.connected()) {
     clientGoogle.print("POST ");
     clientGoogle.print("/formResponse?formkey=dEV4NnNUekZNTFdRNjJGejhZZTd1SEE6MQ");
     clientGoogle.println(" HTTP/1.1");
     clientGoogle.print("Host: ");
     clientGoogle.println("spreadsheets.google.com");
     clientGoogle.println("Content-Type: application/x-www-form-urlencoded");
     clientGoogle.print("Content-Length: ");
     clientGoogle.println("94");
     clientGoogle.println("");
     clientGoogle.println("entry.0.single=10&entry.1.single=10&entry.2.single=10&pageNumber=0&backupCache=&submit=Envoyer");
     clientGoogle.println("");
     clientGoogle.println("");
     delay(4000);
     
     clientGoogle.flush();
     clientGoogle.stop();
 }
  delay (1000);
}


Help, ideas or advices are welcome!

PaulS

Code: [Select]
void loop()
{
    Ethernet.begin(mac, ip, gateway, subnet);

Why are you calling Ethernet.begin() in loop()?
The art of getting good answers lies in asking good questions.

marsangoa

Thanks for helping.

I have been trying to solve the problem by resetting the wiznet at each loop...
Problems arise also if I put the begin in the setup routine.

PaulS

I wonder if you can modify that function to disable interrupts while it is sending data out, and then re-enable them. I have no idea whether any of the things that it does rely on interrupts, but it would seem that an interrupt is occurring, and that changes some values that are not properly defined as volatile, and that that causes your problem.

Calling Ethernet.begin() on every pass through loop() does not seem like a good way to approach solving the problem.
The art of getting good answers lies in asking good questions.

marsangoa

#4
Jun 02, 2011, 02:29 pm Last Edit: Jun 02, 2011, 02:43 pm by marsangola Reason: 1
I tried putting noInterrupts() and interrupts() at begin and at the end of the write and read function isolating the functions from interrupts.

Problems still remain.   :~

marsangoa

I tried the web client sample in the example menu and it gets the page from the server but, after a while, it starts giving funny characters:

Code: [Select]

Take from the Serial Monitor:

block;font-weight:normal;margin-right:2px;white-space:nowrap}#cdr_opt,#loc_opt,#prc_opt{padding-left:`ò¯¾÷ò-rîo»ôïwëoþmöïºinªòé~nsòm_iþsgó$nuuyòógîñ8ÿøi=~mué/~o/Íïzýõ·÷cJëeí'gwa7'¿?ÿ÷ogewm¯÷eoïÝem÷ome§'ei¯m?ýv¼Ëpïîioêóï?ïo?÷÷e¯4¼®ieoûó


Does my ethernet shield is broken?

Go Up