Skip to content

Commit baddfd4

Browse files
committed
solve sd card don't reinitialize
ref: arduino/Arduino#3607
1 parent b1e5e93 commit baddfd4

File tree

100 files changed

+20911
-12
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+20911
-12
lines changed

lana/lana.ino

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

2+
// #define SD_CS_PIN SS
23
#include <SPI.h>
34
#include <SD.h>
5+
//#include <SdFat.h>
6+
//SdFat SD;
47

58
File myFile;
69
const int chipSelect = 4;
@@ -32,9 +35,9 @@
3235
Serial.begin(9600); // we agree to talk fast!
3336
pinMode(LED, OUTPUT);
3437
Serial.println(">> START<<");
35-
sdfilename = "eiei";
36-
sd(sdfilename);
37-
//interruptSetup(); // sets up to read Pulse Sensor signal every 2mS
38+
sdfilename = "test01";
39+
40+
interruptSetup(); // sets up to read Pulse Sensor signal every 2mS
3841
// IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE,
3942
// UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN
4043
// analogReference(EXTERNAL);
@@ -50,7 +53,7 @@
5053
delay(1000);//ms
5154
}
5255
*/
53-
// pul();
56+
pul();
5457
bt(BPM);
5558

5659
}
@@ -86,7 +89,9 @@
8689
input= Serial.read();
8790
if(input=='1')
8891
{
89-
Serial.println("ON");
92+
Serial.println("ON BLUETOOTH");
93+
Serial.println("=========================");
94+
sd(sdfilename,BPM);
9095
digitalWrite(LED, HIGH);
9196
delay(2000);
9297
Serial.println("BMP "+String(BPM));
@@ -107,8 +112,9 @@
107112
}
108113

109114
/* SD Card Function *****************/
110-
void sd(String sdfilename){
111-
Serial.print("Initializing SD card...");
115+
void sd(String sdfilename,int BPM){
116+
117+
Serial.print("Initializing SD card...\n");
112118
pinMode(SS, OUTPUT);
113119

114120
if (!SD.begin(chipSelect)) {
@@ -121,11 +127,10 @@ void sd(String sdfilename){
121127

122128
// if open file has success, write data
123129
if (myFile) {
124-
Serial.println("235235tion done.");
125-
Serial.print("Writing to test.txt...");
126-
myFile.println("data : "+String(sdfilename)); //write data
130+
Serial.print("Writing to "+String(sdfilename));
131+
myFile.println("data : "+String(BPM)); //write data
127132
myFile.close(); // close file
128-
Serial.println("done.");
133+
Serial.println(" done.");
129134
} else {
130135
Serial.println("error opening"+String(sdfilename));
131136
}
@@ -138,10 +143,11 @@ void sd(String sdfilename){
138143
while (myFile.available()) {
139144
Serial.write(myFile.read());
140145
}
141-
myFile.close();
146+
myFile.close();
142147
} else {
143148
Serial.println("error opening "+String(sdfilename));
144149
}
150+
Serial.println("=========================");
145151
}
146152

147153
/* Custom filename to sdcard ***************/

libraries/SdFat.zip

2.7 MB
Binary file not shown.

libraries/SdFat/MinimumSerial.cpp

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* Arduino SdFat Library
2+
* Copyright (C) 2012 by William Greiman
3+
*
4+
* This file is part of the Arduino SdFat Library
5+
*
6+
* This Library is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This Library is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with the Arduino SdFat Library. If not, see
18+
* <http://www.gnu.org/licenses/>.
19+
*/
20+
#include <Arduino.h>
21+
#if defined(UDR0) || defined(DOXYGEN)
22+
#include "MinimumSerial.h"
23+
const uint16_t MIN_2X_BAUD = F_CPU/(4*(2*0XFFF + 1)) + 1;
24+
//------------------------------------------------------------------------------
25+
void MinimumSerial::begin(uint32_t baud) {
26+
uint16_t baud_setting;
27+
// don't worry, the compiler will squeeze out F_CPU != 16000000UL
28+
if ((F_CPU != 16000000UL || baud != 57600) && baud > MIN_2X_BAUD) {
29+
// Double the USART Transmission Speed
30+
UCSR0A = 1 << U2X0;
31+
baud_setting = (F_CPU / 4 / baud - 1) / 2;
32+
} else {
33+
// hardcoded exception for compatibility with the bootloader shipped
34+
// with the Duemilanove and previous boards and the firmware on the 8U2
35+
// on the Uno and Mega 2560.
36+
UCSR0A = 0;
37+
baud_setting = (F_CPU / 8 / baud - 1) / 2;
38+
}
39+
// assign the baud_setting
40+
UBRR0H = baud_setting >> 8;
41+
UBRR0L = baud_setting;
42+
// enable transmit and receive
43+
UCSR0B |= (1 << TXEN0) | (1 << RXEN0);
44+
}
45+
//------------------------------------------------------------------------------
46+
int MinimumSerial::read() {
47+
if (UCSR0A & (1 << RXC0)) {
48+
return UDR0;
49+
}
50+
return -1;
51+
}
52+
//------------------------------------------------------------------------------
53+
size_t MinimumSerial::write(uint8_t b) {
54+
while (((1 << UDRIE0) & UCSR0B) || !(UCSR0A & (1 << UDRE0))) {}
55+
UDR0 = b;
56+
return 1;
57+
}
58+
#endif // defined(UDR0) || defined(DOXYGEN)

libraries/SdFat/MinimumSerial.h

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* Arduino SdFat Library
2+
* Copyright (C) 2012 by William Greiman
3+
*
4+
* This file is part of the Arduino SdFat Library
5+
*
6+
* This Library is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This Library is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with the Arduino SdFat Library. If not, see
18+
* <http://www.gnu.org/licenses/>.
19+
*/
20+
#ifndef MinimumSerial_h
21+
#define MinimumSerial_h
22+
#include <Arduino.h>
23+
//==============================================================================
24+
/**
25+
* \class MinimumSerial
26+
* \brief mini serial class for the %SdFat library.
27+
*/
28+
class MinimumSerial : public Print {
29+
public:
30+
/**
31+
* Set baud rate for serial port zero and enable in non interrupt mode.
32+
* Do not call this function if you use another serial library.
33+
* \param[in] baud rate
34+
*/
35+
void begin(uint32_t baud);
36+
/**
37+
* Unbuffered read
38+
* \return -1 if no character is available or an available character.
39+
*/
40+
int read();
41+
/**
42+
* Unbuffered write
43+
*
44+
* \param[in] b byte to write.
45+
* \return 1
46+
*/
47+
size_t write(uint8_t b);
48+
using Print::write;
49+
};
50+
#endif // MinimumSerial_h

0 commit comments

Comments
 (0)