在线时间776 小时
UID126526
注册时间2008-5-19
NXP金币0
TA的每日心情 | 奋斗 2023-9-17 19:57 |
---|
签到天数: 2310 天 连续签到: 1 天 [LV.Master]伴坛终老
金牌会员
 
- 积分
- 10481
- 最后登录
- 2023-9-17
|
本帖最后由 shaoziyang 于 2015-2-22 00:47 编辑
今天在YL-KL26Z开发板上测试SD卡,结果运行失败。运行到fp = fopen("/sd/hello.txt", "r");这一行后程序死循环了。同样的程序在FRDM-KL25Z上是可以正常运行的。
另外,下载光盘上的例程bin文件也提示出错,不知道官方的例程是不是有问题。
测试程序:
- #include "mbed.h"
- #include "SDFileSystem.h"
- SDFileSystem sd(PTC6, PTC7, PTC5, PTC4, "sd"); // MOSI, MISO, SCK, CS
- Serial pc(USBTX, USBRX);
- FILE *fp;
- char buffer[1024];
- int main() {
- pc.printf("Initializing \n");
- wait(2);
- fp = fopen("/sd/hello.txt", "r");
- if (fp != NULL) {
- fclose(fp);
- remove("/sd/hello.txt");
- pc.printf("Remove an existing file with the same name \n");
- }
- printf("\nWriting data to the sd card \n");
- fp = fopen("/sd/hello.txt", "w");
- if (fp == NULL) {
- pc.printf("Unable to write the file \n");
- } else {
- fprintf(fp, "mbed SDCard application!");
- fclose(fp);
- pc.printf("File successfully written! \n");
- }
- printf("\nReading data from the SD card. \n");
- fp = fopen("/sd/hello.txt", "r");
- if (fp != NULL) {
- int size = fread(buffer, sizeof(char), 1024, fp);
- printf("Number of data read: %d, text from hello.txt file: %s \n", size, buffer);
- fclose(fp);
- }
- printf("End of Lab 4. \n");
- }
复制代码
|
|