SPI
OVERVIEW
The S3C2440A Serial Peripheral Interface (SPI) can interface with the serial data transfer. The S3C2440A includes
two SPI, each of which has two 8-bit shift registers for transmission and receiving, respectively. During an SPI
transfer, data is simultaneously transmitted (shifted out serially) and received (shifted in serially). 8-bit serial data at
a frequency is determined by its corresponding control register settings. If you only want to transmit, receive data
can be kept dummy. Otherwise, if you only want to receive, you should transmit dummy '1' data.
There are 4 I/O pin signals associated with SPI transfers: SCK (SPICLK0,1), MISO (SPIMISO0,1) data line, MOSI
(SPIMOSI0,1) data line and active low /SS (nSS0,1) pin (input).
FEATURES
— Support 2-ch SPI
— SPI Protocol (ver. 2.11) compatible
— 8-bit Shift Register for transmit
— 8-bit Shift Register for receive
— 8-bit Prescaler logic
— Polling, Interrupt and DMA transfer mode
SPI OPERATION
Using the SPI interface, S3C2440A can send/receive 8-bit data simultaneously with an external device. A serial
clock line is synchronized with the two data lines for shifting and sampling of the information. When the SPI is the
master, transmission frequency can be controlled by setting the appropriate bit in SPPREn register. You can modify
its frequency to adjust the baud rate data register value. When the SPI is a slave, other master supplies the clock.
When the programmer writes byte data to SPTDATn register, SPI transmit/receive operation will start
simultaneously. In some cases, nSS should be activated before writing byte data to SPTDATn.
PROGRAMMING PROCEDURE
When a byte data is written into the SPTDATn register, SPI starts to transmit if ENSCK and MSTR of SPCONn
register are set. You can use a typical programming procedure to operate an SPI card.
To program the SPI modules, follow these basic steps:
1. Set Baud Rate Prescaler Register (SPPREn).
2. Set SPCONn to configure properly the SPI module.
3. Write data 0xFF to SPTDATn 10 times in order to initialize MMC or SD card.
4. Set a GPIO pin, which acts as nSS, low to activate the MMC or SD card.
5. Tx data ? Check the status of Transfer Ready flag (REDY=1), and then write data to SPTDATn.
6. Rx data(1): SPCONn's TAGD bit disable = normal mode
7. ? write 0xFF to SPTDATn, then confirm REDY to set, and then read data from Read Buffer.
8. Rx data(2): SPCONn's TAGD bit enable = Tx Auto Garbage Data mode
9. ? confirm REDY to set, and then read data from Read Buffer (then automatically start to transfer).
10. Set a GPIO pin, which acts as nSS, high to deactivate the MMC or SD card.
PROCEDURE FOR DMA
1. SPI is configured as DMA mode.
2. DMA is configured properly.
3. SPI requests DMA service.
4. DMA transmits 1byte data to the SPI.
5. SPI transmits the data to card.
6. Return to Step 3 until DMA count becomes 0.
6. SPI is configured as interrupt or polling mode with SMOD bits.
RECEIVING PROCEDURE FOR DMA
1. SPI is configured as DMA start with SMOD bits and TAGD bit set.
2. DMA is configured properly.
3. SPI receives 1byte data from card.
4. SPI requests DMA service.
5. DMA receives the data from the SPI.
6. Write data 0xFF automatically to SPTDATn.
7. Return to Step 4 until DMA count becomes 0.
8. SPI is configured as polling mode with SMOD bits and clear TAGD bit.
9. If SPSTAn’s READY flag is set, then read the last byte data.
关键是要会用它,还是说说你用过其中哪部分吧,遇到过什么问题,又是如何解决的
引用: 引用 23 楼 guetcw 的回复:
关键是要会用它,还是说说你用过其中哪部分吧,遇到过什么问题,又是如何解决的
刚刚开始正式学,还没有做试验...
前天觉得自己可以做了,拿来代码一看,茫然.....
自己觉得内存管理哪的问题,现在反过来正在自己探索SDRAM,FLASH,MMU.....
各位,我用的是轮回模式,请问这么初始化对了吗?
我用自发自收的方法做,结果,始终收不到数据?
各位帮忙看下是不是初始化错了。(s3c2440)
static int spi_open(struct inode *inode,struct file *filp)
{
unsigned int port_state;
int i=0;
/*=============== start init spi regiser ============*/
/*Control PCLK into SPI block,Reset value = 0xfffff0*/
/*Set the value Enable: CLKCON[18] = 1*/
if (!(CLKCON&(1<<18)))
CLKCON|=(1<<18);
/*Set the IO port as SPI. GPGCON reset value is 0x0*/
port_state = readl(GPGCON);
port_state &= ~SPI_USE;
port_state |= SPI_USE;
SPI_GPGCON = port_state;
port_state=0x0;
port_state = readl(GPGUP);
port_state &=~(1<<3 | 1<<5 | 1<<6 | 1<<7);//set GPG3 = 00 (INPUT)
writel(port_state,GPGUP);
port_state = readl(SPPRE1);
SPI_SPPRE1=0x18;
printk("The Baud Rate is: %x \n", readl(SPPRE1));
/* set Baud rate 1M .get it in net.note: PCLE=48MHz ,SPICLK=48/2/(0x18+1)=1M */
/* set spi module */
port_state = readl(SPCON1);
port_state &= ~0x03f;//clear
port_state |= (0<<0 | 0<<1 | 1<<2 | 1<<3 | 1<<4 | 0<<5 );
/* 0<<0 normal mode , 0<<1 format A,1<<2 active low ,1<<3 master
* 1<<4 SCK enable (master only), 0<<5 polling mode
*/
writel(port_stats, SPCON1);
/* SPI1 pin control */
port_state = readl(SPPIN1);
port_state &= ~(1<<0 | 1<<1 | 1<<2);
port_state |= (0<<2 | 1<<1 | 0<<0);
/* 0<<0:release 1<<1:SBO 0<<2:dis-ENMUL*/
writel(port_state,SPPIN1);
return 0;
}