Re: SPI傳輸中斷致動
|
||||
---|---|---|---|---|
高級會員
|
謝謝您
我會根據您的建議在自己試試看 有疑問會再提出 感謝您的幫助
發表於: 2009/11/3 18:16
|
|||
|
Re: SPI傳輸中斷致動
|
||||
---|---|---|---|---|
高級會員
|
你貼的是SPI的initial副函式,非SPI函式,SPI_Read應該會有類似,
val = SPI_Read(); 或是 val = SPI_BUFF; 這種方式! 當然在Initial時要設定中斷(如果你有此需求!) 然後在中斷內寫 void __attribute__((__interrupt__)) _SPI1Interrupt(void) { val = SPI_Data_Buff; // 讀值,要看是哪個Register IFS0bits.SPI1IF = 0; // 清除flag... } val 變數記得令為Global parameter. 這樣在main()裡的while()就可以print此變數內容! 此外,在main()的開頭,要加入"打開中斷機制". void main() { INTCON = ?; INTCON2 = ?; INTCON3 = ?; RFIF = ?; RFIE = ?; IPEN = ?; GIEH = ?; GIEL = ?; .................... 諸如此類的Registers. while(1) {....} } 這樣說明,希望能幫到你!
發表於: 2009/11/3 18:00
|
|||
|
Re: SPI傳輸中斷致動
|
||||
---|---|---|---|---|
高級會員
|
您好
小弟問的是DSPIC30F4011這塊晶片 void __attribute__((__interrupt__)) _SPI1Interrupt(void) { IFS0bits.SPI1IF = 0; } void Init_SPI(void) { unsigned int config1 , config2 ; config1 = FRAME_ENABLE_OFF & FRAME_SYNC_OUTPUT & ENABLE_SDO_PIN & SPI_MODE16_ON & SPI_SMP_OFF & SPI_CKE_ON & SLAVE_SELECT_ENABLE_OFF & CLK_POL_ACTIVE_HIGH & MASTER_ENABLE_ON & SEC_PRESCAL_7_1 & PRI_PRESCAL_64_1; config2 = SPI_ENABLE & SPI_IDLE_CON & SPI_RX_OVFLOW_CLR ConfigIntSPI1(SPI_INT_PRI_6 & SPI_INT_EN); OpenSPI1(config1,config2); } 這是SPI副函式 和中斷的寫法 我是想問說 當主函式呼叫SPI副函式執行 需再Init_SPI()中設定哪種條件下還是說當主函式中整個跑完才會跑到中斷把Flag清零 才會讓他跳到中斷 void __attribute__((__interrupt__)) _SPI1Interrupt 把IFS0bits.SPI1IF = 0;清零
發表於: 2009/11/3 16:53
|
|||
|
Re: SPI傳輸中斷致動
|
||||
---|---|---|---|---|
高級會員
|
我的程式碼(範例,pic18f4620):
#include "p18f4620.h" void setup_interrupt(void); void high_isr(void); void low_isr(void); void main() { ...................(略) } // ------------------------------------------------------------------- // High Interrupt #pragma code high_vector=0x08 void interrupt_at_high_vector(void) { _asm GOTO high_isr _endasm } #pragma code #pragma interrupt high_isr void high_isr(void) { // ------------------------------------------ // Rx Interrupt if (PIR1bits.RCIF) // USART Rx Interrupt { ......... } // ------------------------------------------ if (TMR1IF) // Timer 1 Interrupt { .................. } //if (TMR1IF) // ------------------------------------------ } //interrupt routine // ------------------------------------------------------------------- // Low Interrupt #pragma code low_vector=0x18 void interrupt_at_low_vector(void) { _asm GOTO low_isr _endasm } #pragma code #pragma interrupt low_isr void low_isr(void) { } //interrupt routine // ------------------------------------------------------------------- void setup_interrupt(void) { .......... }
發表於: 2009/11/3 16:45
|
|||
|
Re: SPI傳輸中斷致動
|
||||
---|---|---|---|---|
高級會員
|
不懂你在問什麼...你問的是哪顆晶片?
中斷通常是由硬體提供資源, 非軟體可以模擬...(當然你有OS的話令當別論!) 中斷的Microchip C語言寫法,在網路上可以找到很多! 概念是中斷後進入中斷函式,在函式裡確認中斷的Flag是哪支,大概是如此!!
發表於: 2009/11/3 16:39
|
|||
|
SPI傳輸中斷致動
|
||||
---|---|---|---|---|
高級會員
|
想請問板大
關於SPI中斷如果是用函數去寫 它是如何跳到中斷執行?? void __attribute__((__interrupt__)) _SPI1Interrupt(void) 程式是以哪種條件跳到上列中斷去執行 例如計時器中斷 是設計週期暫存器PR值 指令周期到達PR直就會跳到中斷 小弟不太了解 SPI是必須在函數檔設定哪種條件才能控制何時跳中斷
發表於: 2009/11/3 11:46
|
|||
|