# HG changeset patch # User Paul Boddie # Date 1440350403 -7200 # Node ID c3fae781613c6c8992581b061499031d2269ef9d # Parent ad17e0dbe2277aaaa48ab49daa681c167cf2cb11 Increased the input buffer size, propagated the number of read/expected characters so that erase and program sequences have their command lengths described. diff -r ad17e0dbe227 -r c3fae781613c ArduinoAm29F010.cpp --- a/ArduinoAm29F010.cpp Sun Aug 09 19:51:29 2015 +0200 +++ b/ArduinoAm29F010.cpp Sun Aug 23 19:20:03 2015 +0200 @@ -21,7 +21,7 @@ DQ0 = 7, DQ1 = 6, DQ2 = 5, DQ3 = 4, DQ4 = 8, DQ5 = 9, DQ6 = 10, DQ7 = 11; -const int BUFSIZE = 8; +const int BUFSIZE = 9; char inbuffer[BUFSIZE]; int nread = 0; @@ -160,7 +160,7 @@ digitalWrite(CE, HIGH); } -int readCommand(const char buffer[]) +int readCommand(const char buffer[], int nread) { int high, low, i; @@ -181,7 +181,7 @@ return readOp(high, low); } -bool writeCommand(const char buffer[]) +bool writeCommand(const char buffer[], int nread) { int high, low, data, i; @@ -234,7 +234,7 @@ { for (int i = 0; i < 5; i++) { - writeCommand(ERASE[i]); + writeCommand(ERASE[i], 7); } writeOp(0x55, 0x55, 0x30); return waitForCompletion(0, 0, 0xff); @@ -251,7 +251,7 @@ for (int i = 0; i < 5; i++) { - writeCommand(ERASE[i]); + writeCommand(ERASE[i], 7); } writeOp(high, 0, 0x30); @@ -260,7 +260,7 @@ return waitForCompletion(high, 0, 0xff); } -bool program(const char buffer[]) +bool program(const char buffer[], int nread) { int high, low, data, i; @@ -281,7 +281,7 @@ for (int i = 0; i < 3; i++) { - writeCommand(PROGRAM[i]); + writeCommand(PROGRAM[i], 7); } writeOp(high, low, data); @@ -325,7 +325,7 @@ case 'R': if (nread >= 5) { - Serial.println(readCommand(inbuffer), HEX); + Serial.println(readCommand(inbuffer, nread), HEX); nread = 0; } break; @@ -333,7 +333,7 @@ case 'W': if (nread >= 7) { - if (writeCommand(inbuffer)) + if (writeCommand(inbuffer, nread)) Serial.println("W"); else Serial.println("C"); @@ -363,7 +363,7 @@ case 'P': if (nread >= 7) { - if (program(inbuffer)) + if (program(inbuffer, nread)) Serial.println("P"); else Serial.println("C");