The AT24C32 EEPROM that comes with the DS3132 RTC module has 32kbit of space, meaning it can store 4096 bytes or 4096 characters when using an 8-bit character encoding like ASCII.
To save some useful data on it, we need to divide it into equal blocks that would contain the data. If we want to utilize the entire available space, we should focus on the divisors of the number 4096:
|first factor||second factor|
These are all familiar numbers, the powers of 2 showing factors (whole number divisors) of the number 4096. We can see for instance, that we could divide the memory into 1 block of 4096 bytes or 2058 blocks each 2 bytes long. But these are not very useful decisions. To get to some useful number we have to optimize either for the block size or the number of blocks.
If we choose our block size is 32 bytes, so we can store quite a lot of data at once, we are limited to the 128 blocks as we can see in the table above:
4096 bytes / 32 bytes per block = 128 blocks
This would mean that out data-logger would be able to store last 128 entries. If we decide we need to support at least 256 different entries (blocks) of data, we have to fit the all the entry data into the 16 bytes:
4096 bytes / 256 blocks = 16 bytes per block
Sixteen bytes per block, not great, not terrible. It all depends on the data logged. If all the required information fit there, great. If not, terrible. We could also choose some arbitrary number like 21 bytes per block:
4096 bytes / 21 bytes per block = 195.047619048 bytes per block
Of course, we are not going to deal with fractions of byte here. The above rather means that we have 195 full blocks available and some bytes remain unclaimed somewhere, usually at the beginning or at the end of memory space. In this particular scenario, it is actually just a single unused byte:
4096 bytes MODULO 21 bytes per block = 1 unclaimed byte
Or in other words:
195 blocks * 21 bytes per block = 4095 claimed bytes
This single byte can be used for some other purpose, like a some configuration flag. Just make sure it is changing less often than the actual blocks of data are logged, otherwise you wear that byte out sooner!
This is a 64th post of #100daystooffload.