DSP28335的SPI发送
#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
unsigned char table[]={
0xC0, //"0"
0xF9, //"1"
0xA4, //"2"
0xB0, //"3"
0x99, //"4"
0x92, //"5"
0x82, //"6"
0xF8, //"7"
0x80, //"8"
0x90, //"9"
0x88, //"A"
0x83, //"B"
0xC6, //"C"
0xA1, //"D"
0x86, //"E"
0x8E, //"F"
0x89, //"H"
0xC7, //"L"
0xC8, //"n"
0xC1, //"u"
0x8C, //"P"
0xA3, //"o"
0xBF, //"-"
0xFF, //熄灭
0xFF //自定义
};
void init(void)
{
InitSysCtrl();
InitSpiaGpio();
EALLOW;
GpioCtrlRegs.GPBMUX2.bit.GPIO58=0;
GpioCtrlRegs.GPBDIR.bit.GPIO58=1;
GpioCtrlRegs.GPBMUX2.bit.GPIO59=0;
GpioCtrlRegs.GPBDIR.bit.GPIO59=1;
GpioCtrlRegs.GPBMUX2.bit.GPIO63=0;
GpioCtrlRegs.GPBDIR.bit.GPIO63=1;
GpioCtrlRegs.GPBMUX2.bit.GPIO62=0;
GpioCtrlRegs.GPBDIR.bit.GPIO62=1;
EDIS;
GpioDataRegs.GPBSET.bit.GPIO58=1;
GpioDataRegs.GPBSET.bit.GPIO59=0;
GpioDataRegs.GPBSET.bit.GPIO62=0;
GpioDataRegs.GPBSET.bit.GPIO63=1;
}
void delay(void)
{
long int i,j;
for(i=0;i<1000;i++)
for(j=0;j<10000;j++);
}
void delay1(void)
{
long int i,j;
for(i=0;i<10;i++)
for(j=0;j<10;j++);
}
void init_spi(void)
{
SpiaRegs.SPICCR.bit.CLKPOLARITY=1;
SpiaRegs.SPICTL.bit.TALK=1;//发送启动
SpiaRegs.SPICTL.bit.CLK_PHASE=0;
SpiaRegs.SPICTL.bit.MASTER_SLAVE=1;
SpiaRegs.SPICCR.bit.SPICHAR=0x0f;
SpiaRegs.SPIBRR =0x007F;
SpiaRegs.SPICCR.bit.SPISWRESET=1;
SpiaRegs.SPIPRI.bit.FREE=1;
}
void main(void)
{
int k;
init();
init_spi();
while(1)
{
for(k=0;k<16;k++)
{
if(SpiaRegs.SPISTS.bit.BUFFULL_FLAG!=1)
{
SpiaRegs.SPITXBUF=table[k];
delay();
// delay();
}
// delay();
}
}
}