今天刚拿到板子,马上焊了最小系统,连上JATG程序下载正常,利用系统的时钟编写了一个定时器中断交替点亮2个LED的程序。程序在瑞泰2812实验箱上运行正常,可以在LED的驱动引脚上得到一个方波信号。说明程序运行正常,可以驱动LED灯闪烁运行。程序下载到开发板运行,给DSP供电的电源芯片ASM1117-5开始温度升高。运行程序,灯没有被驱动。发现2812芯片,与2812芯片供电电源芯片ASM1117-5温度升高到烫手,给外设供电的ASM1117-5没有发现温度大幅升高。给发迅速停止程序运行,芯片温度降低。可以推测为在2812开始运行时,电源芯片电流急剧增大。 附录程序 #include "DSP281x_Device.h" // DSP281x Headerfile Include File #include "DSP281x_Examples.h" // DSP281x Examples Include File
// 中断服务程序函数原型声明 interrupt void cpu_timer0_isr(void);
//*定义的各个外设寄存器的地址*// #define LEDS *(int *)0xc0000 //#define CTRGR *(int *)0x108000 //#define CTRLCDCMDR *(int *)0x108001 //#define CTRKEY *(int *)0x108001 //#define CTRLCDCR *(int *)0x108002 //#define CTRCLKEY *(int *)0x108002 //#define CTRLCDLCR *(int *)0x108003 //#define CTRLCDRCR *(int *)0x108004 //#define CTRLA *(int *)0x108005 //#define CTRLR *(int *)0x108007 #define LED1_ON GpioDataRegs.GPFDAT.bit.GPIOF6=0 #define LED1_OFF GpioDataRegs.GPFDAT.bit.GPIOF6=1 #define LED2_ON GpioDataRegs.GPFDAT.bit.GPIOF7=0 #define LED2_OFF GpioDataRegs.GPFDAT.bit.GPIOF7=1
void Gpio_select(void);
//声明全局变量 int i=0,nCount; unsigned int uLBD,z;
void main(void) { // unsigned int uPort8000;
InitSysCtrl(); //初始化cpu
DINT; //关中断
InitPieCtrl(); //初始化pie寄存器
IER = 0x0000; //禁止所有的中断 IFR = 0x0000; //清除所有的中断标志CPU级
InitPieVectTable(); //初始化pie中断向量表,使中断指向可知状态
EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.TINT0 = &cpu_timer0_isr; //指定中断服务子程序 EDIS; // This is needed to disable write to EALLOW protected registers
CpuTimer0.RegsAddr = &CpuTimer0Regs; CpuTimer0Regs.PRD.all = 0xffff; //定时计数器最大周期 CpuTimer0Regs.TPR.all = 0x0010; //定时器预定标寄存器,4分频 CpuTimer0Regs.TIM.all = 0; //定时计数器 CpuTimer0Regs.TPRH.all = 0; //定时器预定标寄存器 // 确定定时器停止: CpuTimer0Regs.TCR.bit.TSS = 1; //定时器停止状态位,停止 CpuTimer0Regs.TCR.bit.SOFT = 1; //CPU定时器仿真模式(自由运行) CpuTimer0Regs.TCR.bit.FREE = 1; //CPU定时器仿真模式(自由运行) // 重新使能定时器: CpuTimer0Regs.TCR.bit.TRB = 1; //定时器重新装载控制位 CpuTimer0Regs.TCR.bit.TIE = 1; //定时器中断使能位 // 初始化定时器中断计数器: CpuTimer0.InterruptCount = 0; //定时器中断计数器
StartCpuTimer0(); //启动定时器0
// Enable CPU INT1 which is connected to CPU-Timer 0: IER |= M_INT1;
// Enable TINT0 in the PIE: Group 1 interrupt 7 PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
// Enable global Interrupts and higher priority real-time debug events: EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM //CTRGR=0; // 初始化ICETEK-CTR //CTRGR=0x80; //CTRGR=0; //CTRLR=0; // 关闭东西方向的交通灯 //CTRLR=0x40; // 关闭南北方向的交通灯 //uPort8000=CTRCLKEY; // Gpio_select(); // Toggle I/Os using DATA register for ever while ( 1 ) { Gpio_select(); // Toggle I/Os using DATA register for ever }
}
//interrupt void cpu_timer0_isr(void) //{ //int j,k; // z = CpuTimer0.InterruptCount++;
// Acknowledge this interrupt to receive more interrupts from group 1 // PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //清除中断标志 // CpuTimer0Regs.TCR.bit.TIF = 1; //重启,计数器递减到零时会置位,定时器中断标志 // CpuTimer0Regs.TCR.bit.TRB = 1; //定时器重新装载PRD寄存器周期值, //并且PSC装载定时器分频寄存器TDDR中的值 // if ( nCount==0 ) // { // LEDS=uLBD; // uLBD++; uLBD%=16; // } // nCount++; nCount%=194; //取余运算
//}
void Gpio_select(void) { EALLOW; GpioMuxRegs.GPAMUX.all= 0x0330; //设置GPIOA9,8,5,4为外设功能,4,5为PWM,8,9为编码器解码; GpioMuxRegs.GPBMUX.all= 0x0300; //设置GPIOB8,9为外设功能,8,9为编码器解码; GpioMuxRegs.GPDMUX.all= 0x0000; //设置为GPIO GpioMuxRegs.GPFMUX.all= 0x003F; //设置GPIOF5,4为SCI,设置GPIOF3,2,1,0为SPI; GpioMuxRegs.GPEMUX.all= 0x0000; //设置为GPIO GpioMuxRegs.GPGMUX.all= 0x0030; //设置GPIOG5,4为SCI; GpioMuxRegs.GPADIR.all= 0; // GPIO作为输出口 GpioMuxRegs.GPBDIR.all= 0x0012; // GPIOB2,4作为输入口 GpioMuxRegs.GPDDIR.all= 0; GpioMuxRegs.GPEDIR.all= 0x0003; // GPIOE0,1作为输入口 GpioMuxRegs.GPFDIR.all= 0; GpioMuxRegs.GPGDIR.all= 0;
GpioMuxRegs.GPAQUAL.all= 0; // Set GPIO input qualifier values GpioMuxRegs.GPBQUAL.all= 0; GpioMuxRegs.GPDQUAL.all= 0; GpioMuxRegs.GPEQUAL.all= 0; EDIS; } //=========================================================================== // No more. //======================================== //实验现象:LED灯约每0.1S变化一下状态 unsigned int Led_Flag;
interrupt void cpu_timer0_isr(void) { CpuTimer0.InterruptCount++; // Acknowledge this interrupt to receive more interrupts from group 1 PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //清除中断标志 CpuTimer0Regs.TCR.bit.TIF = 1; //重启,计数器递减到零时会置位,定时器中断标志 CpuTimer0Regs.TCR.bit.TRB = 1; //定时器重新装载PRD寄存器周期值, //并且PSC装载定时器分频寄存器TDDR中的值 if(Led_Flag == 1) { LED2_OFF; LED1_ON; Led_Flag = 0; } else { LED2_ON;// = 1; LED1_OFF; Led_Flag = 1; } } |