Skip to content

Commit 2846e32

Browse files
committed
Driving SPI pins low to avoid power consumption on some SD cards. See issue 215.
1 parent d1aefc7 commit 2846e32

File tree

1 file changed

+119
-101
lines changed

1 file changed

+119
-101
lines changed

firmware/OpenLog_Firmware/OpenLog/OpenLog.ino

Lines changed: 119 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
11
/*
2-
12-3-09
3-
Nathan Seidle
4-
SparkFun Electronics
2+
12-3-09
3+
Nathan Seidle
4+
SparkFun Electronics
55
6-
OpenLog hardware and firmware are released under the Creative Commons Share Alike v3.0 license.
7-
http://creativecommons.org/licenses/by-sa/3.0/
8-
Feel free to use, distribute, and sell varients of OpenLog. All we ask is that you include attribution of 'Based on OpenLog by SparkFun'.
6+
OpenLog hardware and firmware are released under the Creative Commons Share Alike v3.0 license.
7+
http://creativecommons.org/licenses/by-sa/3.0/
8+
Feel free to use, distribute, and sell varients of OpenLog. All we ask is that you include attribution of 'Based on OpenLog by SparkFun'.
99
10-
OpenLog is based on the work of Bill Greiman and sdfatlib: https://github.com/greiman/SdFat-beta
10+
OpenLog is based on the work of Bill Greiman and sdfatlib: https://github.com/greiman/SdFat-beta
1111
12-
OpenLog is a simple serial logger based on the ATmega328 running at 16MHz. The whole purpose of this
13-
logger was to create a logger that just powered up and worked. OpenLog ships with an Arduino/Optiboot
14-
115200bps serial bootloader running at 16MHz so you can load new firmware with a simple serial
15-
connection.
12+
OpenLog is a simple serial logger based on the ATmega328 running at 16MHz. The whole purpose of this
13+
logger was to create a logger that just powered up and worked. OpenLog ships with an Arduino/Optiboot
14+
115200bps serial bootloader running at 16MHz so you can load new firmware with a simple serial
15+
connection.
1616
17-
OpenLog has progressed significantly over the past three years. Please see CHANGELOG.md or GitHub commits
18-
for a full trip down memory lane.
17+
OpenLog has progressed significantly over the past three years. Please see CHANGELOG.md or GitHub commits
18+
for a full trip down memory lane.
1919
20-
OpenLog automatically works with 512MB to 64GB micro/SD cards.
20+
OpenLog automatically works with 512MB to 64GB micro/SD cards.
2121
22-
OpenLog runs at 9600bps by default. This is configurable to 1200, 2400, 4800, 9600, 19200, 38400, 57600, and 115200bps. You can alter
23-
all settings including baud rate and escape characters by editing config.txt found on OpenLog.
22+
OpenLog runs at 9600bps by default. This is configurable to 1200, 2400, 4800, 9600, 19200, 38400, 57600, and 115200bps. You can alter
23+
all settings including baud rate and escape characters by editing config.txt found on OpenLog.
2424
25-
Type '?' to get a list of supported commands.
25+
Type '?' to get a list of supported commands.
2626
27-
During power up, you will see '12<'. '1' indicates the serial connection is established. '2' indicates
28-
the SD card has been successfully initialized. '<' indicates OpenLog is ready to receive serial characters.
27+
During power up, you will see '12<'. '1' indicates the serial connection is established. '2' indicates
28+
the SD card has been successfully initialized. '<' indicates OpenLog is ready to receive serial characters.
2929
30-
Recording constant 115200bps datastreams are supported. Throw it everything you've got! To acheive this maximum record rate, please use the
31-
SD card formatter from : http://www.sdcard.org/consumers/formatter/. The fewer files on the card, the faster OpenLog is able to begin logging.
32-
200 files is ok. 2GB worth of music and pictures is not.
30+
Recording constant 115200bps datastreams are supported. Throw it everything you've got! To acheive this maximum record rate, please use the
31+
SD card formatter from : http://www.sdcard.org/consumers/formatter/. The fewer files on the card, the faster OpenLog is able to begin logging.
32+
200 files is ok. 2GB worth of music and pictures is not.
3333
34-
To a lower dir, use 'cd ..' instead of 'cd..'.
34+
To a lower dir, use 'cd ..' instead of 'cd..'.
3535
36-
Only standard 8.3 file names are supported. "12345678.123" is acceptable. "123456789.123" is not.
36+
Only standard 8.3 file names are supported. "12345678.123" is acceptable. "123456789.123" is not.
3737
38-
All file names are pushed to upper case. "NewLog.txt" will become "NEWLOG.TXT".
38+
All file names are pushed to upper case. "NewLog.txt" will become "NEWLOG.TXT".
3939
40-
Type 'set' to enter baud rate configuration menu. Select the baud rate and press enter. You will then
41-
see a message 'Going to 9600bps...' or some such message. You will need to power down OpenLog, change
42-
your system UART settings to match the new OpenLog baud rate and then power OpenLog back up.
40+
Type 'set' to enter baud rate configuration menu. Select the baud rate and press enter. You will then
41+
see a message 'Going to 9600bps...' or some such message. You will need to power down OpenLog, change
42+
your system UART settings to match the new OpenLog baud rate and then power OpenLog back up.
4343
44-
If you get OpenLog stuck into an unknown baudrate, there is a safety mechanism built-in. Tie the RX pin
45-
to ground and power up OpenLog. You should see the LEDs blink back and forth for 2 seconds, then blink
46-
in unison. Now power down OpenLog and remove the RX/GND jumper. OpenLog is now reset to 9600bps.
44+
If you get OpenLog stuck into an unknown baudrate, there is a safety mechanism built-in. Tie the RX pin
45+
to ground and power up OpenLog. You should see the LEDs blink back and forth for 2 seconds, then blink
46+
in unison. Now power down OpenLog and remove the RX/GND jumper. OpenLog is now reset to 9600bps.
4747
48-
Please note: The preloaded Optiboot serial bootloader is 0.5k, and begins at 0x7E00 (32,256). If the code is
49-
larger than 32,256 bytes, you will get verification errors during serial bootloading.
48+
Please note: The preloaded Optiboot serial bootloader is 0.5k, and begins at 0x7E00 (32,256). If the code is
49+
larger than 32,256 bytes, you will get verification errors during serial bootloading.
5050
51-
OpenLog regularly shuts down to conserve power. If after 0.5 seconds no characters are received, OpenLog will record
52-
any unsaved characters and go to sleep. OpenLog will automatically wake up and continue logging the instant a
53-
new character is received.
51+
OpenLog regularly shuts down to conserve power. If after 0.5 seconds no characters are received, OpenLog will record
52+
any unsaved characters and go to sleep. OpenLog will automatically wake up and continue logging the instant a
53+
new character is received.
5454
55-
1.55mA idle
56-
15mA actively writing
55+
1.55mA idle
56+
15mA actively writing
5757
58-
Input voltage on VCC can be 3.3 to 12V. Input voltage on RX-I pin must not exceed 6V. Output voltage on
59-
TX-O pin will not be greater than 3.3V. This may cause problems with some systems - for example if your
60-
attached microcontroller requires 4V minimum for serial communication (this is rare).
58+
Input voltage on VCC can be 3.3 to 12V. Input voltage on RX-I pin must not exceed 6V. Output voltage on
59+
TX-O pin will not be greater than 3.3V. This may cause problems with some systems - for example if your
60+
attached microcontroller requires 4V minimum for serial communication (this is rare).
6161
62-
*/
62+
*/
6363

6464
#define __PROG_TYPES_COMPAT__ //Needed to get SerialPort.h to work in Arduino 1.6.x
6565

@@ -71,7 +71,7 @@
7171

7272
SerialPort<0, 512, 0> NewSerial;
7373
//<port #, RX buffer size, TX buffer size>
74-
//We set the TX buffer to zero because we will be spending most of our
74+
//We set the TX buffer to zero because we will be spending most of our
7575
//time needing to buffer the incoming (RX) characters.
7676

7777
//This is the array within the append file routine
@@ -311,7 +311,7 @@ char* newLog(void)
311311

312312
//There is a weird EEPROM power-up glitch that causes the newFileNumber to advance
313313
//arbitrarily. This fixes that problem.
314-
if(newFileNumber > 0) newFileNumber--;
314+
if (newFileNumber > 0) newFileNumber--;
315315

316316
//Search for next available log spot
317317
static char newFileName[13]; //Bug fix from ystark's pull request: https://github.com/sparkfun/OpenLog/pull/189
@@ -322,7 +322,7 @@ char* newLog(void)
322322
// O_CREAT - create the file if it does not exist
323323
// O_APPEND - seek to the end of the file prior to each write
324324
// O_WRITE - open for write
325-
// O_EXCL - if O_CREAT and O_EXCEL are set, open() shall fail if file exists
325+
// O_EXCL - if O_CREAT and O_EXCEL are set, open() shall fail if file exists
326326

327327
//Try to open file, if it opens (file doesn't exist), then break
328328
if (newFile.open(newFileName, O_CREAT | O_EXCL | O_WRITE)) break;
@@ -459,6 +459,15 @@ byte appendFile(char* fileName)
459459

460460
power_timer0_disable(); //Shut down peripherals we don't need
461461
power_spi_disable();
462+
463+
//Driving SPI pins low before sleep to attempt to lower microSD card stand-by current
464+
//Pins: 10, 11, 12, 13
465+
for (byte x = 10 ; x < 14 ; x++)
466+
{
467+
pinMode(x, OUTPUT);
468+
digitalWrite(x, LOW);
469+
}
470+
462471
sleep_mode(); //Stop everything and go to sleep. Wake up if serial character received
463472

464473
power_spi_enable(); //After wake up, power up peripherals
@@ -511,6 +520,15 @@ byte appendFile(char* fileName)
511520

512521
power_timer0_disable(); //Shut down peripherals we don't need
513522
power_spi_disable();
523+
524+
//Driving SPI pins low before sleep to attempt to lower microSD card stand-by current
525+
//Pins: 10, 11, 12, 13
526+
for (byte x = 10 ; x < 14 ; x++)
527+
{
528+
pinMode(x, OUTPUT);
529+
digitalWrite(x, LOW);
530+
}
531+
514532
sleep_mode(); //Stop everything and go to sleep. Wake up if serial character received
515533

516534
power_spi_enable(); //After wake up, power up peripherals
@@ -525,9 +543,9 @@ byte appendFile(char* fileName)
525543
workingFile.sync();
526544

527545
//Remove the escape characters from the end of the file
528-
if(setting_max_escape_character > 0)
546+
if (setting_max_escape_character > 0)
529547
workingFile.truncate(workingFile.fileSize() - setting_max_escape_character);
530-
548+
531549
workingFile.close(); // Done recording, close out the file
532550

533551
digitalWrite(stat1, LOW); // Turn off indicator LED
@@ -1708,7 +1726,7 @@ byte readLine(char* buffer, byte bufferLength)
17081726
//To capture the escape command and immediately record
17091727
//the buffer then stop asking for input from user
17101728
//See issue 168: https://github.com/sparkfun/OpenLog/issues/168
1711-
}*/
1729+
}*/
17121730
else {
17131731
buffer[readLength] = c;
17141732
++readLength;
@@ -2110,33 +2128,33 @@ byte wildcmp(const char* wild, const char* string)
21102128
#define DIR_SIZE (sizeof(dir_t))
21112129

21122130
/*
2113-
* NAME:
2114-
* void lsPrint(SdFile * theDir, char * cmdStr, byte flags, byte indent)
2115-
*
2116-
* PARAMETERS:
2117-
* SdFile * theDir = the directory to list (assumed opened)
2118-
* char * cmdStr = the command line file/directory string (with possible wildcards)
2119-
* byte flags = the inclusive OR of
2120-
* LS_SIZE - print the file size
2121-
* LS_R - recursively list subdirectories
2122-
* byte indent = amount of space before file name
2123-
* (used for recursive list to indicate subdirectory level)
2124-
*
2125-
* WHAT:
2126-
* List directory contents to serial port.
2127-
*
2128-
* Wildcard support rules:
2129-
* Wildcard characters ('*', '?') only apply to the selection of filenames to
2130-
* list, not to the listing of directory or subdirectory names. All directory
2131-
* and subdirectory names are always listed.
2132-
*
2133-
* RETURN VALUES:
2134-
* None.
2135-
*
2136-
* SPECIAL CONSIDERATIONS:
2137-
* May be called recursively with limited recursion depth (see FOLDER_TRACK_DEPTH).
2138-
* Each recursion uses ~50 bytes of RAM.
2139-
*/
2131+
NAME:
2132+
void lsPrint(SdFile * theDir, char * cmdStr, byte flags, byte indent)
2133+
2134+
PARAMETERS:
2135+
SdFile * theDir = the directory to list (assumed opened)
2136+
char * cmdStr = the command line file/directory string (with possible wildcards)
2137+
byte flags = the inclusive OR of
2138+
LS_SIZE - print the file size
2139+
LS_R - recursively list subdirectories
2140+
byte indent = amount of space before file name
2141+
(used for recursive list to indicate subdirectory level)
2142+
2143+
WHAT:
2144+
List directory contents to serial port.
2145+
2146+
Wildcard support rules:
2147+
Wildcard characters ('*', '?') only apply to the selection of filenames to
2148+
list, not to the listing of directory or subdirectory names. All directory
2149+
and subdirectory names are always listed.
2150+
2151+
RETURN VALUES:
2152+
None.
2153+
2154+
SPECIAL CONSIDERATIONS:
2155+
May be called recursively with limited recursion depth (see FOLDER_TRACK_DEPTH).
2156+
Each recursion uses ~50 bytes of RAM.
2157+
*/
21402158
//void lsPrint(SdFile * theDir, char * cmdStr, byte flags, byte indent)
21412159
void lsPrint(FatFile * theDir, char * cmdStr, byte flags, byte indent)
21422160
{
@@ -2168,32 +2186,32 @@ void lsPrint(FatFile * theDir, char * cmdStr, byte flags, byte indent)
21682186
}
21692187

21702188
/*
2171-
* NAME:
2172-
* void lsPrintNext(SdFile * theDir, char * cmdStr, byte flags, byte indent)
2173-
*
2174-
* PARAMETERS:
2175-
* SdFile * theDir = the directory to list (assumed opened)
2176-
* char * cmdStr = the command line file/directory string (with possible wildcards)
2177-
* byte flags = the inclusive OR of
2178-
* LS_SIZE - print the file size
2179-
* LS_R - recursively list subdirectories
2180-
* byte indent = amount of space before file name
2181-
* (used for recursive list to indicate subdirectory level)
2182-
*
2183-
* WHAT:
2184-
* List directory's next contents to serial port.
2185-
*
2186-
* Wildcard support rules:
2187-
* Wildcard characters ('*', '?') only apply to the selection of filenames to
2188-
* list, not to the listing of directory or subdirectory names. All directory
2189-
* and subdirectory names are always listed.
2190-
*
2191-
* RETURN VALUES:
2192-
* byte = WAS_EOF - EOF, WAS_FILE - normal file, or WAS_SUBDIR - subdirectory
2193-
*
2194-
* SPECIAL CONSIDERATIONS:
2195-
* None.
2196-
*/
2189+
NAME:
2190+
void lsPrintNext(SdFile * theDir, char * cmdStr, byte flags, byte indent)
2191+
2192+
PARAMETERS:
2193+
SdFile * theDir = the directory to list (assumed opened)
2194+
char * cmdStr = the command line file/directory string (with possible wildcards)
2195+
byte flags = the inclusive OR of
2196+
LS_SIZE - print the file size
2197+
LS_R - recursively list subdirectories
2198+
byte indent = amount of space before file name
2199+
(used for recursive list to indicate subdirectory level)
2200+
2201+
WHAT:
2202+
List directory's next contents to serial port.
2203+
2204+
Wildcard support rules:
2205+
Wildcard characters ('*', '?') only apply to the selection of filenames to
2206+
list, not to the listing of directory or subdirectory names. All directory
2207+
and subdirectory names are always listed.
2208+
2209+
RETURN VALUES:
2210+
byte = WAS_EOF - EOF, WAS_FILE - normal file, or WAS_SUBDIR - subdirectory
2211+
2212+
SPECIAL CONSIDERATIONS:
2213+
None.
2214+
*/
21972215
//byte lsPrintNext(SdFile * theDir, char * cmdStr, byte flags, byte indent)
21982216
byte lsPrintNext(FatFile * theDir, char * cmdStr, byte flags, byte indent)
21992217
{

0 commit comments

Comments
 (0)