• slider image 514
  • slider image 516
  • slider image 517
  • slider image 518
  • slider image 519
:::


Browsing this Thread:   1 Anonymous Users






Re: SPI傳輸中斷致動
#7
版主
版主


查看用戶資訊
參照:

PML1986 寫道:
想請問板大
關於SPI中斷如果是用函數去寫

它是如何跳到中斷執行??


void __attribute__((__interrupt__)) _SPI1Interrupt(void)

程式是以哪種條件跳到上列中斷去執行

例如計時器中斷 是設計週期暫存器PR值 指令周期到達PR直就會跳到中斷

小弟不太了解 SPI是必須在函數檔設定哪種條件才能控制何時跳中斷

在 dsPIC30F Peripheral Module 教育訓練裡的 SPI Slave 一段程式,設定 SPI Slave 中斷部分:
#include     <p30F4011.h>
#include    <spi.h>
#include     "spiSubs.h"


#define        MODE_SPICS    ADPCFGbits.PCFG2


void    Init_SPI(void)
{
    
unsigned int     config1 config2 ;

    
MODE_SPI_CS ;                //  CS PIN for SPIis Digital Mode
    
SPI_CS ;                    //    Inactive CS
    
DIR_SPI_CS ;                //    SS PIN is "input" when Slave mode 
    
    
SPI1CON 0x22dc ;                //    0010 0010 1101 1100
    
SPI1STAT 0xa000 ;                //    1010 0000 0000 0000
    
SPI1BUF 0x00 ;
    
    
ConfigIntSPI1(SPI_INT_EN SPI_INT_PRI_4) ;

}

有興趣請自行下在此教育訓練的 SPI 裡的練習二 SPI Slave

發表於: 2009/11/5 12:07
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: SPI傳輸中斷致動
#6
高級會員
高級會員


查看用戶資訊
謝謝您

我會根據您的建議在自己試試看

有疑問會再提出

感謝您的幫助

發表於: 2009/11/3 18:16
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: SPI傳輸中斷致動
#5
高級會員
高級會員


查看用戶資訊
你貼的是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
Morgan Chuang
s909201@gmail.com
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: SPI傳輸中斷致動
#4
高級會員
高級會員


查看用戶資訊
您好
小弟問的是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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: SPI傳輸中斷致動
#3
高級會員
高級會員


查看用戶資訊
我的程式碼(範例,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
Morgan Chuang
s909201@gmail.com
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: SPI傳輸中斷致動
#2
高級會員
高級會員


查看用戶資訊
不懂你在問什麼...你問的是哪顆晶片?

中斷通常是由硬體提供資源,
非軟體可以模擬...(當然你有OS的話令當別論!)

中斷的Microchip C語言寫法,在網路上可以找到很多!
概念是中斷後進入中斷函式,在函式裡確認中斷的Flag是哪支,大概是如此!!

發表於: 2009/11/3 16:39
Morgan Chuang
s909201@gmail.com
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


SPI傳輸中斷致動
#1
高級會員
高級會員


查看用戶資訊
想請問板大
關於SPI中斷如果是用函數去寫

它是如何跳到中斷執行??


void __attribute__((__interrupt__)) _SPI1Interrupt(void)

程式是以哪種條件跳到上列中斷去執行

例如計時器中斷 是設計週期暫存器PR值 指令周期到達PR直就會跳到中斷

小弟不太了解 SPI是必須在函數檔設定哪種條件才能控制何時跳中斷

發表於: 2009/11/3 11:46
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... ]

教育訓練中心

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