void EEPROM_MultiByte_Write(uint32_t mem_addr, uint8_t pData[], uint16_t size)
{
uint8_t device_addr_write, adress_to_write[2];
init_I2C_EEPROM();
delay_ms(5);
if(mem_addr >= 0x10000){
device_addr_write = EEPROM_I2C_HIGH_ADDRESS_WRITE;
}else{ //memory address points to 00000h to 0FFFFh
device_addr_write = EEPROM_I2C_LOW_ADDRESS_WRITE;
}
adress_to_write[0] = mem_addr>>8;
adress_to_write[1] = mem_addr&0x00FF;
EEPROM_Disable_Write_Protection();
delay_ms(3);
if(size <= 256){
I2C_write_EEPROM((uint32_t)device_addr_write, &adress_to_write[0], &EEPROM_Write_data[0], 2, size);
}
else{
uint16_t new_addr_AVG = mem_addr;
uint8_t no_pages;
for(no_pages = 0; no_pages < 2; no_pages++){
new_addr_AVG = mem_addr + (no_pages * 256);
adress_to_write[0] = new_addr_AVG >> 8;
adress_to_write[1] = new_addr_AVG & 0x00FF;
if(new_addr_AVG >= 0x10000){
device_addr_write = EEPROM_I2C_HIGH_ADDRESS_WRITE;
}
else{
device_addr_write = EEPROM_I2C_LOW_ADDRESS_WRITE;
}
I2C_write_EEPROM((uint32_t)device_addr_write, &adress_to_write[0], EEPROM_Write_data+(no_pages * 256), 2, 256);
}
}
EEPROM_Enable_Write_Protection();
delay_ms(2);
I2C_Reset(I2C1);
I2C1->ROUTEPEN = _I2C_ROUTEPEN_RESETVALUE;
I2C1->ROUTELOC0 = _I2C_ROUTELOC0_RESETVALUE;
CMU_ClockEnable(cmuClock_I2C1, false);
delay_ms(2);
GPIO_PinOutSet(EEPROM_SCL_PORT, EEPROM_SCL_PIN);
delay_ms(1);
GPIO_PinOutSet(EEPROM_SDA_PORT, EEPROM_SDA_PIN);
delay_ms(2);
}