Difference between revisions of "SD CARD"

From Ethersex_Wiki
Jump to: navigation, search
(Configuration)
Line 12: Line 12:
 
|CODE=[https://github.com/ethersex/ethersex/tree/master/hardware/storage/sd_reader https://github.com/ethersex/ethersex/tree/master/hardware/storage/sd_reader]
 
|CODE=[https://github.com/ethersex/ethersex/tree/master/hardware/storage/sd_reader https://github.com/ethersex/ethersex/tree/master/hardware/storage/sd_reader]
 
}}
 
}}
 +
 +
The module is based on Roland Riegel's [http://www.roland-riegel.de/sd-reader/ MMC/SD/SDHC card library] complemented by the connection to the Ethersex [[VFS|Virtual File System]].
  
 
== Connection ==
 
== Connection ==
 +
 +
[[File:Sdcard adapter schaltung.png|200px|thumb|right|SD-Card Adapter Schaltung]]
 +
[[File:Sdcard adapter.jpg|200px|thumb|right|SD-Card Adapter Aufbau]]
 +
[[File:Microsd_adapter.jpg|200px|thumb|right|MicroSD-Card Adapter mit Level-Shifter aus China]]
  
 
== Configuration ==
 
== Configuration ==
Line 45: Line 51:
  
 
== [[ECMD|ECMD]] ==
 
== [[ECMD|ECMD]] ==
 +
 +
IRMP implements an [[ECMD]] interface. See [[ECMD_Reference|ECMD reference]].
  
 
== [[Control6|Control6]] ==
 
== [[Control6|Control6]] ==
 +
 +
The following example writes the date, time and temperature by VFS_LOG_ALLOCA (VFS_LOG requires UIP) in the file "temp.log" as soon as the temperature has changed by more than a degree to the last measurement. For date and time CLOCK_SUPPORT must be enabled.
 +
 +
<pre>
 +
#include <stdlib.h>
 +
 +
int16_t Temperatur;
 +
int16_t Temperatur_alt;
 +
 +
CONTROL_START
 +
 +
THREAD(read_temp)
 +
  Temperatur = ONEWIRE_GET(10d85594010800eb);
 +
  ON abs(Temperatur-Temperatur_alt)>10 DO
 +
    uint8_t sign = Temperatur<0;
 +
    div_t res = div(abs(Temperatur),10);
 +
    VFS_LOG_ALLOCA("temp.log", 50, "%2d.%2d.%4d %2d:%02d %S%d.%d", CLOCK_DAY, CLOCK_MONTH, CLOCK_YEAR, CLOCK_HOUR, CLOCK_MIN, sign?PSTR("-"):PSTR(""),res.quot,res.rem)
 +
    Temperatur_alt = Temperatur;
 +
  END
 +
  WAIT(15);
 +
THREAD_END(read_temp)
 +
 +
ON STARTUP DO
 +
  Temperatur = Temperatur_alt = 0;
 +
  THREAD_START(read_temp);
 +
END
 +
 +
CONTROL_END
 +
</pre>

Revision as of 10:39, 19 December 2013

SD/MMC-Card Reader
Status
Stable
menuconfig I/O->SD/MMC-Card Reader
Pinning yes
Ecmd yes
Control6 yes
Depends on ECMD
Code https://github.com/ethersex/ethersex/tree/master/hardware/storage/sd_reader

The module is based on Roland Riegel's MMC/SD/SDHC card library complemented by the connection to the Ethersex Virtual File System.

Connection

SD-Card Adapter Schaltung
SD-Card Adapter Aufbau
MicroSD-Card Adapter mit Level-Shifter aus China

Configuration

 | |        I/O  --->                                                    | |
 ...
 │ │        Storage  --->                                                │ │ 
 ...
 | |        [*] SD/MMC-Card Reader  --->                                 | |
 ...
 | |        [ ] SDHC support                                             | |
 | |        [*] VFAT LFN support                                         | |
 | |        [ ] Read-only mode                                           | |
 | |        [*] Use read-timeout                                         | |
 | |        [*] Ping-read SD card every 10s                              | |
 | |        --- ECMD Support                                             | |
 | |        [*] info                                                     | |
 | |        [*] dir                                                      | |
 | |        [*] mkdir                                                    | |
 | |        [*] rm                                                       | |
 | |        --- Debugging Flags                                          | |
 | |        [*] FAT                                                      | |
 | |        [*] RAW                                                      | |
 | |        [*] VFS                                                      | |
   
 | |        General Setup  --->                                          | |
 ...
 | |        [*] VFS (Virtual File System) support  --->                  | |
 ...
 | |             [*] SD/MMC-Card Filesystem                              | |

ECMD

IRMP implements an ECMD interface. See ECMD reference.

Control6

The following example writes the date, time and temperature by VFS_LOG_ALLOCA (VFS_LOG requires UIP) in the file "temp.log" as soon as the temperature has changed by more than a degree to the last measurement. For date and time CLOCK_SUPPORT must be enabled.

#include <stdlib.h>

int16_t Temperatur;
int16_t Temperatur_alt;

CONTROL_START

THREAD(read_temp)
  Temperatur = ONEWIRE_GET(10d85594010800eb);
  ON abs(Temperatur-Temperatur_alt)>10 DO
    uint8_t sign = Temperatur<0;
    div_t res = div(abs(Temperatur),10);
    VFS_LOG_ALLOCA("temp.log", 50, "%2d.%2d.%4d %2d:%02d %S%d.%d", CLOCK_DAY, CLOCK_MONTH, CLOCK_YEAR, CLOCK_HOUR, CLOCK_MIN, sign?PSTR("-"):PSTR(""),res.quot,res.rem)
    Temperatur_alt = Temperatur;
  END
  WAIT(15);
THREAD_END(read_temp)

ON STARTUP DO
  Temperatur = Temperatur_alt = 0;
  THREAD_START(read_temp);
END

CONTROL_END