本文整理汇总了C++中SdFat::initErrorHalt方法的典型用法代码示例。如果您正苦于以下问题:C++ SdFat::initErrorHalt方法的具体用法?C++ SdFat::initErrorHalt怎么用?C++ SdFat::initErrorHalt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SdFat
的用法示例。
在下文中一共展示了SdFat::initErrorHalt方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: begin
bool Tune::begin()
{
// Pin configuration
pinMode(DREQ, INPUT_PULLUP);
pinMode(XDCS, OUTPUT);
pinMode(XCS, OUTPUT);
pinMode(SDCS, OUTPUT);
// Deselect control & data ctrl
digitalWrite(XCS, HIGH);
digitalWrite(XDCS, HIGH);
// Deselect SD's chip select
digitalWrite(SDCS, HIGH);
// SD card initialization
if (!sd.begin(SDCS, SPI_HALF_SPEED))
{
sd.initErrorHalt(); // describe problem if there's one
return 0;
}
// Tracklisting also return the number of playable files
Serial.print(listFiles());
Serial.print(" tracks found, ");
// SPI bus initialization
SPI.begin();
SPI.setDataMode(SPI_MODE0);
// Both SCI and SDI read data MSB first
SPI.setBitOrder(MSBFIRST);
// From the datasheet, max SPI reads are CLKI/6. Here CLKI = 26MHz -> SPI max speed is 4.33MHz.
// We'll take 16MHz/4 = 4MHz to be safe.
// Plus it's the max recommended speed when using a resistor-based lvl converter with an SD card.
SPI.setClockDivider(SPI_CLOCK_DIV4);
SPI.transfer(0xFF);
delay(10);
// Codec initialization
// Software reset
setBit(SCI_MODE, SM_RESET);
delay(5);
// VS1022 "New mode" activation
setBit(SCI_MODE, SM_SDINEW);
// Clock setting (default is 24.576MHz)
writeSCI(SCI_CLOCKF, 0x32, 0xC8);
delay(5);
// Wait until the chip is ready
while (!digitalRead(DREQ));
delay(100);
// Set playState flag
playState = idle;
// Set volume to avoid hurt ears ;)
setVolume(150);
Serial.println("Tune ready !");
return 1;
}
示例2: main
int main()
{
// initialize the SD card at SPI_FULL_SPEED for best performance.
// try SPI_HALF_SPEED if bus errors occur.
if (!sd.begin(SD_ENABLE_PIN, SPI_FULL_SPEED)) sd.initErrorHalt();
if (!myFile.open("test.txt", O_RDWR | O_CREAT | O_AT_END)) {
sd.errorHalt("opening test.txt for write failed");
}
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
while (1);
return 0;
}
示例3: ScriviSd
void ScriviSd(void)
{
int n;
n = 0;
if (!sd.init(SPI_HALF_SPEED, 10))
{
sd.initErrorHalt();
return;
}
if (!myFile.open("test-1.txt", O_WRITE | O_CREAT | O_APPEND))
{
delay(800);
digitalWrite(7, LOW);
delay(200);
digitalWrite(7, HIGH);
delay(800);
sd.errorHalt("opening test.txt for write failed");
return;
}
// Serial.println(nMin);
// for(n = 0; n < nCount; n++)
// {
// myFile.print("TIME: ");
// myFile.print(nMin);
// myFile.print(" min. - VALUE : ");
// myFile.print(nValue[n]);
myFile.println(" mTesla");
// }
// Serial.println("ScriviSd5");
// nCount = 0;
// nMin++;
myFile.close();
}
示例4: startBinLogger
void startBinLogger(void (*dateTime)(uint16_t *date, uint16_t *time)){
#ifdef LOGGER_DEBUG
Serial.print("Size of Struct: ");
Serial.println(sizeof(salus_data_t));
Serial.print("Data_DIM: ");
Serial.println(DATA_DIM);
Serial.print("FILL_DIM: ");
Serial.println(FILL_DIM);
Serial.print("Sizeof Block: ");
Serial.println(sizeof(block_t));
Serial.println();
#endif
if (!sd.begin(SD_CHIPSELECT, SD_SPI_SPEED)) {
sd.initErrorHalt();
}
int number = 0;
char sName[80];
// Find a filename that hasn't been used already
do
{
sprintf(sName, "Salus_Results_%d.bin", number++);
} while (sd.exists(sName));
binFile.close();
binFile.dateTimeCallback(dateTime);
if (!binFile.createContiguous(sd.vwd(), sName, 512 * FILE_BLOCK_COUNT)){
error("createContiguous failed");
}
if (!binFile.contiguousRange(&bgnBlock, &endBlock)){
error("contiguousRange failed");
}
// Use SdFat's internal buffer ( ???? )
uint8_t* cache = (uint8_t*)sd.vol()->cacheClear();
if (cache == 0) {
error("cacheClear failed");
}
binFile.dateTimeCallbackCancel();
uint32_t bgnErase = bgnBlock;
uint32_t endErase;
while (bgnErase < endBlock) {
endErase = bgnErase + ERASE_SIZE;
if (endErase > endBlock) {
endErase = endBlock;
}
if (!sd.card()->erase(bgnErase, endErase)) {
error("erase failed");
}
bgnErase = endErase + 1;
}
// Start a multiple block write.
if (!sd.card()->writeStart(bgnBlock, FILE_BLOCK_COUNT)) {
error("writeBegin failed");
}
}
示例5:
boolean MP3Player::Init(byte CS_uSD,byte ASD)
{
PLAY = false;
isPlayAll = false;
name.reserve(80);
name = "";
vol = 0;
counter=0;
currentDir.reserve(20);
currentDir = "";
_isPause = false;
_isMute = false;
ls_flag = false;
CS_SD=CS_uSD;
AMP=ASD;
pinMode(CS,OUTPUT); //STA013CS
digitalWrite(CS,LOW); //deactivate sta013 spi input
pinMode(DATREQ,INPUT); //DATREQ
pinMode(RESET,OUTPUT); //reset
digitalWrite(RESET,HIGH);
pinMode(AMP,INPUT); //shutdown the amp
pinMode(CS_SD, OUTPUT); //SPI uSD CS
InitI2C();
Reset_STA013();
#if DEBUG
Serial.begin(9600);
while (!Serial) ; // wait for serial port to connect. Needed for Leonardo only
#endif
if (!sd.begin(CS_SD, SPI_FULL_SPEED))
{
#if DEBUG
sd.initErrorHalt();
#endif
return false;
}
SPI.begin();
boolean stat=Verify_STA013();
if (stat==false)
{
#if DEBUG
Serial.println("STA013 not exist!");
#endif
return false;
}
else
{
#if DEBUG
Serial.println("STA013 verified..");
#endif
if(!Setup_STA013())
{
return false;
}
else
{
delayMicroseconds(100000);
setVolume(220); // set volume by default in case user forgets to set it.
AMPON();
return true;
}
}
}
示例6: setup
//------------------------------------------------------------------------------
void setup() {
Serial.begin(9600);
// Wait for USB Serial
while (!Serial) {
SysCall::yield();
}
delay(1000);
cout << F("Type any character to start\n");
// Wait for input line and discard.
cin.readline();
cout << endl;
// Initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
// breadboards. use SPI_FULL_SPEED for better performance.
if (!sd.begin(SD_CHIP_SELECT, SPI_HALF_SPEED)) {
sd.initErrorHalt();
}
if (sd.exists("Folder1")
|| sd.exists("Folder1/file1.txt")
|| sd.exists("Folder1/File2.txt")) {
error("Please remove existing Folder1, file1.txt, and File2.txt");
}
int rootFileCount = 0;
sd.vwd()->rewind();
while (file.openNext(sd.vwd(), O_READ)) {
if (!file.isHidden()) {
rootFileCount++;
}
file.close();
if (rootFileCount > 10) {
error("Too many files in root. Please use an empty SD.");
}
}
if (rootFileCount) {
cout << F("\nPlease use an empty SD for best results.\n\n");
delay(1000);
}
// Create a new folder.
if (!sd.mkdir("Folder1")) {
error("Create Folder1 failed");
}
cout << F("Created Folder1\n");
// Create a file in Folder1 using a path.
if (!file.open("Folder1/file1.txt", O_CREAT | O_WRITE)) {
error("create Folder1/file1.txt failed");
}
file.close();
cout << F("Created Folder1/file1.txt\n");
// Change volume working directory to Folder1.
if (!sd.chdir("Folder1")) {
error("chdir failed for Folder1.\n");
}
cout << F("chdir to Folder1\n");
// Create File2.txt in current directory.
if (!file.open("File2.txt", O_CREAT | O_WRITE)) {
error("create File2.txt failed");
}
file.close();
cout << F("Created File2.txt in current directory\n");
cout << F("\nList of files on the SD.\n");
sd.ls("/", LS_R);
// Remove files from current directory.
if (!sd.remove("file1.txt") || !sd.remove("File2.txt")) {
error("remove failed");
}
cout << F("\nfile1.txt and File2.txt removed.\n");
// Change current directory to root.
if (!sd.chdir()) {
error("chdir to root failed.\n");
}
cout << F("\nList of files on the SD.\n");
sd.ls(LS_R);
// Remove Folder1.
if (!sd.rmdir("Folder1")) {
error("rmdir for Folder1 failed\n");
}
cout << F("\nFolder1 removed.\n");
cout << F("\nList of files on the SD.\n");
sd.ls(LS_R);
cout << F("Done!\n");
}