![](/img/trans.png)
[英]Can't write to SD card file with SPI using Chan FatFs library on a STM32F407
[英]SD card can't read write STM32f4
我正在尝试将SD卡与STM32F4接口,但是事情不起作用,代码是使用cubemx开发的
调试步骤:
我单步执行代码fmount是成功的,但是当我单步执行fopen
,在find_volume()
返回了FR_NOT_READY
的错误代码。
硬件连接:
我有带有SPI引脚的arduino micro SD分支板,因此连接是
int main(void)
{
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_SDIO_SD_Init();
MX_FATFS_Init();
HAL_Delay(1000);
/* USER CODE BEGIN 2 */
if(f_mount(&mynewdiskFatFs,(const TCHAR*)SD_Path, 0) == FR_OK)
{
if(f_open(&MyFile, "abc.txt", FA_READ ) == FR_OK)
{
// GPIO_SetBits(GPIOD, GPIO_Pin_15);
if(f_read(&MyFile, wtext, sizeof(wtext), (void *)&wbytes) ==FR_OK);
{
f_close(&MyFile);
}
}
}
while (1)
{
}
}
f_open(&MyFile, "abc.txt", FA_READ )
在ffconf.h中查看有关文件名的配置选项。
尝试使用(FA_OPEN_EXISTING | FA_READ)标志。
以100ms的间隔重复使用f_open(),例如5次,直到返回FR_OK。
嗨turboJ,我正在使用1位宽的SDIO模式连接SD卡,所以我猜没有用CS
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.