|
明確這樣幾條,就能正確理解IIC總線的原理:
1. scl信號(hào)永遠(yuǎn)是由主機(jī)產(chǎn)生的。
2. 主機(jī)和從機(jī)都能作為發(fā)送端,也都能作為接收端
3. 主機(jī)在寫數(shù)據(jù)的時(shí)候主機(jī)是發(fā)送端,從機(jī)是接收端,主機(jī)在讀數(shù)據(jù)的時(shí)候從機(jī)是發(fā)送端,主機(jī)是接收端。
4. 在頁寫數(shù)據(jù)的時(shí)候會(huì)以8或16作為頁寫數(shù)據(jù)的個(gè)數(shù),如果寫入的數(shù)據(jù)超過這個(gè)數(shù)值那么先前寫入的數(shù)據(jù)會(huì)被覆蓋掉。
5. 在連續(xù)讀的模式下數(shù)據(jù)的地址會(huì)一直增加下去,沒有頁讀的8或16的限制。
6. 在SCL在高電平的時(shí)候DAT是不能變化的,否則這個(gè)變化會(huì)作為開始或結(jié)束的信號(hào)。根據(jù)這一條就可以斷定,DAT數(shù)據(jù)的變化是在SCL為低電平的時(shí)候,也就能說明在向24C02寫數(shù)據(jù)的時(shí)候?qū)懲?個(gè)數(shù)據(jù)之后的 那個(gè)下降沿會(huì)觸發(fā)第9個(gè)應(yīng)答位。這個(gè)應(yīng)答位必須在SCL變?yōu)楦唠娖街熬头(wěn)定下來,否則會(huì)被視為起始位或是結(jié)束位。同位的道理在讀數(shù)據(jù)的時(shí)候,當(dāng)24C02發(fā)完一個(gè)8位的數(shù)據(jù)之后,在之后的那個(gè)SCL的下降沿,單片機(jī)必須先將DAT變?yōu)楦唠娙缓蟛拍軐CL拉為高電平,否則也會(huì)出現(xiàn)上面的問題也就是會(huì)被24C02視為起始位或是結(jié)束位。
7. 24C02芯片有一個(gè)TWR參數(shù),就是兩次寫操作的最小時(shí)間間隔,這個(gè)時(shí)間因不同的芯片生產(chǎn)廠商有不同,一般兩次寫的時(shí)間間隔設(shè)定為10ms是足夠的。
8. 關(guān)于24C02的頁寫入模式,我察看了一個(gè)24C02的數(shù)據(jù)手冊(cè)對(duì)頁寫模式的摘寫下來:Page Write. For the Page Writemode, the MODEpin must be at VIL. The Page Write mode allows upto 8 bytes to bewritten in a single write cycle,providedthat they are all located in the same ’row’in the memory: that is the 5 mostsignificant mem-ory address bits (A7-A3) are the same. The mastersends from oneup to 8 bytes of data, which areeach acknowledged by the memory. After eachbyteis transfered, the internal byte address counter(3 least significant bits only)is incremented. Thetransfer is terminated by the master generating aSTOPcondition. Care must be taken to avoid ad-dress counter ’roll-over’ which couldresult in databeing overwritten. Note that, for any write mode,the generationby the master of the STOP conditionstarts the internal memory program cycle.All inputsare disabled until the completion of this cycle andthe memory willnot respond to any request.
這里說明頁寫模式下最多只能寫入8個(gè)字節(jié),如果寫得超過8個(gè)字節(jié),前面的數(shù)據(jù)就會(huì)被覆蓋掉,這里就要注意寫入24C02的基地址了,只能是8的整數(shù)倍了,而且也只能最多寫入8個(gè)數(shù)據(jù),這個(gè)在編寫頁寫函數(shù)時(shí)要特注意。
當(dāng)然對(duì)于不是24C02的芯片,比如24C04,或是容量更大的芯片,這個(gè)數(shù)據(jù)就不是8個(gè)了,有可能是16個(gè),或是32個(gè)。
9. 關(guān)于24C02的順序讀的操作,是沒有頁的概念的,下面是摘于24C02的數(shù)據(jù)手冊(cè):
Sequential Read. This mode can be initiated witheither a Current Address Read or a Random Ad-dress Read. However, in this case the masterDOES acknowledge the data byte output and thememory continues to output the next byte in se-quence. To terminate the stream of bytes, themaster must NOT acknowledge the last byte out-put, but MUST generate a STOP condition. Theoutput data is from consecutive byte addresses,with the internal byte address counter automat-ically incremented after each byte output. After acount of the last memory address, the addresscounter will ’roll- over’ and the memory will continueto output data.
10. 應(yīng)答是在SCL在低電平的時(shí)候?qū)AT拉為低電平,非應(yīng)答是在SCL在低電平的時(shí)候?qū)AT拉為高電平,這是沒有任何問題的,只是要區(qū)分,應(yīng)答是主機(jī)發(fā)出的還是從機(jī)發(fā)出的,因?yàn)閼?yīng)答的一定是接收方,主機(jī)和從機(jī)都可能是接收方,但是這里注意非應(yīng)答數(shù)據(jù)一定是主機(jī)發(fā)出的,從這一點(diǎn)可以看出主機(jī)和從機(jī)在邏輯上是不對(duì)稱的。
|
評(píng)分
-
查看全部評(píng)分
|