void SPI_InitialGPIO()
{
rGPECON |= 2<<22|2<<24|2<<26;//配置SPI0 GPE端口的GPE11 GPE12 GPE13 分别为MISO MOSI SPICLK
//rGPGCON |= 3<<4;//配置GPG端口的GPG2 为nss0
//rGPEUP &=~(0x3800);
rGPEUP |=(1<<11)|(1<<12)|(1<<13);//配置上拉
rGPGUP |=0x4;//GPG2上拉禁止
rGPGCON=rGPGCON & (~(3<<4)) | (1<<4);
rGPGDAT|=0x4;
rGPFCON = 0x1000;
rGPFUP=0xb0;
//rGPFDAT |= (6<<0);
//rGPBUP &= ~(1<<1);
}
//void SPI0_Interrupt_Init()
//{
//rINTMSK &=~(1<<22);
//pISR_SPI0 = (U32)SPI0_ISR;
//}
void SPI_Mode()
{
// ClearPending(BIT_SPI0);//清除中断挂起
//配置寄存器
rSPPRE0=0x4;//SPICLK=5M
rSPCON0=(0<<5)|(1<<4)|(1<<3)|(1<<2)|(0<<1)|(0<<0); //中断方式
//rSPPIN0=(0<<2)|(1<<1)|(0<<0);
//rGPGDAT &= 0XFFFB;
}
unsigned char SPIReadByte(void)
{
unsigned char SpiRx;
// ClearPending(BIT_SPI0);
rGPGDAT &= ~(1<<2);
while(!(rSPSTA0&0x1));
SpiRx=rSPRDAT0;
while(!(rSPSTA0&0x1));
rGPGDAT |= (1<<2);
return SpiRx;
}
void SPIWriteByte(unsigned char SPIData)
{
//ClearPending(BIT_SPI0);
rGPGDAT &= ~(1<<3);
while(!(rSPSTA0&0x1));
rSPTDAT0=SPIData;
while(!(rSPSTA0&0x1));
rGPGDAT |= (1<<3);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>