微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > SPI 读写函数出不来SPI_ReadWriteByte(u8 TxData)

SPI 读写函数出不来SPI_ReadWriteByte(u8 TxData)

时间:10-02 整理:3721RD 点击:
代码执行到这俩个while()中就出不来了,俩个都出不来。我是做SD卡的spi方式,在第一个实验SD卡的读写都是没有问题的,能够正常的读写,后来把他移植到fatfs文件系统就出现这样的情况,实在是不解。第一个实验的成功说明硬件是好的呀。
u8 SPI_ReadWriteByte(u8 TxData)
{      
  while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);//μè′y·¢?í????       
  SPI_I2S_SendData(SPI2, TxData);//·¢?íò???byte
  while(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);//μè′y?óê?íêò???byte
  return SPI_I2S_ReceiveData(SPI2); //·μ??ê?μ?μ?êy?Y
}
我把移植的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_initialize (
        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!\n");
}

/*-----------------------------------------------------------------------*/
/* 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( "\r\n?aê?ò???2aê?   f_open:\n" );
        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;
}
我太穷了,就俩个积分了。见谅呀!


已退回2积分

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top