diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index b175aa8..4763055 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -22,12 +22,8 @@
-
-
-
+
-
-
@@ -100,7 +96,7 @@
-
+
@@ -115,7 +111,6 @@
-
@@ -161,7 +156,7 @@
-
+
@@ -228,6 +223,7 @@
+
1701692190748
diff --git a/driver/eeprom.c b/driver/eeprom.c
index 461c2e2..1238e39 100644
--- a/driver/eeprom.c
+++ b/driver/eeprom.c
@@ -21,103 +21,72 @@
#include "driver/i2c.h"
#include "driver/system.h"
-void EEPROM_ReadBuffer(uint16_t Address, void *pBuffer, uint8_t Size)
-{
- I2C_Start();
-
- I2C_Write(0xA0);
-
- I2C_Write((Address >> 8) & 0xFF);
- I2C_Write((Address >> 0) & 0xFF);
-
- I2C_Start();
-
- I2C_Write(0xA1);
-
- I2C_ReadBuffer(pBuffer, Size);
-
- I2C_Stop();
-}
-void EEPROM_WriteBuffer(uint16_t Address, const void *pBuffer)
-{
- if (pBuffer == NULL || Address >= 0x2000)
- return;
-
-
- uint8_t buffer[8];
- EEPROM_ReadBuffer(Address, buffer, 8);
- if (memcmp(pBuffer, buffer, 8) != 0)
- {
+void EEPROM_ReadBuffer(uint32_t Address, void *pBuffer, uint8_t Size) {
+ if(Address<0x10000) {
I2C_Start();
+
I2C_Write(0xA0);
+
I2C_Write((Address >> 8) & 0xFF);
I2C_Write((Address >> 0) & 0xFF);
- I2C_WriteBuffer(pBuffer, 8);
+
+ I2C_Start();
+
+ I2C_Write(0xA1);
+
+ I2C_ReadBuffer(pBuffer, Size);
+
I2C_Stop();
- }
+ } else{
+ I2C_Start();
+ uint8_t P0 = (StartAddr / 0x10000) << 1;
- // give the EEPROM time to burn the data in (apparently takes 5ms)
- SYSTEM_DelayMs(8);
-}
+ I2C_Write(0xA4|P0);
-#define AT24C1024_ADDRESS 0xA4
-#define AT24C1024_PAGE_SIZE 64
-
-void E1EPROM_ReadBuffer_1024(uint32_t Address, void *pBuffer, uint16_t Size) {
- if (pBuffer == NULL || Address >= 0x20000) // Address limit for AT24C1024 (17-bit address)
- return;
-
- uint16_t bytesRead = 0;
- uint8_t* dataPointer = (uint8_t*)pBuffer;
-
- while (bytesRead < Size) {
- uint16_t bytesToRead = (Size - bytesRead < AT24C1024_PAGE_SIZE) ? (Size - bytesRead) : AT24C1024_PAGE_SIZE;
- uint16_t offset = Address % AT24C1024_PAGE_SIZE;
+ I2C_Write((Address >> 8) & 0xFF);
+ I2C_Write((Address >> 0) & 0xFF);
I2C_Start();
- I2C_Write(AT24C1024_ADDRESS | ((Address >> 16) & 0x01)); // Sending device address and MSB of memory address
- I2C_Write((uint8_t)(Address >> 8)); // Sending address high byte
- I2C_Write((uint8_t)(Address & 0xFF)); // Sending address low byte
- I2C_Start();
- I2C_Write(AT24C1024_ADDRESS | 0x01); // Sending device address with read bit
- uint8_t buffer[AT24C1024_PAGE_SIZE];
- I2C_ReadBuffer(buffer, AT24C1024_PAGE_SIZE);
+ I2C_Write((0xA4|P0)+1);
- // Copy the relevant portion of the buffer to the output buffer
- memcpy(dataPointer, buffer + offset, bytesToRead);
-
- bytesRead += bytesToRead;
- dataPointer += bytesToRead;
- Address += bytesToRead;
+ I2C_ReadBuffer(pBuffer, Size);
I2C_Stop();
}
}
-void E1EPROM_WriteBuffer_1024(uint32_t Address, const void *pBuffer, uint16_t Size) {
- if (pBuffer == NULL || Address >= 0x20000) // Address limit for AT24C1024 (17-bit address)
+void EEPROM_WriteBuffer(uint32_t Address, const void *pBuffer) {
+ if (pBuffer == NULL || Address >= 0x20000)
return;
+ if (Address < 0x10000) {
- uint8_t buffer[AT24C1024_PAGE_SIZE];
- uint32_t endAddress = Address + Size;
- for (uint32_t addr = Address; addr < endAddress; addr += AT24C1024_PAGE_SIZE) {
- uint16_t bytesToWrite = (endAddress - addr < AT24C1024_PAGE_SIZE) ? (endAddress - addr) : AT24C1024_PAGE_SIZE;
- uint16_t offset = Address % AT24C1024_PAGE_SIZE;
- uint16_t remaining = AT24C1024_PAGE_SIZE - offset;
- bytesToWrite = (bytesToWrite < remaining) ? bytesToWrite : remaining;
-
- EEPROM_ReadBuffer(addr - offset, buffer, AT24C1024_PAGE_SIZE);
- if (memcmp(pBuffer, buffer + offset, bytesToWrite) != 0) {
+ uint8_t buffer[8];
+ EEPROM_ReadBuffer(Address, buffer, 8);
+ if (memcmp(pBuffer, buffer, 8) != 0) {
I2C_Start();
- I2C_Write(AT24C1024_ADDRESS | ((addr >> 16) & 0x01)); // Sending device address and MSB of memory address
- I2C_Write((uint8_t)(addr >> 8)); // Sending address high byte
- I2C_Write((uint8_t)(addr & 0xFF)); // Sending address low byte
- I2C_WriteBuffer(pBuffer, bytesToWrite);
+ I2C_Write(0xA0);
+ I2C_Write((Address >> 8) & 0xFF);
+ I2C_Write((Address >> 0) & 0xFF);
+ I2C_WriteBuffer(pBuffer, 8);
I2C_Stop();
}
- pBuffer += bytesToWrite;
- // give the EEPROM time to burn the data in (assuming 5ms per page write)
- SYSTEM_DelayMs(5);
+
+ // give the EEPROM time to burn the data in (apparently takes 5ms)
+ SYSTEM_DelayMs(8);
+ } else {
+ uint8_t P0 = (Address / 0x10000) << 1;
+ I2C_Start();
+ I2C_Write(0xA4 | P0);
+ I2C_Write((Address >> 8) & 0xFF);
+ I2C_Write((Address >> 0) & 0xFF);
+ I2C_WriteBuffer(pBuffer, 64);
+ I2C_Stop();
+ SYSTEM_DelayMs(8);
+
}
+
}
+
+
+
diff --git a/driver/eeprom.h b/driver/eeprom.h
index 165671e..5cae018 100644
--- a/driver/eeprom.h
+++ b/driver/eeprom.h
@@ -19,10 +19,8 @@
#include
-void EEPROM_ReadBuffer(uint16_t Address, void *pBuffer, uint8_t Size);
-void EEPROM_WriteBuffer(uint16_t Address, const void *pBuffer);
-void E1EPROM_ReadBuffer_1024(uint32_t Address, void *pBuffer, uint16_t Size) ;
- void E1EPROM_WriteBuffer_1024(uint32_t Address, const void *pBuffer, uint16_t Size) ;
+void EEPROM_ReadBuffer(uint32_t Address, void *pBuffer, uint8_t Size);
+void EEPROM_WriteBuffer(uint32_t Address, const void *pBuffer);
#endif
diff --git a/main.c b/main.c
index 6d92f5f..2fbb914 100644
--- a/main.c
+++ b/main.c
@@ -212,14 +212,14 @@ void Main(void)
// for (int i =MDC_ADD[0]; i < MDC_ADD[0]+16; ++i) {
// EEPROM_WriteBuffer(i,&A[i-MDC_ADD[0]]);
// }
- uint8_t B[64];
- memset(B,'B',sizeof (B));
- E1EPROM_WriteBuffer_1024(0x10000,B,64);
- E1EPROM_ReadBuffer_1024(0x10000,B,64);
- UART_Send(B,64);
+
while(1)
{
-
+ uint8_t B[64];
+ memset(B,'B',sizeof (B));
+ EEPROM_ReadBuffer(0x10000,B,64);
+ EEPROM_ReadBuffer(0x10000,B,64);
+ UART_Send(B,64);
}
while (1)
{