Spi.c
上传用户:yzchenlin
上传日期:2022-03-09
资源大小:712k
文件大小:2k
- #include <string.h>
- #include "2410lib.h"
- #include "spi.h"
- #include "def.h"
- #define spi_count 0x80
- #define SPI_BUFFER _NONCACHE_STARTADDRESS
- volatile char *spiTxStr,*spiRxStr;
- volatile int endSpiTx;
- /****************************************************************
- * SMDK2400 SPI configuration *
- * GPG2=nSS0, GPE11=SPIMISO0, GPE12=SPIMOSI0, GPE13=SPICLK0 *
- * GPG3=nSS1, GPG5 =SPIMISO1, GPG6 =SPIMOSI1, GPG7 =SPICLK1 *
- * SPI1 is tested by OS(WINCE). So, Only SPI0 is tested by this code *
- ****************************************************************/
- void Test_Spi_MS_poll(void)
- {
- int i=0;
- char *txStr,*rxStr;
- // SPI_Port_Init(0);
- rGPEUP&=~(0x3800);
- rGPEUP|=0x2000;
- rGPECON=((rGPECON&0xf03fffff)|0xa800000);
- rGPGUP|=0x4;
- rGPGCON=((rGPGCON&0xffffffcf)|0x30); // Slave(nSS)
-
- Uart_Printf("[SPI Polling Tx/Rx Test]n");
- Uart_Printf("Connect SPIMOSI0 into SPIMISO0.n");
- endSpiTx=0;
- spiTxStr="ABC";
- spiRxStr=(char *) SPI_BUFFER;
- txStr=(char *)spiTxStr;
- rxStr=(char *)spiRxStr;
- Uart_Printf("[Test point 1]n");
- rSPPRE0=0x0; //if PCLK=50Mhz,SPICLK=25Mhz
- rSPCON0=(0<<5)|(1<<4)|(1<<3)|(1<<2)|(0<<1)|(0<<0);//Polling,en-SCK,master,low,A,normal
- rSPPIN0=(0<<2)|(1<<1)|(0<<0);//dis-ENMUL,SBO,release
- Uart_Printf("[Test point 1]n");
- while(endSpiTx==0)
- {
- if(rSPSTA0&0x1) //Check Tx ready state
- {
- if(*spiTxStr!=' ')
- rSPTDAT0=*spiTxStr++;
- else
- endSpiTx=1;
- while(!(rSPSTA0&0x1)); //Check Rx ready state
- *spiRxStr++=rSPRDAT0;
- }
- i=i+1;
- Uart_Printf("[Test point %d]n",i);
- }
- rSPCON0=(0<<5)|(0<<4)|(1<<3)|(1<<2)|(0<<1)|(0<<0);//Polling,dis-SCK,master,low,A,normal
- *(spiRxStr-1)=' ';//remove last dummy data & attach End of String(Null)
- //
- Port_Init();
- Uart_Init(0,115200);
- Uart_Select(0);
- //
- Uart_Printf("Tx Strings:%sn",txStr);
- Uart_Printf("Rx Strings:%s :",rxStr);
-
- if(strcmp(rxStr,txStr)==0)
- Uart_Printf("O.K.n");
- else
- Uart_Printf("ERROR!!!n");
- }