• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users






Re: 關於I2C EEPROM的ACK問題請教
#4
資深會員
資深會員


查看用戶資訊
感謝版主及foxjan的回覆,
正如版主說的,我原本就有將組與和C的EEPROM範例都下載下來,比對了也有發覺這個問題,還蠻納悶的,現在豁然開朗,
謝謝!

祝新年快樂

發表於: 2010/2/10 17:47
不怕苦...苦半輩子;怕苦...苦一輩子
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於I2C EEPROM的ACK問題請教
#3
版主
版主


查看用戶資訊
這種 Code Example 也有 C 的版本,參考一下底下的範例連結。

http://www.microchip.com.tw/modules/w ... lefile.php?cid=17&lid=267

當初在寫這組語時,我省定了一個檢查 ACK/NACK 的動作。Slave 在收捯完整的 Control Byte 後會自動回 ACK 的,Master 會主動發送一個 Clk Pulse 將 ACK 讀回來。因為我認定 ACK 一定會送所以我就不去檢查 ACK 的狀態了。所以妳會誤以為少做了一步檢查的動作。

實際的程式應如下所示,因為沒有加入Time-Out 的檢查機制,所以當不接 EEPROM 時程式會卡住的,你可以不檢查或加入 Time-Out 的判斷。
//***********************************************
//*         Write a Byte to EEPROM              *
//*   - ctrl : Control Byte of EEPROM            *
//*   - addr : Location of EEPROM            *
//*   - data : Data Byte of EEPROM                *
//***********************************************
void EEPROM_Write(unsigned char ctrl,unsigned char addr,unsigned char data)
{
    
IdleI2C();                         // ensure module is idle
      
StartI2C();                        // Start condition
    
I2C_Done();                        // Wait Start condition completed and clear SSPIF flag                

    
WriteI2C(ctrl);                    // Write Control+Write to EEPROM & Check BF flag
    
while(SSPCON2bits.ACKSTAT);     // wait until received the Acknowledge from EEPROM
    
I2C_Done();                        // Clear SSPIF flag

    
WriteI2C(addr);                    // Write Address to EEPROM
    
while(SSPCON2bits.ACKSTAT);        // wait until received the Acknowledge from EEPROM
    
I2C_Done();

    
WriteI2C(data);                    // Write Data to EEPROM
    
while(SSPCON2bits.ACKSTAT);     // wait until received the Acknowledge from EEPROM
    
I2C_Done();

    
StopI2C();                        // Stop condition
    
I2C_Done();                        // Wait the Stop condition completed
}

發表於: 2010/2/10 17:39
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 關於I2C EEPROM的ACK問題請教
#2
資深會員
資深會員


查看用戶資訊
大多由USER 在使用的I2C控制 皆為MASTER
既然是MASTER 當然是等人家的ACK 自己不送ACK

除非要撰寫SLAVE端的機制 才需要用到吧

這個社會 都是 小弟附和大哥的 沒有大哥附和小弟的

...既然問了ACK 怎麼沒問 NO ACK的事

MCU-->I2C IC
主----->從
回話呀--->是,大哥

簡單的來說

去讀寫別人 當然是等人家回
被人家讀寫 當然是你要回

發表於: 2010/2/10 17:17
My name is jan,Jan是棒的
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


關於I2C EEPROM的ACK問題請教
#1
資深會員
資深會員


查看用戶資訊
請教各位高手:

小弟目前因工作需求,須使用I2C EEPROM,在MCHP TW的下載中心 » 網友提供資料 > 範例程式 下載i2c_ee.asm,翻成C來使用,也看完了I2C Timing的圖,有個疑問請教各位

範例中
EE_Byte_Write
call StartI2C ; Set SSPCON2.SEN
;
bcf I2C_Ctrl,0 ;Clear for Write Command
movf I2C_Ctrl,W ; Send Slave Address to I2C Bus
call Send_Byte
;
movf I2C_Addr,W ; Send out the Command
call Send_Byte
;
movf I2C_Data,W ; Send out the Data
call Send_Byte
;
call StopI2C ; Initial STOP Condition
return
;

在送完I2C_Ctrl時,不用送ACK嗎?
我有對照時序圖,有ACK存在,還是小弟關念有問題?

Attach file:



jpg  (0.00 KB)


發表於: 2010/2/10 16:59
不怕苦...苦半輩子;怕苦...苦一輩子
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------