代码执行到这俩个while()中就出不来了,俩个都出不来。我是做SD卡的spi方式,在第一个实验SD卡的读写都是没有问题的,能够正常的读写,后来把他移植到fatfs文件系统就出现这样的情况,实在是不解。第一个实验的成功说明硬件是好的呀。
u8 SPI_ReadWriteByte(u8 TxData)
{
while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);//µÈ´ý·¢ËÍÇø¿Õ
SPI_I2S_SendData(SPI2, TxData);//·¢ËÍÒ»¸öbyte
while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);//µÈ´ý½ÓÊÕÍêÒ»¸öbyte
return SPI_I2S_ReceiveData(SPI2); //·µ»ØÊÕµ½µÄÊý¾Ý
}
我把移植的diskio.c 的代码也贴出来,求大神指点。
#include "diskio.h"
#include "
STM32f10x.h"
#include "mmc_sd.h"
#include "usart1.h"
#define BLOCK_SIZE 512 /* Block Size in Bytes */
/*-----------------------------------------------------------------------*/
/* Inidialize a Drive */
DSTATUS disk_ini
tialize (
BYTE drv /* Physical drive nmuber (0..) */
)
{
BYTE re;
switch(drv)
{
case 0 :
return RES_OK;
case 1 :
return RES_OK;
case 2 :
return RES_OK;
case 3 :
return RES_OK;
default:
return STA_NOINIT;
}
re= SD_Init();
if(re==0)
USART1_printf(USART1, " SD Card Init Success!
");
}
/*-----------------------------------------------------------------------*/
/* Return Disk Status */
DSTATUS disk_status (
BYTE drv /* Physical drive nmuber (0..) */
)
{
return RES_OK;
}
/*-----------------------------------------------------------------------*/
/* Read Sector(s) */
DRESULT disk_read (
BYTE drv, /* Physical drive nmuber (0..) */
BYTE *buff, /* Data buffer to store read data */
DWORD sector, /* Sector address (LBA) */
BYTE count /* Number of sectors to read (1..255) */
)
{
if (count > 1)
{
SD_ReadMultiBlock(sector, buff, count);
}
else
{
// printf( "
ÕâÊÇÒ»¸ö²âÊÔ f_open:
" );
SD_ReadSingleBlock(sector, buff);
}
return RES_OK;
}
/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
#if _READONLY == 0
DRESULT disk_write (
BYTE drv, /* Physical drive nmuber (0..) */
const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector address (LBA) */
BYTE count /* Number of sectors to write (1..255) */
)
{
if (count > 1)
{
SD_WriteMultiBlock(sector, buff, count);
}
else
{
SD_WriteSingleBlock(sector, buff);
}
return RES_OK;
}
#endif /* _READONLY */
/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */
DRESULT disk_ioctl (
BYTE drv, /* Physical drive nmuber (0..) */
BYTE ctrl, /* Control code */
void *buff /* Buffer to send/receive control data */
)
{
return RES_OK;
}
/*-----------------------------------------------------------------------*/
/* Get current time */
/*-----------------------------------------------------------------------*/
DWORD get_fattime(void)
{
return 0;
}
我太穷了,就俩个积分了。见谅呀!
一周热门 更多>