在这个函数中,我使用的是spi来操作led显示,来检测spi是否正常工作。
在这里遇到的情况是
74HC595 的位选问题,需要先锁存后开启。我实验了先开后锁,这是不能够用的
#include "inc/DSP28_Device.h"
#include "inc/DSP28_GlobalPrototypes.h"
#define uchar unsigned char
#define uint unsigned int
unsigned int * SPI_CS = (unsigned int *) 0x4500; //0X4500是CPLD的SPICS地址
unsigned long int a;
Uint16 SpiCode[]={0x7E7E,0x2929,0x2c2c,0x6666,0xa4a4,0xa0a0,
0x3e3e,0x2020,0x2424,0x2222,0xe0e0,0xb1b1,0x6868,0xa1a1,0xa3a3,0xffff,0xdfdf};
void init_spi(void)
{
EALLOW;
///设置SPI口外设功能,这里我们只用了SPISIMO和SPICLK
GpioMuxRegs.GPFMUX.bit.SPISIMOA_GPIOF0 = 1;
///GpioMuxRegs.GPFMUX.bit.SPISOMIA_GPIOF1 = 1;
GpioMuxRegs.GPFMUX.bit.SPICLKA_GPIOF2 = 1;
///GpioMuxRegs.GPFMUX.bit.SPISTEA_GPIOF3 = 1;
EDIS;
SpiaRegs.SPICCR.bit.RESET=0;
SpiaRegs.SPICCR.bit.SPICHAR=0x0f;
SpiaRegs.SPICCR.bit.RESET=1;
SpiaRegs.SPICTL.bit.TALK=1;
//SpiaRegs.SPIBRR=0x1d;
SpiaRegs.SPICTL.bit.MASTER_SLAVE=1;
}
void delay()
{
uint x,y;
for(x=0;x<50000;x++)
for(y=0;y<5;y++);
}
void main()
{
InitSysCtrl();
DINT;
InitPieCtrl();
InitPieVectTable();
init_spi();
EINT;
while(1)
{
if(Spi_TxReady() == 1)
SpiaRegs.SPITXBUF=SpiCode[a%16];
while(Spi_TxReady()!= 1);
a++;
delay();
*SPI_CS=0x01;*SPI_CS=0x00;
}
} |