Sahara's WebLog

日記のような、備忘録のような、うらみつらみのような、自慢のような…。

PIC12F675 + I2C + AT24C256B Page write

EEPROMへのデータの書き込みにかかる時間を気にするなら、1バイトずつ書き込むByte writeでなく、まとめて書き込むPage writeが有利だ。
Byte writeで64バイト書き込むには最大で64 × 5msの時間がWrite Cycle Timeとして費やされるが、これをPage writeで書き込めば、一番時間を食うWrite Cycle Timeの最大5msを、ページのサイズである64バイトを送り終わった後に1度だけ待てばいいからだ。

なので、64バイト分の配列でも用意しておいてそこにデータをキープしておき、たまったら一気に書き込めばいいと思っていた。
が、PIC12F675はそんな贅沢を許さない。
ので、32バイトずつとかでもいいのかなと思い、斜め読みだったデータ・シートをもう一度読み直した。

PAGE WRITE: The 256K EEPROM is capable of 64-byte page writes.
A page write is initiated the same way as a byte write, but the microcontroller does not send a stop condition after the first data word is clocked in. Instead, after the EEPROM acknowledges receipt of the first data word, the microcontroller can transmit up to 63 more data words. The
EEPROM will respond with a “0” after each data word received. The microcontroller must terminate the page write sequence with a stop condition (see Figure 9).
The data word address lower six bits are internally incremented following the receipt of each data word. The higher data word address bits are not incremented, retaining the memory page row location. When the word address, internally generated, reaches the page boundary, the following byte is placed at the beginning of the same page. If more than 64 data words are transmitted to the EEPROM, the data word address will “roll over” and previous data will be overwritten. The address “roll over” during write is from the last byte of the current page to the first byte of the same page.

64バイト以下ならサイズは少なくても構わないようだ。
ただ、書き始めたページの範囲を越えた場合には、同じページの先頭へ戻ってそこに上書きしてしまうということらしい。

64バイト確保できないなら、たとえば32バイトとか区切りのいいサイズにして、ページを越境するようなことにだけはならないように気をつけてコードを書けばいいようだ。

わざとページを越えるような書き込みをしてみた。
pic16f88_12f675_09
0x002Aから書き始めて、0x00~0x31までの32バイトを書き込んだところ、0x15でページの最後に来るので、0x16以降はページの先頭に戻って書き込まれている。
ちなみに100kbpsでこれを行ってみると、32バイトを19msで送信し終わっている。
pic16f88_12f675_10

このエントリーをはてなブックマークに追加

Posted under: I2C, MPLAB X, PIC その他, PIC12F675


コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

Time limit is exhausted. Please reload CAPTCHA.