Shield Code 6.0
Loading...
Searching...
No Matches
AT25M02.hpp
Go to the documentation of this file.
1#ifndef AT25M02_H
2#define AT25M02_H
3
4#include "Arduino.h"
5#include "SPI.h"
6
19{
25 READ = 0x03,
26 WRITE_BYTE = 0x02,
27 WRITE_PAGE = 0x02
28};
33{
34 public:
36 void init();
37
38 /*
39 * Write from the given array to the memory. This data is
40 * appended to the end of the queue.
41 * Returns true if it successfully wrote all bytes.
42 * Returns false if it could not write every byte without
43 * overwriting existing data.
44 */
45 bool writeData(byte* bytes, uint32_t length);
46
47 /*
48 * Write the given number of bytes from the ram into the
49 * destination array. These bytes are taken from the start of
50 * the queue. Returns how many bytes were read.
51 */
52 int readData(byte* dest, uint32_t length);
53
54 /*
55 * Returns how many bytes are free and available to be written
56 * to.
57 */
58 uint32_t freeBytes();
59
60 /*
61 * Returns the number of bytes currently being used.
62 */
63 uint32_t usedBytes();
64
65 /*
66 * Checks if the RAM chip is ready for a new command.
67 */
68 bool isReady();
69
70 private:
71 /*
72 * Reads the status register and returns the register
73 */
74 byte readStatusReg();
75
76 uint32_t usedMemoryBytes();
77 uint32_t freeMemoryBytes();
78 uint32_t usedBufferBytes();
79 uint32_t freeBufferBytes();
80
81 uint32_t readWriteBuffer(byte *dest, uint32_t length);
82 uint32_t readMemory(byte *dest, uint32_t length);
83
84 /*
85 * Sets the Write Status Register
86 */
87 void setWRSR(byte val);
88
89 /*
90 * Waits until the write cycle is done.
91 */
92 void waitUntilReady();
93
94 /*
95 * Writes are page buffered.
96 * Partial page reads are supported.
97 * Start is inclusive, end is exclusive.
98 */
99 uint8_t write_buffer[256];
100 uint32_t wb_end;
101 uint32_t mem_start;
102 uint32_t mem_end;
104
105 SPISettings spi_settings;
106
107 /*
108 * Just writes a page without caring about overwrite
109 */
110 void writePage(uint32_t addr, byte* bytes, uint32_t length);
111
112 /*
113 * Chips select low => enabled on this chip.
114 */
115 void csl();
116
117 /*
118 * Chip select high => disabled on this chip/
119 */
120 void csh();
121
122 /*
123 * Sends a command to the EEPROM.
124 */
125 void sendCommand(Command cmd);
126
127 // Pin out information
129};
130
131#endif
Command
Commands for the AT25M02 chip. Pulled from the data sheet for this chip. All commands are MSB first.
Definition: AT25M02.hpp:19
@ LOW_PWR_WRITE_POLL
Definition: AT25M02.hpp:21
@ READ_STATUS
Definition: AT25M02.hpp:20
@ WRITE_ENABLE
Definition: AT25M02.hpp:22
@ WRITE_STATUS
Definition: AT25M02.hpp:24
@ READ
Definition: AT25M02.hpp:25
@ WRITE_PAGE
Definition: AT25M02.hpp:27
@ WRITE_DISABLE
Definition: AT25M02.hpp:23
@ WRITE_BYTE
Definition: AT25M02.hpp:26
Interfaces with the AT25M02 EEPROM chip.
Definition: AT25M02.hpp:33
void setWRSR(byte val)
Sets the WRSR (Write status reg)
Definition: AT25M02.cpp:272
uint32_t freeBufferBytes()
Definition: AT25M02.cpp:87
uint8_t write_buffer[256]
Definition: AT25M02.hpp:99
void init()
Initialize the AT25M02 EEPROM device. Define spi settings, chip select pin, and set initial variables...
Definition: AT25M02.cpp:39
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.
Definition: AT25M02.cpp:206
void waitUntilReady()
Waits until the RAM is ready to write.
Definition: AT25M02.cpp:289
AT25M02()
Definition: AT25M02.hpp:35
uint32_t readMemory(byte *dest, uint32_t length)
Definition: AT25M02.cpp:141
SPISettings spi_settings
Definition: AT25M02.hpp:105
uint32_t wb_end
Definition: AT25M02.hpp:100
uint32_t usedMemoryBytes()
Definition: AT25M02.cpp:68
uint32_t mem_end
Definition: AT25M02.hpp:102
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....
Definition: AT25M02.cpp:98
bool ram_full
Definition: AT25M02.hpp:103
uint32_t mem_start
Definition: AT25M02.hpp:101
uint32_t usedBufferBytes()
Definition: AT25M02.cpp:82
bool isReady()
Checks if the RAM is ready for a new command.
Definition: AT25M02.cpp:187
void csl()
Definition: AT25M02.cpp:231
uint32_t freeBytes()
Returns how many bytes are free and available to be written to.
Definition: AT25M02.cpp:55
uint32_t readWriteBuffer(byte *dest, uint32_t length)
Definition: AT25M02.cpp:130
void sendCommand(Command cmd)
Definition: AT25M02.cpp:260
int chip_select_pin
Definition: AT25M02.hpp:128
void csh()
Definition: AT25M02.cpp:239
uint32_t freeMemoryBytes()
Definition: AT25M02.cpp:77
byte readStatusReg()
Definition: AT25M02.cpp:245
uint32_t usedBytes()
Returns the number of bytes currently being used.
Definition: AT25M02.cpp:63
void readData()
Definition: main.cpp:496