Created
February 11, 2018 19:11
-
-
Save HectorTorres/d8d808ff6a901c37286363a4d9006ca7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
FUNCIÓN EEPROM CRC | |
Esta es una forma de buscar un error en la EEPROM | |
*/ | |
#include <Arduino.h> | |
#include <EEPROM.h> | |
void setup() | |
{ | |
Serial.begin(9600); // Inicializa Serial | |
while (!Serial) | |
{ | |
; // Espera a que el puerto serial se conecte (Sólo es necesario si se usa un puerto de USB local) | |
} | |
Serial.print("Longitud EEPROM: "); | |
Serial.println(EEPROM.length()); // Imprime cuántos datos van a correr por CRC y lo muestra en la ventana serial del software de Arduino | |
Serial.print("CRC de EEPROM: "); | |
Serial.println(EEPROMCRC(), HEX); // Muestra el resultado de haber llamado a EEPROMCRC, “HEX” es el formato en el que se mostrará el valor, en este caso, en base 16 o hexadecimal en la ventana serial del software de Arduino | |
} | |
void loop() | |
{ | |
// void loop vacío | |
} | |
unsigned long EEPROMCRC(void) | |
{ | |
const unsigned long TABLACRC[16] = | |
{ | |
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, | |
0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, | |
0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, | |
0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c | |
}; | |
unsigned long CRC = ~0L; | |
for (int indice = 0 ; indice < EEPROM.length() ; ++indice) | |
{ | |
CRC = TABLACRC[(CRC ^ EEPROM[indice]) & 0x0f] ^ (CRC >> 4); | |
CRC = TABLACRC[(CRC ^ (EEPROM[indice] >> 4)) & 0x0f] ^ (CRC >> 4); | |
CRC = ~CRC; | |
} | |
return CRC; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment