主程序文件.
#include "DSP28x_Project.h"
void main(void) {
DisableDog();
InitSysCtrl();
InitGpio();
InitSpiaGpio();
DINT;
//TO Flash
//memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
EALLOW;
//使能上拉
GpioCtrlRegs.GPAPUD.bit.GPIO16 = 0;
GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0;
GpioCtrlRegs.GPAPUD.bit.GPIO18 = 0;
GpioCtrlRegs.GPAPUD.bit.GPIO18 = 0;
//使能异步端口操作
GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 3;
GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3;
GpioCtrlRegs.GPAQSEL2.bit.GPIO18 = 3;
GpioCtrlRegs.GPAQSEL2.bit.GPIO19 = 3;
//使能端口第二功能
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 1;
GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 1;
GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 1;
GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 1;
//使能时钟
SysCtrlRegs.PCLKCR0.bit.SPIAENCLK = 1;
//长度使能
SpiaRegs.SPICCR.bit.SPICHAR = 8;
//主机模式
SpiaRegs.SPICTL.bit.MASTER_SLAVE = 1;
//开启数据传输
SpiaRegs.SPICTL.bit.TALK = 1;
//设置波特率(1M)
SpiaRegs.SPIBRR = (12<<0);
//回环(测试)
SpiaRegs.SPICCR.bit.SPILBK = 1;
//接收中断
SpiaRegs.SPICTL.bit.OVERRUNINTENA = 1;
//SPI全局中断允许
SpiaRegs.SPICTL.bit.SPIINTENA = 1;
//存入SPI设置寄存器数值
SpiaRegs.SPICCR.bit.SPISWRESET = 1;
//设置运行优先级
SpiaRegs.SPIPRI.bit.FREE = 1;
//初始化SPI FIFO通道
SpiaRegs.SPIFFTX.bit.SPIRST = 1;
//SPI FIFO使能
SpiaRegs.SPIFFTX.bit.SPIFFENA = 1;
//重置发送FIFO
SpiaRegs.SPIFFTX.bit.SPIRST = 0;
//FIFO发送中断清除
SpiaRegs.SPIFFTX.bit.TXFFINTCLR = 1;
//FIFO发送中断层数
SpiaRegs.SPIFFTX.bit.TXFFIL = (1<<0);
//FIFO发送中断使能
SpiaRegs.SPIFFTX.bit.TXFFIENA = 1;
//重置接收FIFO
SpiaRegs.SPIFFRX.bit.RXFIFORESET = 0;
//FIFO接收中断清除
SpiaRegs.SPIFFRX.bit.RXFFINTCLR = 1;
//FIFO接收中断层数
SpiaRegs.SPIFFRX.bit.RXFFIL = (1<<0);
//FIFO接收中断使能
SpiaRegs.SPIFFRX.bit.RXFFIENA = 1;
//FIFO发送中断清除
SpiaRegs.SPIFFTX.bit.TXFFINTCLR = 1;
//FIFO接收中断清除
SpiaRegs.SPIFFRX.bit.RXFFINTCLR = 1;
EDIS;
IER = 0x0000;
IFR = 0x0000;
InitPieCtrl();
InitPieVectTable();
//打开第六组中断
IER |= M_INT6;
PieCtrlRegs.PIEIER6.bit.INTx1 = 1;
PieCtrlRegs.PIEIER6.bit.INTx2 = 1;
EINT;
for(;;){
SpiaRegs.SPITXBUF = 0xAA;
IDLE;
}
}
中断向量:
interrupt void SPIRXINTA_ISR(void) // SPI-A
{
asm (" ESTOP0");
PieCtrlRegs.PIEACK.all = PIEACK_GROUP6;
SpiaRegs.SPIFFRX.bit.RXFFINTCLR = 1;
}
interrupt void SPITXINTA_ISR(void) // SPI-A
{
asm (" ESTOP0");
PieCtrlRegs.PIEACK.all = PIEACK_GROUP6;
SpiaRegs.SPIFFTX.bit.TXFFINTCLR = 1;
}
结果执行到IDLE无法继续,资料说是IDLE可以被任何中断唤醒,换成延迟后,也不能进入中断.
可以别让我去看示例吗?我不喜欢用函数封装的开发,我想这样,告诉我如何改改?
JunJie Li1:
示例文件非常好,适合我这些从430上来的用户的风格.