From dd1ec9920b8fd6b445cdcc943f53333990b34428 Mon Sep 17 00:00:00 2001 From: Chris--A Date: Tue, 17 Mar 2015 17:17:08 +1000 Subject: Added additional examples to EEPROM lib --- .../EEPROM/examples/eeprom_crc/eeprom_crc.ino | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino (limited to 'libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino') diff --git a/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino b/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino new file mode 100644 index 0000000..40b08bd --- /dev/null +++ b/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino @@ -0,0 +1,47 @@ +/*** + Written by Christopher Andrews. + CRC algorithm generated by pycrc, MIT licence ( https://github.com/tpircher/pycrc ). + + A CRC is a simple way of checking whether data has changed or become corrupted. + This example calculates a CRC value directly on the EEPROM values. + The purpose of this example is to highlight how the EEPROM object can be used just like an array. +***/ + +#include +#include + +void setup(){ + + //Start serial + Serial.begin(9600); + + //Print length of data to run CRC on. + Serial.print( "EEPROM length: " ); + Serial.println( EEPROM.length() ); + + //Print the result of calling eeprom_crc() + Serial.print( "CRC32 of EEPROM data: 0x" ); + Serial.println( eeprom_crc(), HEX ); + Serial.print( "\n\nDone!" ); +} + +void loop(){ /* Empty loop */ } + +unsigned long eeprom_crc( void ){ + + const unsigned long crc_table[16] = { + 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, + 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, + 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, + 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c + }; + + unsigned long crc = ~0L; + + for( int index = 0 ; index < 32 ; ++index ){ + crc = crc_table[( crc ^ EEPROM[index] ) & 0x0f] ^ (crc >> 4); + crc = crc_table[( crc ^ ( EEPROM[index] >> 4 )) & 0x0f] ^ (crc >> 4); + crc = ~crc; + } + return crc; +} \ No newline at end of file -- cgit v1.2.3-18-g5258 From 5da9792cd61b5ba9eed9fb80874edb52081d6232 Mon Sep 17 00:00:00 2001 From: Chris--A Date: Tue, 24 Mar 2015 13:58:01 +1000 Subject: Fixed EEPROM examples and added readme --- libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino') diff --git a/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino b/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino index 40b08bd..a4baacc 100644 --- a/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino +++ b/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino @@ -38,7 +38,7 @@ unsigned long eeprom_crc( void ){ unsigned long crc = ~0L; - for( int index = 0 ; index < 32 ; ++index ){ + for( int index = 0 ; index < EEPROM.length() ; ++index ){ crc = crc_table[( crc ^ EEPROM[index] ) & 0x0f] ^ (crc >> 4); crc = crc_table[( crc ^ ( EEPROM[index] >> 4 )) & 0x0f] ^ (crc >> 4); crc = ~crc; -- cgit v1.2.3-18-g5258 From d8656b8c5249c9d06cd8ed96b2061759ab69b5bf Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 24 Mar 2015 10:20:00 +0100 Subject: EEPROM: examples: fix Serial for board Leonardo --- libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino') diff --git a/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino b/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino index a4baacc..8461d56 100644 --- a/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino +++ b/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino @@ -14,7 +14,10 @@ void setup(){ //Start serial Serial.begin(9600); - + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + //Print length of data to run CRC on. Serial.print( "EEPROM length: " ); Serial.println( EEPROM.length() ); -- cgit v1.2.3-18-g5258