17#define CHIP_SELECT_PIN 4
20#define SPI_DATA_RATE 5000000
25#define NUM_PAGES (RAM_SIZE / PAGE_LEN)
149 byte addr_byte2 = (byte) ((
mem_start >> 16) & 0xFF);
150 byte addr_byte1 = (byte) ((
mem_start >> 8) & 0xFF);
151 byte addr_byte0 = (byte) (
mem_start & 0xFF);
156 SPI.transfer(addr_byte2);
157 SPI.transfer(addr_byte1);
158 SPI.transfer(addr_byte0);
159 SPI.transfer(dest, len);
161 SPI.endTransaction();
176 if (memlen < length) {
181 return memlen + buflen;
194 ready = (SPI.transfer(0) & 0x01) == 0;
196 SPI.endTransaction();
209 byte addr_byte2 = (byte) ((addr >> 16) & 0xFF);
210 byte addr_byte1 = (byte) ((addr >> 8) & 0xFF);
211 byte addr_byte0 = (byte) (addr & 0xFF);
218 SPI.transfer(addr_byte2);
219 SPI.transfer(addr_byte1);
220 SPI.transfer(addr_byte0);
221 SPI.transfer(bytes, length);
223 SPI.endTransaction();
251 ret = SPI.transfer(0);
253 SPI.endTransaction();
266 SPI.endTransaction();
281 volatile byte status = SPI.transfer(0);
283 SPI.endTransaction();
297 }
while ((SPI.transfer(0) & 0x01) != 0);
299 SPI.endTransaction();
Provides a library to interact with Microchip's AT25M02 chip. This treats the chip as a circular queu...
Command
Commands for the AT25M02 chip. Pulled from the data sheet for this chip. All commands are MSB first.
void setWRSR(byte val)
Sets the WRSR (Write status reg)
uint32_t freeBufferBytes()
int readData(byte *dest, uint32_t length)
Write the given number of bytes from the ram into the destination array. These bytes are taken from t...
uint8_t write_buffer[256]
void init()
Initialize the AT25M02 EEPROM device. Define spi settings, chip select pin, and set initial variables...
void writePage(uint32_t addr, byte *bytes, uint32_t length)
Write the given data to the RAM in a page write. Increments mem_end when done.
void waitUntilReady()
Waits until the RAM is ready to write.
uint32_t readMemory(byte *dest, uint32_t length)
uint32_t usedMemoryBytes()
bool writeData(byte *bytes, uint32_t length)
Write from the given array to the memory. This data is appended to the end of the queue....
uint32_t usedBufferBytes()
bool isReady()
Checks if the RAM is ready for a new command.
uint32_t freeBytes()
Returns how many bytes are free and available to be written to.
uint32_t readWriteBuffer(byte *dest, uint32_t length)
void sendCommand(Command cmd)
uint32_t freeMemoryBytes()
uint32_t usedBytes()
Returns the number of bytes currently being used.