F28335 的外设中断源

远远不止 12 个,共用 58 个。那么如何将这 58 个外设中断源分配给这 12 个中断线呢,
这就需要 F28335 的 PIE 外设中断扩展模块来完成。
dsp28335杂记1-LMLPHP

PIE 级中断表。。。。。非常有用

dsp28335杂记1-LMLPHP

每一组 ePWM 模块

dsp28335杂记1-LMLPHP

GPIO输出配置LED
void LED_Init(void)
{
	EALLOW;
	SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1;// 开启GPIO时钟
	//LED1端口配置
	GpioCtrlRegs.GPCMUX1.bit.GPIO68=0;//设置为通用GPIO功能
	GpioCtrlRegs.GPCDIR.bit.GPIO68=1;//设置GPIO方向为输出
	GpioCtrlRegs.GPCPUD.bit.GPIO68=0;//使能GPIO上拉电阻
	//LED2端口配置
	GpioCtrlRegs.GPCMUX1.bit.GPIO67=0;
	GpioCtrlRegs.GPCDIR.bit.GPIO67=1;
	GpioCtrlRegs.GPCPUD.bit.GPIO67=0;
	//LED3端口配置
	GpioCtrlRegs.GPCMUX1.bit.GPIO66=0;
	GpioCtrlRegs.GPCDIR.bit.GPIO66=1;
	GpioCtrlRegs.GPCPUD.bit.GPIO66=0;
	//LED4端口配置
	GpioCtrlRegs.GPCMUX1.bit.GPIO65=0;
	GpioCtrlRegs.GPCDIR.bit.GPIO65=1;
	GpioCtrlRegs.GPCPUD.bit.GPIO65=0;
	//LED5端口配置
	GpioCtrlRegs.GPCMUX1.bit.GPIO64=0;
	GpioCtrlRegs.GPCDIR.bit.GPIO64=1;
	GpioCtrlRegs.GPCPUD.bit.GPIO64=0;
	//LED6端口配置
	GpioCtrlRegs.GPAMUX1.bit.GPIO10=0;
	GpioCtrlRegs.GPADIR.bit.GPIO10=1;
	GpioCtrlRegs.GPAPUD.bit.GPIO10=0;

	//LED7端口配置
	GpioCtrlRegs.GPAMUX1.bit.GPIO11=0;
	GpioCtrlRegs.GPADIR.bit.GPIO11=1;
	GpioCtrlRegs.GPAPUD.bit.GPIO11=0;
	
	GpioDataRegs.GPCSET.bit.GPIO68=1;
	GpioDataRegs.GPCSET.bit.GPIO67=1;
	GpioDataRegs.GPCSET.bit.GPIO66=1;
	GpioDataRegs.GPCSET.bit.GPIO65=1;
	GpioDataRegs.GPCSET.bit.GPIO64=1;
	GpioDataRegs.GPASET.bit.GPIO10=1;
	GpioDataRegs.GPASET.bit.GPIO11=1;
	EDIS;
}
GPIO输入配置KEY
void KEY_Init(void)
{
   EALLOW;
   SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1;// 开启GPIO时钟

   //KEY端口配置
   GpioCtrlRegs.GPAMUX1.bit.GPIO12=0;
   GpioCtrlRegs.GPADIR.bit.GPIO12=0;
   GpioCtrlRegs.GPAPUD.bit.GPIO12=0;

   GpioCtrlRegs.GPAMUX1.bit.GPIO13=0;
   GpioCtrlRegs.GPADIR.bit.GPIO13=0;
   GpioCtrlRegs.GPAPUD.bit.GPIO13=0;

   GpioCtrlRegs.GPAMUX1.bit.GPIO14=0;
   GpioCtrlRegs.GPADIR.bit.GPIO14=0;
   GpioCtrlRegs.GPAPUD.bit.GPIO14=0;

   GpioCtrlRegs.GPBMUX2.bit.GPIO48=0;
   GpioCtrlRegs.GPBDIR.bit.GPIO48=1;
   GpioCtrlRegs.GPBPUD.bit.GPIO48=0;

   GpioCtrlRegs.GPBMUX2.bit.GPIO49=0;
   GpioCtrlRegs.GPBDIR.bit.GPIO49=1;
   GpioCtrlRegs.GPBPUD.bit.GPIO49=0;

   GpioCtrlRegs.GPBMUX2.bit.GPIO50=0;
   GpioCtrlRegs.GPBDIR.bit.GPIO50=1;
   GpioCtrlRegs.GPBPUD.bit.GPIO50=0;
   EDIS;
   
   GpioDataRegs.GPBSET.bit.GPIO48=1;
   GpioDataRegs.GPBSET.bit.GPIO49=1;
   GpioDataRegs.GPBSET.bit.GPIO50=1;
}

char KEY_Scan(char mode)
{
   static char keyl1=1;
   static char keyl2=1;
   static char keyl3=1;
   //第1列扫描
   KEY_L1_SetL;
   KEY_L2_SetH;
   KEY_L3_SetH;
   if(keyl1==1&&(KEY_H1==0||KEY_H2==0||KEY_H3==0))
   {
   	DELAY_US(10000);
   	keyl1=0;
   	if(KEY_H1==0)
   	{
   		return KEY1_PRESS;
   	}
   	else if(KEY_H2==0)
   	{
   		return KEY4_PRESS;
   	}
   	else if(KEY_H3==0)
   	{
   		return KEY7_PRESS;
   	}
   }
   else if(KEY_H1==1&&KEY_H2==1&&KEY_H3==1)
   {
   	keyl1=1;
   }
   if(mode)
   	keyl1=1;
   //第2列扫描
   KEY_L2_SetL;
   KEY_L1_SetH;
   KEY_L3_SetH;
   if(keyl2==1&&(KEY_H1==0||KEY_H2==0||KEY_H3==0))
   {
   	DELAY_US(10000);
   	keyl2=0;
   	if(KEY_H1==0)
   	{
   		return KEY2_PRESS;
   	}
   	else if(KEY_H2==0)
   	{
   		return KEY5_PRESS;
   	}
   	else if(KEY_H3==0)
   	{
   		return KEY8_PRESS;
   	}
   }
   else if(KEY_H1==1&&KEY_H2==1&&KEY_H3==1)
   {
   	keyl2=1;
   }
   if(mode)
   	keyl2=1;
   //第3列扫描
   KEY_L3_SetL;
   KEY_L1_SetH;
   KEY_L2_SetH;
   if(keyl3==1&&(KEY_H1==0||KEY_H2==0||KEY_H3==0))
   {
   	DELAY_US(10000);
   	keyl3=0;
   	if(KEY_H1==0)
   	{
   		return KEY3_PRESS;
   	}
   	else if(KEY_H2==0)
   	{
   		return KEY6_PRESS;
   	}
   	else if(KEY_H3==0)
   	{
   		return KEY9_PRESS;
   	}
   }
   else if(KEY_H1==1&&KEY_H2==1&&KEY_H3==1)
   {
   	keyl3=1;
   }
   if(mode)
   	keyl3=1;

   return KEY_UNPRESS;
}

外设中断PIE配置
interrupt void EXTI1_IRQn(void)void EXTI1_Init(void)
{
   EALLOW;
   SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1;    // GPIO input clock
   EDIS;

   EALLOW;
   //KEY端口配置
   GpioCtrlRegs.GPAMUX1.bit.GPIO12=0;
   GpioCtrlRegs.GPADIR.bit.GPIO12=0;
   GpioCtrlRegs.GPAPUD.bit.GPIO12=0;
   GpioCtrlRegs.GPAQSEL1.bit.GPIO12 = 0;  // 外部中断1(XINT1)与系统时钟SYSCLKOUT同步

   GpioCtrlRegs.GPBMUX2.bit.GPIO48=0;
   GpioCtrlRegs.GPBDIR.bit.GPIO48=1;
   GpioCtrlRegs.GPBPUD.bit.GPIO48=0;
   GpioDataRegs.GPBCLEAR.bit.GPIO48=1;//L
   EDIS;

   EALLOW;
   GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = 12;   // XINT1是GPIO12
   EDIS;

   EALLOW;	// 修改被保护的寄存器,修改前应添加EALLOW语句
   PieVectTable.XINT1 = &EXTI1_IRQn;
   EDIS;   // EDIS的意思是不允许修改被保护的寄存器

   PieCtrlRegs.PIEIER1.bit.INTx4 = 1;          // 使能PIE组1的INT4

   XIntruptRegs.XINT1CR.bit.POLARITY = 0;      // 下降沿触发中断
   XIntruptRegs.XINT1CR.bit.ENABLE= 1;        // 使能XINT1

   IER |= M_INT1;                        // 使能CPU中断1(INT1)
   EINT;                                       // 开全局中断
   ERTM;
}

interrupt void EXTI1_IRQn(void)
{
   Uint32 i;
   for(i=0;i<10000;i++);    //键盘消抖动
   while(!KEY_H1);
   LED2_TOGGLE;
   PieCtrlRegs.PIEACK.bit.ACK1=1;
}
定时器0配置,1与2类比即可
interrupt void TIM0_IRQn(void)//定时器0初始化函数
//Freq:CPU时钟频率(150MHz)
//Period:定时周期值,单位us
void TIM0_Init(float Freq, float Period)
{
   EALLOW;
   SysCtrlRegs.PCLKCR3.bit.CPUTIMER0ENCLK = 1; // CPU Timer 0
   EDIS;

   //设置定时器0的中断入口地址为中断向量表的INT0
   EALLOW;
   PieVectTable.TINT0 = &TIM0_IRQn;
   EDIS;

   //指向定时器0的寄存器地址
   CpuTimer0.RegsAddr = &CpuTimer0Regs;
   //设置定时器0的周期寄存器值
   CpuTimer0Regs.PRD.all  = 0xFFFFFFFF;
   //设置定时器预定标计数器值为0
   CpuTimer0Regs.TPR.all  = 0;
   CpuTimer0Regs.TPRH.all = 0;
   //确保定时器0为停止状态
   CpuTimer0Regs.TCR.bit.TSS = 1;
   //重载使能
   CpuTimer0Regs.TCR.bit.TRB = 1;
   // Reset interrupt counters:
   CpuTimer0.InterruptCount = 0;

   ConfigCpuTimer(&CpuTimer0, Freq, Period);

   //开始定时器功能
   CpuTimer0Regs.TCR.bit.TSS=0;
   //开启CPU第一组中断并使能第一组中断的第7个小中断,即定时器0
   IER |= M_INT1;
   PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
   //使能总中断
   EINT;
   ERTM;
}

interrupt void TIM0_IRQn(void)
{
   EALLOW;
   LED2_TOGGLE;
   PieCtrlRegs.PIEACK.bit.ACK1=1;
   EDIS;
}
EPWM配置,外加PIE中断
interrupt void epwm1_timer_isr(void);
void EPWM1_Init(Uint16 tbprd)
{
   EALLOW;
   SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;   // Disable TBCLK within the ePWM
   SysCtrlRegs.PCLKCR1.bit.EPWM1ENCLK = 1;  // ePWM1
   EDIS;

   // Interrupts that are used in this example are re-mapped to
   // ISR functions found within this file.
   EALLOW;  // This is needed to write to EALLOW protected registers
   PieVectTable.EPWM1_INT = &epwm1_timer_isr;
   EDIS;    // This is needed to disable write to EALLOW protected registers

   EALLOW;
   SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;      // Stop all the TB clocks
   EDIS;

   // Setup Sync
   EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;  // Pass through

   // Allow each timer to be sync'ed
   EPwm1Regs.TBCTL.bit.PHSEN = TB_ENABLE;

   EPwm1Regs.TBPHS.half.TBPHS = 0;

   EPwm1Regs.TBPRD = tbprd;
   EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;    // Count up
   EPwm1Regs.TBCTL.bit.HSPCLKDIV=TB_DIV1;
   EPwm1Regs.TBCTL.bit.CLKDIV=TB_DIV1;
   EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO;     // Select INT on Zero event
   EPwm1Regs.ETSEL.bit.INTEN = 1;  // Enable INT
   EPwm1Regs.ETPS.bit.INTPRD = ET_1ST;           // Generate INT on 1st event

   EALLOW;
   SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;         // Start all the timers synced
   EDIS;

   // Enable CPU INT3 which is connected to EPWM1-6 INT:
   IER |= M_INT3;

   // Enable EPWM INTn in the PIE: Group 3 interrupt 1-6
   PieCtrlRegs.PIEIER3.bit.INTx1 = 1;

   // Enable global Interrupts and higher priority real-time debug events:
   EINT;   // Enable Global interrupt INTM
   ERTM;   // Enable Global realtime interrupt DBGM
}

interrupt void epwm1_timer_isr(void)
{
   static Uint16 cnt=0;

   cnt++;
   if(cnt==5000)
   {
   	cnt=0;
   	LED3_TOGGLE;
   }

   // Clear INT flag for this timer
   EPwm1Regs.ETCLR.bit.INT = 1;
   // Acknowledge this interrupt to receive more interrupts from group 3
   PieCtrlRegs.PIEACK.bit.ACK3 = 1;
}

ADC单路配置
void ADC_Init(void)
{
   // Specific clock setting for this example:
   EALLOW;
   SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1;    // ADC
   EDIS;

   // Specific clock setting for this example:
   EALLOW;
   SysCtrlRegs.HISPCP.all = ADC_MODCLK;	// HSPCLK = SYSCLKOUT/(2*ADC_MODCLK)
   EDIS;

   InitAdc();  // For this example, init the ADC

   // Specific ADC setup for this example:
   AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK;
   AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS;
   AdcRegs.ADCTRL1.bit.SEQ_CASC = 1;        // 1  Cascaded mode
   AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0;
   AdcRegs.ADCTRL1.bit.CONT_RUN = 1;       // Setup continuous run
   AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0x0;

   // Start SEQ1
   AdcRegs.ADCTRL2.all = 0x2000;

}

Uint16 Read_ADCValue(void)
{
   while (AdcRegs.ADCST.bit.INT_SEQ1== 0);
   AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
   return AdcRegs.ADCRESULT0>>4;
}
04-15 04:40