Really hope someone can help me as to where I have gone wrong in my code. I am a 25LC1024 micro chip and I'm trying to store a 16 bit integer value into 2 bytes and then reading the 2 bytes and putting them back together. Any help would be much appreciated, THANKS.

// set up to match device datasheet SPI.setBitOrder(MSBFIRST); SPI.setDataMode(SPI_MODE0); SPI.setClockDivider(SPI_CLOCK_DIV2); // max clock is 20MHz, so can set high speed SPI.begin(); // sets up pin modes etc.

The read value printed to the Serial Monitor is always random, usual a very high number such as 65330. Not sure the reading functions manages to do this. Both low and high values are always read as 255

When it always reads everything as 255 it usually indicates a wiring error.But, if for any reason it doesn't write the value into the EEPROM, then you'll get 255 back anyway because that is the initial state of the erased EEPROM.

When I write one integer and to a single address the code works however when put through an array this is when the problem occurs. Trying to write an array of integers using a 'for while loop' to a number of addresses causes funny results. The value saved previously in the address is from writing one value at a time to a single address. If I haven't written something to a single address, thats when 65536 occurs? I think I've neated my code up thought but still having the same issue of writing an array one numbers and reading them back again

// set up to match device data sheet SPI.setBitOrder(MSBFIRST); SPI.setDataMode(SPI_MODE0); SPI.setClockDivider(SPI_CLOCK_DIV2); // max clock is 20MHz, so can set high speed SPI.begin(); // sets up pin modes etc.

// set up to match device datasheet SPI.setBitOrder(MSBFIRST); SPI.setDataMode(SPI_MODE0); SPI.setClockDivider(SPI_CLOCK_DIV2); // max clock is 20MHz, so can set high speed SPI.begin(); // sets up pin modes etc.

In my setup I am also trying to use a DAC. Once I managed to get my code working for the DAC through using digital pin 9 as its OUTPUT for chip select, the pin 10 did not work any more for the external memory.

The result given for the the read value is always 65536 at every address. WHAT IS HAPPENING? I didn't change anything. I have checked the wiring... again and again but I swear its all correct.

The value of 65535 (not 65536?) is a 16-bit word with all ones which is what you get if you read two bytes which have been erased (or deliberately set to 0xFFFF).

Write timing can be critical with EEPROMS. I've had some fun recently getting an I2C 24LC1026 working properly.The 25lc1024 datasheet has this about writing:

Quote

While the write is in progress, the Status Register maybe read to check the status of the WPEN, WIP, WEL,BP1 and BP0 bits (Figure 2-6). A read attempt of amemory array location will not be possible during awrite cycle. When the write cycle is completed, thewrite enable latch is reset.

It is possible that it is still writing one byte when you try to write or read another. After the data has been written you'll have to check the status register to be sure that the write has completed.