废话不多说,直接上移植好的代码
#include <SPI.h>
#include <SD.h>
#define SS 18
#define MOSI 15;
#define MISO 14;
#define SCK 7
File myFile;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
// wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("rowosr.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("rowosr.移植kjh ");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
// re-open the file for reading:
myFile = SD.open("rowosr.txt");
if (myFile) {
Serial.println("rowosr.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop() {
}
这里是库文件的链接
说一下我的血泪移植史,供大家参考
1.我首先把arduino的sd库,直接放到Energia,肯定不会来。
2.然后各种报错,懂得都懂,把arduino的库移植过去,有些函数肯定不能直接用
3.然后修改函数,函数名各种规范,然后修改管脚
4.最重要的是把beginTransaction()换成begin()
endtranaction()换成end()
5.注释掉所有带SPIsetting(******)的函数
演示效果
msp432驱动sd卡