Hallo Leute,
ich bin gerade dabei, eine SD-Karte mit einem ATMEGA328P anzusteuern.
Dazu hab ich mir die Library von Roland Riegel geholt und bin momentan
am UART-Debuggen. Hier ist der Quellcode, den ich für das Schreiben
einer Datei auf der SD-Karte verwende:
1 | int connect_sd(void)
|
2 |
|
3 | {
|
4 | struct partition_struct* partition;
|
5 | struct fat_dir_struct* dd;
|
6 | struct fat_fs_struct* fs;
|
7 |
|
8 | if (!sd_raw_init())
|
9 | {
|
10 | println("MMC/SD Initialization failed");
|
11 | sd_initiated = 0;
|
12 | }
|
13 | else
|
14 | {
|
15 | sd_initiated = 1;
|
16 | println("MMC/SD initialization successful!");
|
17 | }
|
18 |
|
19 | if (sd_initiated)
|
20 | {
|
21 | struct partition_struct* partition = partition_open( sd_raw_read, sd_raw_read_interval, sd_raw_write, sd_raw_write_interval, 0);
|
22 | if (!partition)
|
23 | {
|
24 | partition = partition_open(sd_raw_read, sd_raw_read_interval, sd_raw_write, sd_raw_write_interval, -1);
|
25 | if (!partition)
|
26 | {
|
27 | println("opening partition failed");
|
28 | }
|
29 | }
|
30 |
|
31 | if(partition !=0)
|
32 | {
|
33 | sd_partitioned = 1;
|
34 | println("partition found");
|
35 | fs = fat_open (partition);
|
36 | if (!fs)
|
37 | {
|
38 | println("opening filesystem failed");
|
39 | }
|
40 | struct fat_dir_entry_struct directory;
|
41 | fat_get_dir_entry_of_path(fs, "/", &directory);
|
42 | dd = fat_open_dir(fs, &directory);
|
43 | if (!dd)
|
44 | {
|
45 | println("opening root directory failed");
|
46 | }
|
47 | else
|
48 | {
|
49 | println("opening root directory successful");
|
50 | sd_root = 1;
|
51 | }
|
52 | }
|
53 |
|
54 | /* Ab hier Auskommentiert
|
55 |
|
56 | if(sd_root !=0)
|
57 | {
|
58 | struct fat_file_struct* fd = open_file_in_dir(fs, dd, "TEST.TXT");
|
59 | if (!fd)
|
60 | {
|
61 | println("could not open test.txt");
|
62 | }
|
63 | else
|
64 | {
|
65 | fat_write_file(fd, "testzeile", 15);
|
66 | sd_raw_sync();
|
67 | println("writing successful");
|
68 | }
|
69 | fat_close(fs);
|
70 | partition_close(partition);
|
71 | }
|
72 | */
|
73 | }
|
74 |
|
75 | return sd_root;
|
76 | }
|
Zuerst sagt der Compiler, dass "open_file_in_dir" nicht definiert ist.
Ich denke, da fehler noch irgendwelche Includebefehle?
Jedenfalls kommentiere ich den Teil erstmal raus und Kompilier dann. Die
verwendeten SD-Karten werden erkannt aber bleiben beim Öffnen der
Partition hängen. Der Uart String "open partition failed" wird gesendet.
Formatiert hab ich die SD-Karte auf FAT16 mit Windows 7 Enterprise.
Habt ihr eine Idee, was das Problem sein könnte? Sollte ich die SD-Karte
vielleicht anders Formatieren?
Mit freundlichen Grüßen,
Thomas