Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
Spi.c
Upload User: yzchenlin
Upload Date: 2022-03-09
Package Size: 712k
Code Size: 2k
Category:
ARM-PowerPC-ColdFire-MIPS
Development Platform:
C/C++
- #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");
- }