check_spi.zip
(100.48 KB)
自检程序是设定在spi发送和接收中断中执行的!
#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;
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;
SpiaRegs.SPICCR.bit.SPICHAR=0x08;
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;
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;
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++;*/
}
} |