#include "inc/DSP28_Device.h"
#include "inc/DSP28_GlobalPrototypes.h"
#define uchar unsigned char
#define uint unsigned int
uchar ct;
unsigned int *Led = (unsigned int *)0x4100; 应用的CPLd作为地址的
interrupt void spirx(void)
{
*Led = SpiaRegs.SPIRXBUF;
SpiaRegs.SPIFFRX.bit.RXFFINTCLR=1;
SpiaRegs.SPIFFRX.bit.RXFFOVFCLR=1;这两步是清楚 中断和溢出 标志的
PieCtrl.PIEACK.all= 0x20;这是为了能够再一次相应该中断的
}
interrupt void spitx(void)
{ uint i;
SpiaRegs.SPITXBUF=ct;
while(Spi_TxReady()!=1);
for(i=0;i<50000;i++);
ct++;
PieCtrl.PIEACK.all= 0x20;
SpiaRegs.SPIFFTX.bit.TXFFINTINTCLR=1;
}
void init_spi(void)
{
SpiaRegs.SPICCR.bit.RESET=0;复位spi
SpiaRegs.SPICCR.bit.SPICHAR=0x08;设置发送8个字节
SpiaRegs.SPICCR.bit.SPILBK=1;自检模式打开
SpiaRegs.SPICTL.bit.MASTER_SLAVE=1;必须设置为主模式
SpiaRegs.SPICTL.bit.SPIINTENA=1;中断使能
SpiaRegs.SPICTL.bit.OVERRUN=1;
SpiaRegs.SPICTL.bit.TALK=1;
SpiaRegs.SPIFFTX.all=0xc021;打开接收fifo,并设置接收一个字符
SpiaRegs.SPIFFRX.all=0x0021;
SpiaRegs.SPIBRR=0x1D;
SpiaRegs.SPIFFCT.all=0x00;
SpiaRegs.SPIPRI.all=0x10;
SpiaRegs.SPIFFRX.bit.RXFIFORESET=1;
SpiaRegs.SPIFFTX.bit.TXFIFORESET=1;开始fifo工作
SpiaRegs.SPICCR.bit.RESET=1;
}
void init_gpio(void)
{
EALLOW;
GpioMuxRegs.GPFMUX.bit.SPISIMOA_GPIOF0 = 1;
GpioMuxRegs.GPFMUX.bit.SPICLKA_GPIOF2 = 1;
PieVectTable.SPIRXINTA =&spirx;
PieVectTable.SPITXINTA =&spitx;
PieCtrl.PIECRTL.bit.ENPIE=1;
PieCtrl.PIEIER6.bit.INTx1=1;
PieCtrl.PIEIER6.bit.INTx2=1;
IER =0x20;
EDIS;
}
void main(void)
{
InitSysCtrl();
DINT;
InitPieCtrl();
InitPieVectTable();
init_spi();
init_gpio();
*Led = ct+5;
EINT;
while(1)
{
/* if(Spi_TxReady()==1)
SpiaRegs.SPITXBUF=ct;
while(Spi_TxReady()!=1);
for(i=0;i<50000;i++);
ct++;*/
}
} |