Memory (Part 4)

Part 1234567

So, ready to test your new EEPROM chips ? Let’s go.

For sake of simplicity, we tested the PlainEEPROM_SPI library on all chips which are available in 8 pins PDIP (Plastic Dual In Line Packages): 25LC080A, 25LC160, 25LC320, 25LC320A, 25LC640, 25LC640A, 25LC256, 25LC512 and 25LC1024. Next picture illustrates one of these chips where the pin#1 is identified with an indent or paint dot mark. All these EEPROM chips are pin to pin compatible so that you can very easily upgrade the hardware


25LCxxx memory chips are featuring a SPI port and the table below contains a description of the pinout for all these chips.

PINNAME Arduino's pin description
1CS (Chip Select)10SPI allows one master, actually Arduino, to talk to many slaves : only one EEPROM in our case.
2MISO (Master In Slave Out)12On this line; data flows from the memory to the master.
3 WP (Write Protect)+5V When WP is pulled to ground; no writing to the memory is allowed.
5MOSI (Master Out Slave In)11Used to send data or commands to the EEPROM.
6CLK (Clock)13 The synchronization clock generated by Arduino for its remotely controlled devices.
7HLD (Hold) +5V It suspends the transmission from the EEPROM when pulled down, hook HLD to +5V for continuous operation.

It is now time for coding the test procedures which will come along with PlainSPI_EEPROM!

The first proposed test is plain trivial. It consists in executing the following sequence of operations :

  • Initialize the EEPROM chip
  • Fill each page from  the memory with a constant
  • Read back each page and check if their content matches the written values.

The memory chip is initialized within the setup routine. Next to the initialization, it is possible to get access to global information such as the number of pages (Pages() function), the size of pages (PageSize() function) or the actual buffer pointer location (BufferPointer()).

void setup(void) 
	/* Reset all CS pins from PORTB */
	DDRB |= 0x07; /* Set PB0:2 as output ports */
	PORTB |= 0x07; /* Set PB0:2 to high */
	/* Initialize serial communication */
	Serial.print("Initialize EEPROM");
	_pages = MEM.Pages();
	_pageSize = MEM.PageSize();
	_bufferPtr = MEM.BufferPointer();
	Serial.print("Pages: ");
	Serial.print("Page size: ");

The following function actually executes the test :

void RunTest(void) 
	/* Write pages */
	Serial.print("Write all pages "); 		
	for (uint16_t p = 0; p < _pages; p++) {
		uint8_t *ptr = _bufferPtr;
		for (uint16_t i = 0; i < _pageSize; i++, ptr++) {
			*ptr = _fiftyFive;
	/* Read and check all pages */
	Serial.print("Read and check all pages "); 		
	uint16_t globalErrors = 0;
	for (uint16_t p = 0; p < _pages; p++) {
		uint16_t localErrors = 0;
		uint8_t *ptr = _bufferPtr;
		for (uint16_t i = 0; i < _pageSize; i++, ptr++) {
			if (*ptr != _fiftyFive) {
				localErrors += 1;
		if (localErrors != 0) {
			globalErrors += 1;
	if (globalErrors != 0) {
		Serial.print("Pages in error: "); 		
	} else {
		Serial.print("No errors"); 		

Eventually, the loop function will run the test once in order to save the number of write cycles of the chips.

Reminder: While the number of read cycles is unlimited, the number of write cycles is limited to typically 1.000.000 cycles!

Thus the loop routine…

void loop(void) 
	while(true); /* Run once */

The next post will contain another example which will focus on mixed types of data.

Next post on same subject

Leave a Reply

You must be logged in to post a comment.