SPI的配置;
void spi_init()
{
SpiaRegs.SPICCR.all =0x0007; // Reset on, rising edge, 16-bit char bits
SpiaRegs.SPICTL.all =0x0006; // Enable master mode, normal phase,
SpiaRegs.SPIBRR =0x00FF; // enable talk, and SPI int disabled.
// SpiaRegs.SPIBRR =0x0085;
SpiaRegs.SPICCR.all =0x0087; // Relinquish SPI from Reset
SpiaRegs.SPIPRI.bit.FREE = 1; // Set so breakpoints don't disturb xmission
}
void spi_fifo_init()
{
// Initialize SPI FIFO registers
SpiaRegs.SPIFFTX.all=0xE040;
SpiaRegs.SPIFFRX.all=0x204F;
SpiaRegs.SPIFFCT.all=0x0;
}
实际使用时:
AD_CS=0;
SpiaRegs.SPITXBUF=DA_Data[0];
SpiaRegs.SPITXBUF=DA_Data[1];
SpiaRegs.SPITXBUF=DA_Data[2];
while(1)
{
if((SpiaRegs.SPISTS.all&0x40)==1) break;//如果的中断标志位为1,则证明SPI已经发送成功,则停止等待
}
SpiaRegs.SPIRXBUF=SpiaRegs.SPIRXBUF;//虚读SPIRXBUF,以清除SPI中断标志
// while(SpiaRegs.SPIFFTX.bit.TXFFST!=0){}
AD_CS=1;
|