I'm assuming that each patch is 512 bytes and layout out sequentially across the EEPROM. Is it safe to assume any patch starting with 0x80 is a patch and any other value is blank? (assuming EEPROM is flashed with value hex).
I2C frequency is 262144Hz (a multiple of the spin clock)
The EEPROM takes up to 5ms to write to, regardless of whether you write 1 byte or a page (32 bytes). The I2C bus mustn't be accessed during this time or you will get errors. Therefore it makes sense to write patches to EEPROM in pages of 32 bytes for a 32x speed increase!
Here's some simple Arduino code to do this:
Code: Select all
#define EEPROM_SIZE 4096
#define EEPROM_ADDRESS 0x50
#define EEPROM_PAGE_SIZE 32
#define EEPROM_PAGES (EEPROM_SIZE / EEPROM_PAGE_SIZE)
uint16_t addr = 0;
Wire.begin();
Wire.setClock(262144);
for (uint8_t i=0;i<EEPROM_PAGES;++i)
{
Wire.beginTransmission(EEPROM_ADDRESS);
Wire.write(addr >> 8); // MSB
Wire.write(addr & 0xFF); // LSB
for (uint8_t j=0;j<EEPROM_PAGE_SIZE;++j)
{
Wire.write(pgm_read_byte(&(SPIN_EEPROM[addr])));
addr++;
}
Wire.endTransmission();
delay(5); //time for page write
}