У меня была проблема с записью в EEPROM, нашел пару тестов в виде скетч файлов. Управляются через сериал порт
#include "EEPROM.h" void setup() { byte eData, tData1, tData2, tData3 = 0; Serial.begin(9600); Serial.println("Arduino EEPROM Test v1.0"); Serial.println("http://arduino.on.kg"); // Проходим в цикле всю память EEPROM. for (boolean i = 0; i < EEPROM.length(); i++) { // Запоминаем то, что записано в EEPROM. eData = EEPROM.read(i); // Записываем в ячейку EEPROM нули. EEPROM.write(i, 1); tData1 = EEPROM.read(i); if (tData1 != 1) { Serial.print("Cell "); Serial.print(i); Serial.println(" is corrupted (Test 1)."); continue; } // Записываем в ячейку EEPROM единицы. EEPROM.write(i, 255); tData2 = EEPROM.read(i); if (tData2 != 255) { Serial.print("Cell "); Serial.print(i); Serial.println(" is corrupted (Test 2)."); continue; } // Восстанавливаем данные в EEPROM. EEPROM.write(i, eData); tData3 = EEPROM.read(i); if (tData3 != eData) { Serial.print("Cell "); Serial.print(i); Serial.println(" is corrupted (Test 3)."); continue; } } Serial.println("The test is completed."); } void loop() { // Пустой цикл. }
Тест проверяет все пины арудинки, перезаписывает всю память в 0 или 1 моргает светодиодом и пр.
#define FIRST_PIN 2 #define PIN_LED 13 #define DELAY_ITERATION 200 #define DELAY_BW_TESTS 2000 #define DELAY_WARN 5000 #define ADC_NUMSAMPLES 8 int samples[ADC_NUMSAMPLES]; #include <EEPROM.h> void setup() { Serial.begin(9600); pinMode(PIN_LED, OUTPUT); } void loop() { digitalWrite(PIN_LED, LOW); if (Serial.available() > 0) { switch (Serial.read()) { case 'v': Serial.println("Arduino hardware test v. 1.1b"); Serial.println("a) ADC MANUAL test. Prints values from all analog pins"); Serial.println("i) Inputs MANUAL test. Prints all inputs with LOW level on them"); Serial.println("o) Outputs MANUAL test. Sets all ports to HIGH"); Serial.println("b) Blink. Tests onboard led"); Serial.println("0) Zerofill of built-in EEPROM"); Serial.println("1) 0xFF fill of built-in EEPROM"); Serial.println("p) Test PWM on on-board LED"); Serial.println(""); break; case 'a': //ADC test Tests all analog pins (A0-A7) while(true) { Serial.println("ADC test"); readAnalogValue(A0); readAnalogValue(A1); readAnalogValue(A2); readAnalogValue(A3); readAnalogValue(A4); readAnalogValue(A5); #if(NUM_ANALOG_INPUTS == 8) readAnalogValue(A6); readAnalogValue(A7); #endif digitalWrite(PIN_LED, LOW); delay(DELAY_BW_TESTS); } break; case 'i': //Inputs test. Tests all inputs in digital mode while(true) { Serial.println("Inputs test. Pins in LOW state:"); for(byte pin = FIRST_PIN; pin <= NUM_DIGITAL_PINS; pin++) { pinMode(pin, INPUT_PULLUP); if(!digitalRead(pin)) { if(pin < 10) Serial.print(" PIN: "); else Serial.print(" PIN: "); Serial.print(pin); Serial.println(" LOW"); //Should be no "LOW" messages if all pins is not connected to GND } } delay(DELAY_BW_TESTS); digitalWrite(PIN_LED, !digitalRead(PIN_LED)); //Toggle LED } break; case 'o': //Outputs test. Tests setting all ports to HIGH Serial.println("Outputs test. All set to HIGH"); for(byte pin = FIRST_PIN; pin <= NUM_DIGITAL_PINS; pin++) { pinMode(pin, OUTPUT); digitalWrite(pin, HIGH); } break; case 'b': //Blink. Tests onboard led while(true) { Serial.println("Blink"); digitalWrite(PIN_LED, HIGH); delay(1000); digitalWrite(PIN_LED, LOW); delay(1000); } break; case 'e': e2reader(); break; case '0': //Zerofill of built-in EEPROM Serial.println("Zerofill of EEPROM in 5s"); delay(DELAY_WARN); Serial.println("Started"); for(int i=0; i<EEPROM.length(); i++) { EEPROM.write(i, 0); } Serial.println("Done"); break; case '1': //0xFF fill of built-in EEPROM Serial.println("0xFF Fill of EEPROM in 5s"); delay(DELAY_WARN); Serial.println("Started"); for(int i=0; i<EEPROM.length(); i++) { EEPROM.write(i, 255); } Serial.println("Done"); break; case 'p': //Test PWM on on-board LED while(true) { Serial.println("LED PWM control"); // fade in from min to max in increments of 5 points: for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) { // sets the value (range from 0 to 255): analogWrite(PIN_LED, fadeValue); delay(40); } // fade out from max to min in increments of 5 points: for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) { analogWrite(PIN_LED, fadeValue); delay(40); } } break; } } } void readAnalogValue(int adcPin) { int i; for (i=0; i<ADC_NUMSAMPLES; i++) { samples[i] = analogRead(adcPin); delay(60); } // average all the samples out int average=0; for (i=0; i<ADC_NUMSAMPLES; i++) { average += samples[i]; } average /= ADC_NUMSAMPLES; Serial.print("ADC PIN: "); Serial.print(adcPin); Serial.print(" value: "); Serial.println(average); digitalWrite(PIN_LED, !digitalRead(PIN_LED)); //Toggle LED } #include <EEPROM.h> void e2reader(){ char buffer[16]; char valuePrint[4]; byte value; unsigned int address; uint8_t trailingSpace = 2; Serial.print("Dumping "); Serial.print(E2END + 1); Serial.println(" bytes from EEPROM."); Serial.print("baseAddr "); for(int x = 0; x < 2; x++){ Serial.print(" "); for(int y = 0; y < 25; y++) Serial.print("="); } // E2END is a macro defined as the last EEPROM address // (1023 for ATMEGA328P) for(address = 0; address <= E2END; address++){ // read a byte from the current address of the EEPROM value = EEPROM.read(address); // add space between two sets of 8 bytes if(address % 8 == 0) Serial.print(" "); // newline and address for every 16 bytes if(address % 16 == 0){ //print the buffer if(address > 0 && address % 16 == 0) printASCII(buffer); sprintf(buffer, "\n 0x%05X: ", address); Serial.print(buffer); //clear the buffer for the next data block memset (buffer, 32, 16); } // save the value in temporary storage buffer[address%16] = value; // print the formatted value sprintf(valuePrint, " %02X", value); Serial.print(valuePrint); } if(address % 16 > 0){ if(address % 16 < 9) trailingSpace += 2; trailingSpace += (16 - address % 16) * 3; } for(int i = trailingSpace; i > 0; i--) Serial.print(" "); //last line of data and a new line printASCII(buffer); Serial.println(); } void printASCII(char * buffer){ for(int i = 0; i < 16; i++){ if(i == 8) Serial.print(" "); if(buffer[i] > 31 and buffer[i] < 127){ Serial.print(buffer[i]); }else{ Serial.print("."); } } }
Еще один
Serial.begin(115200); for (byte Pattern=0; Pattern<=0xFF; Pattern++) { for (uint_16 i=0; i<SizeOfEEPROM, i++) EEPROM.write(i,Pattern); for (uint_16 i=0; i<SizeOfEEPROM, i++) if (EEPROM.read(i)!=Pattern) { Serial.print("Ошибка по адресу: "); Serial.print(i); Serial.print(", заполнитель: "); Serial.println(Pattern); } } Serial.print("Тест закончен."); while (1);