中斷
參考文檔SPRUFN3C
外設中斷示意圖:
外設級:
當一個外設發生了一箇中斷,特定的外設寄存器中相應的中斷標誌位(IF)就會置位。如果相應的中斷使能位被設置,外設就會向PIE控制器產生一箇中斷請求。如果中斷在外設級沒有被使能,IF位仍然保持置1狀態直到被軟件清除。如果中斷之後使能,IF位仍然是1,中斷請求將會被PIE響應。
外設寄存器的中斷標誌應該被手動清除。
PIE級:
PIE把 8個外設和外中斷多路複用爲一個CPU中斷。這些中斷被分爲12組。同一組的中斷複用一個CPU中斷。例如:PIE組1複用CPU中斷1(INT1),PIE組12複用CPU中斷12(INT12)。連接到CPU其餘的中斷的中斷源是沒有被複用的,PIE直接將請求傳遞到CPU。
對於複用的中斷源,每個中斷組的PIE塊中有相應的標誌寄存器(PIEIFRx)和使能寄存器(PIEIERx)(X = PIE組1 - PIE組12)。組內的每個位,稱爲y,對應於一個8路複用的中斷,因此PIEIFRx.y 和PIEIERx.y (y =1-8)對應於中斷PIE組X(X= 1〜12)。另外,每個PIE中斷組都有一箇中斷答應位。
當有向PIE控制器的請求時,相應的PIE中斷標誌(PIEIFRx.y)就會置1,如果PIE中斷使能位(PIEIERx.y)被設置,PIE控制器就會檢查相應的PIEACKx位,確認CPU是否爲中斷做好準備。如果PIEACKx位已被清除,PIE就會向CPU發送一箇中斷請求。如果PIEACKx位被置位,PIE等到它別清除,再發送INTx的請求。
CPU級:
當請求被髮送到CPU,CPU級相應的與INTx的中斷標誌位(IFR)被置位,一旦在IFR的標誌被設定後,相應的中斷不會被服務,直到是但設置了CPU的中斷使能寄存器(IER)或調試中斷使能寄存器(DBGIER)和全局中斷屏蔽位(INTM)。
外中斷配置步驟:
1. 編寫中斷服務函數
2. 把中斷服務函數地址賦值到的中斷矢量表。
3. 使能或者除能上拉電阻(GPxPUD)。
ePWM模式默認除能,其他功能默認使能。模擬IO沒有上拉電阻。
4. 選擇引腳功能(GPxMUXn)。
5. 如果是數字IO的話,選擇方向(GPxDIR)。
6. 輸入採樣設置(GPxCTRL、 GPxQSELn)。
7. 把相應的GPIO作爲XINTn(n=1-3)中斷源GPIOxINTnSEL
8. 選擇低功耗模式下的喚醒輸入引腳(GPIOLPMSEL)。
9. 設置觸發方式(xINTnCR)。
10. 使能XINTn中斷(外設級使能)。(xINTnCR)
11. 使能PIE。(PIECTRL)
12. 在PIE中使能該中斷(PIE級使能)。(PIEIERn)
13. 在IER中使能該組的中斷(CPU級使能)。
14. 總中斷使能。
15. 在中斷服務函數中要清除中斷應答位
程序設計:
按鍵GPIO12觸發外中斷,在中斷服務函數中翻轉IO。
程序:
程序:
/*********************************************
標題:INT_test.c
軟件平臺:CCS v5.2
硬件平臺:C2000 LaunchPad
主頻:60M
描述:練習外中斷,測試按鍵
基於2802x C/C++ Header Files V1.26
author:小船
data:2012-09-25
As supplied, this project is configured for "boot to SARAM"
operation. The 2802x Boot Modetable is shown below.
$Boot_Table
While an emulator is connected to your device, the TRSTn pin = 1,
which sets the device into EMU_BOOT boot mode. In this mode, the
peripheral boot modes are as follows:
Boot Mode: EMU_KEY EMU_BMODE
(0xD00) (0xD01)
---------------------------------------
Wait !=0x55AA X
I/O 0x55AA 0x0000
SCI 0x55AA 0x0001
Wait 0x55AA 0x0002
Get_Mode 0x55AA 0x0003
SPI 0x55AA 0x0004
I2C 0x55AA 0x0005
OTP 0x55AA 0x0006
Wait 0x55AA 0x0007
Wait 0x55AA 0x0008
SARAM 0x55AA 0x000A <-- "Boot to SARAM"
Flash 0x55AA 0x000B
Wait 0x55AA Other
Write EMU_KEY to 0xD00 and EMU_BMODE to 0xD01 via the debugger
according to the Boot Mode Table above. Build/Load project,
Reset the device, and Run example
$End_Boot_Table
**********************************************/
#include"DSP28x_Project.h" // Device Headerfile and Examples Include File
#include"LEDs.h"
interruptvoidKey_On(void);
void main(void)
{
// Step 1. Initialize SystemControl:
// PLL, WatchDog, enablePeripheral Clocks
// This example function is foundin the DSP2802x_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initalize GPIO:
// This example function is foundin the DSP2802x_Gpio.c file and
// illustrates how to set the GPIOto it's default state.
// InitGpio(); // Skipped for this example
// Step 3. Clear all interruptsand initialize PIE vector table:
// Disable CPU interrupts
DINT;
// Initialize PIE controlregisters to their default state.
// The default state is all PIEinterrupts disabled and flags
// are cleared.
// This function is found in theDSP2802x_PieCtrl.c file.
InitPieCtrl();
// Disable CPU interrupts andclear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector tablewith pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entiretable, even if the interrupt
// is not used in thisexample. This is useful for debugpurposes.
// The shell ISR routines arefound in DSP2802x_DefaultIsr.c.
// This function is found inDSP2802x_PieVect.c.
InitPieVectTable();
// Step 4. Initialize all theDevice Peripherals:
// This function is found inDSP2802x_InitPeripherals.c
// InitPeripherals(); // Notrequired for this example
// Step 5. User specific code:
EALLOW;
PieVectTable.XINT1= &Key_On;
GpioCtrlRegs.GPAPUD.bit.GPIO12 = 0; //除能上拉電阻
GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 0; //GPIO12
GpioCtrlRegs.GPADIR.bit.GPIO12 = 0; //輸入
GpioCtrlRegs.GPAQSEL1.bit.GPIO12 = 2; // 6 samples
GpioCtrlRegs.GPACTRL.bit.QUALPRD1 = 0xff;//採樣週期爲510*Tsysclk,窗口寬度爲5*510*Tsysclk=2550/60M=42.5us
GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 12; //GPIO12作爲xint1的中斷源
EDIS;
XIntruptRegs.XINT1CR.bit.POLARITY = 1; //上升沿觸發中斷
XIntruptRegs.XINT1CR.bit.ENABLE = 1; //外中斷1使能
EALLOW;
PieCtrlRegs.PIECTRL.bit.ENPIE = 1; //使能PIE
PieCtrlRegs.PIEIER1.bit.INTx4 = 1; //使能int1.4
IER |= 0x0001;//使能int1
EINT;
EDIS;
LEDs_init();
while(1)
{
};
}
interruptvoidKey_On(void)
{
LED_toggle(LED0);
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}
//=========================================================================
// No more.
//=========================================================================