Re: 關於中斷的問題
|
||||
---|---|---|---|---|
版主
|
24Cxx 系列的 I2C EEPROM 算是最基本的 Slave Device ,建議先用 24Cxx 系列的元件來練習 I2C 的 Master 的傳送,等初步熟悉了 I2C 的 protocol 後再連接你的 Slave Device 這樣比較不會搞不清楚是 Master & Slave 的錯。
發表於: 2007/8/17 17:15
|
|||
|
Re: 關於中斷的問題
|
||||
---|---|---|---|---|
新會員
|
跟意麵大說的一樣
小弟我真的是土法煉鋼型的 小弟知道降的學習 底子會很不穩 但..被趕鴨子上架了..ORZ 而且小弟的slave device還不是EEPROM 而是其他種類的device 小弟搞懂了I2C的通訊協定之後 就用PICC裡面的範例程式所改過來的 感謝意麵大大的提醒 我會去買書回來好好學習的~~!!! 謝謝大家..^^
發表於: 2007/8/17 14:02
|
|||
|
Re: 關於中斷的問題
|
||||
---|---|---|---|---|
資深會員
|
小弟寫了個簡單的中斷程式
主程式內只有 while(1) 然後timer1 25ms中斷一次 但每次程式跑一跑 一開始還正常 之後就會出現 只有time1正常計時並執行中斷程式 主迴圈內的printf就再也沒被執行過了 不知道版上各位高手是否有遇過降的問題 可以指點一下小弟我 感謝大家..^^ p.s. 小弟是使用picc編譯 ======================== 小弟使用的是18F452 不好意思 以上這個問題已經解決了 是小弟的程式結構不好 調整之後已經解決了 但現在出現另一個問題 就是在char read_ext_eeprom(int address) {} 這段程式內的 data = i2c_read(0); // read byte 這邊常常都會停很久 導致MCU重啟 而我在I2C的設定中 已經設定在read的部份 會自動restart wdt (#use I2C(master, sda=I2C_SDA, scl=I2C_SCL,RESTART_WDT,FORCE_HW)) 不知道為什麼還是會讓MCU重啟 麻煩大家幫我看看了 謝謝 意麵大哥,謝謝你提醒我把code貼上來..^^ p.s 每次都po些笨問題,謝謝大家不吝指教..^^
//================================
發表於: 2007/8/17 10:40
|
|||
|
Re: 關於中斷的問題
|
||||
---|---|---|---|---|
新會員
|
不好意思
晚點將程式補上 (程式不在身邊..) 感謝大大...^^
發表於: 2007/8/16 14:34
|
|||
|
Re: 關於中斷的問題
|
||||
---|---|---|---|---|
資深會員
|
可以列出所有的程式嗎??至少列出中斷那部分...還有是用那一顆PIC??
發表於: 2007/8/16 0:43
|
|||
|
關於中斷的問題
|
||||
---|---|---|---|---|
新會員
|
小弟寫了個簡單的中斷程式
主程式內只有 while(1) 然後timer1 25ms中斷一次 但每次程式跑一跑 一開始還正常 之後就會出現 只有time1正常計時並執行中斷程式 主迴圈內的printf就再也沒被執行過了 不知道版上各位高手是否有遇過降的問題 可以指點一下小弟我 感謝大家..^^ p.s. 小弟是使用picc編譯 ======================== 小弟使用的是18F452 不好意思 以上這個問題已經解決了 是小弟的程式結構不好 調整之後已經解決了 但現在出現另一個問題 就是在char read_ext_eeprom(int address) {} 這段程式內的 data = i2c_read(0); // read byte 這邊常常都會停很久 導致MCU重啟 而我在I2C的設定中 已經設定在read的部份 會自動restart wdt (#use I2C(master, sda=I2C_SDA, scl=I2C_SCL,RESTART_WDT,FORCE_HW)) 不知道為什麼還是會讓MCU重啟 麻煩大家幫我看看了 謝謝 意麵大哥,謝謝你提醒我把code貼上來..^^ p.s 每次都po些笨問題,謝謝大家不吝指教..^^ ================================ 主程式 void main(void) { InitI2C(); InitPIC(); I2C_Init(); InitInterrupts(); write_ext_eeprom(0x00,0x0A); write_ext_eeprom(0x01,0x0E); write_ext_eeprom(0x02,0x03); write_ext_eeprom(0x03,0x00); write_ext_eeprom(0x05,0x00); write_ext_eeprom(0x04,0x00); write_ext_eeprom(0x06,0x00); write_ext_eeprom(0x07,0x00); printf("Start\r\n"); while(1) { restart_wdt(); if(printf_flag == 1) { printf("now data = %x\r\n",j8); j8 = 0; printf_flag = 0; } } } ============================== 中斷部份 #int_timer1 //0.025sec timer1_interrupt() { disable_interrupts(GLOBAL); Timer1Count++; restart_wdt(); j8 = read_ext_eeprom(0x08); if (Timer1Count>=40) { Timer1Count = 0; printf_flag = 1; } enable_interrupts(GLOBAL); } ================================== I2C(write) void write_ext_eeprom(int address, int data) { int i =9; restart_wdt(); i2c_start(); // start bit i2c_write(0x1C); // control byte i2c_write(address); // Address low byte i2c_write(data); // data byte i2c_stop(); // stop bit delay_ms(11); // delay to allow write } ================================== I2C(read) char read_ext_eeprom(int address) { int i =9; restart_wdt(); i2c_start(); // start bit i2c_write(0x1C); // control byte i2c_write(address); // address low byte i2c_start(); // restart i2c_write(0x1D); // control byte data = i2c_read(0); // read byte i2c_stop(); // stop bit return(data); }
發表於: 2007/8/15 16:03
|
|||
|