我一直在尝试使用 SD 卡将数据记录到我的 NUCLEO F746ZG。这是我的代码:
#include "mbed.h"
#include "SDFileSystem.h"
//#include "Hx711.h"
#include <string>
//#include "ep29.h"
//#include "wsdef.h"
//#include "image.h"
//#include <vector>
PinName mosi = PE_6;
PinName miso = PE_5;
PinName sclk = PE_2;
PinName cs = PE_4;
PinName cd = PE_3;
SDFileSystem sd(mosi, miso, sclk, cs, "sd"); // the pinout on the mbed Cool Components workshop board
Serial pc(SERIAL_TX, SERIAL_RX);
int main(void) {
pc.baud(9600);
pc.printf("starting\r\n");
FILE *fp = fopen("/sd/sdtest.txt", "w");
if(fp == NULL) {
pc.printf("Could not open file for write\n");
}
fprintf(fp,"starting to read from strain gauge:128G, 32G \r\n");
fprintf(fp,"\r\n");
pc.printf("worked!\r\n");
}
它以前工作过一次或两次,但只有在我上传代码之前有SD卡时才能工作,并且当我按下重置按钮时不会重写到SD卡。但是,它似乎不再起作用了。
有可能是我刚刚损坏了 sd 卡,还是我的代码有问题?
干杯,
阿里