[Fx2lib-devel] i2c write to eeprom
Status: Beta
Brought to you by:
mulicheng
From: S S <ss...@ho...> - 2011-06-15 12:45:17
|
Hi Folks, Could I suggest we modify the i2c eeprom_write function in i2c.c to the code given below? The current function writes one byte at a time on the eeprom. This is less than optimum as each write triggers a refresh on the eeprom which refreshes a whole page (64 bytes). That is sub-optimal on two accounts: 1- the eeprom endurance is specified in number of page refresh (OK at 1 million it might not be an issue) but 2- it takes about 64 times longer than needed to write a program into the eeprom. Modifying the function to write 64 bytes at a time (which fit nicely in one EP0 transfer) cuts down the program writing time from 73s down to 2s. Cheers, Sébastien BOOL eeprom_write(BYTE prom_addr, WORD addr, WORD length, BYTE* buf) { BYTE addr_len=0; BYTE addr_buffer[2]; BYTE bs; BYTE *data_buffer_ptr = buf; BYTE *last_data_ptr = buf + length; if (EEPROM_TWO_BYTE) { addr_len = 2; addr_buffer[0] = MSB(addr); addr_buffer[1] = LSB(addr); } else { addr_len = 1; addr_buffer[0] = LSB(addr); } while ( data_buffer_ptr < last_data_ptr ) { if ( (last_data_ptr - data_buffer_ptr) > MAX_EEP_WRITE) { // Should not be the case if data is from an EP0 transfer bs = MAX_EEP_WRITE; } else bs = last_data_ptr - data_buffer_ptr; if ( ! i2c_write ( prom_addr, addr_len, addr_buffer, bs, data_buffer_ptr ) ) return FALSE; addr += bs; // Potentially more data to come so remember to increase the address and buffer pointer data_buffer_ptr += bs; } return TRUE; } |