全部博文(185)
分类:
2009-04-12 10:33:48
很早就想把这些东西写写,总结总结了。最近下班回来就看陀枪师姐IV,一直拖着,今天白天睡了个大觉,晚上挺精神,就赶快补起咯
在此感谢 RockCarry的帮助 谢谢
先了解一下SD卡工作的总体流程
1: SD Memory Card state diagram (card identification mode)
2: SD Memory Card state diagram (data transfer mode)
按照S3C2410 datasheet上介绍:
先配置几个SD卡使用的I/O口,看I/O口介绍那章就知道,都要配置成10咯
GPE10 [21:20] 00 = Input 01 = Output 10 = SDDAT3 11 = Reserved
GPE9 [19:18] 00 = Input 01 = Output 10 = SDDAT2 11 = Reserved
GPE8 [17:16] 00 = Input 01 = Output 10 = SDDAT1 11 = Reserved
GPE7 [15:14] 00 = Input 01 = Output 10 = SDDAT0 11 = Reserved
GPE6 [13:12] 00 = Input 01 = Output 10 = SDCMD 11 = Reserved
GPE5 [11:10] 00 = Input 01 = Output 10 = SDCLK 11 = Reserved
然后初始化SD卡控制寄存器
1. Set SDICON to configure properly with clock and interrupt.
2. Set SDIPRE to configure with a proper value.
3. Wait 74 SDCLK clock cycle in order to initialize the card.
要是要给SD卡发命令,就按以下几个步骤来办
1. Write command argument (32-bit) to SDICARG register.
2. Determine command types and start command by setting SDICCON[8].
3. Confirm the end of SDI command operation when the specific flag of SDICSTA is set. — If the type of command is no-response, the flag is SDICSTA[11]. — If the type of command is with-response, the flag is SDICSTA[9].
4. Clear the corresponding flag of the SDICSTA register by writing one to the flag bit.
跟SD读取和写入数据时,就按照以下几步来
1. Write timeout period to SDIDTIMER register.
2. Write block size (block length) to SDIBSIZE register (normally 0x200 byte).
3. Determine the mode of block, wide bus, DMA, etc. and start data transfer with setting SDIDCON register.
4. Write Tx-data to SDIDAT register while Tx FIFO is available by checking SDIFSTA (available, half or empty) register.
5. Read Rx-data from SDIDAT register while Rx FIFO is available by checking SDIFSTA (available, half or be last data) register.
6. Confirm the end of SDI data operation when the flag of data transfer finish (SDIDSTA[4]) is set.
7. Clear the corresponding flag of SDIDSTA register by writing one to the flag bit.