micro sd read write

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • Page 2 of 6
TheBeginner
Schreiberling
Avatar
Gender: n/a
Location: Wunsiedel Bayern
Age: 67
Posts: 767
Registered: 06 / 2013
Subject:

Re: micro sd read write

 · 
Posted: 24.04.2021 - 20:58  ·  #9
Hello Merlin,
I understood that tomorrow, I'll write the new code. It's over for today.
==================
Hallo Merlin,
das habe ich verstanden morgen gehts weiter, dann schreibe ich den neuen Code. Für heute ist schluss.


Gruß Frank
Harry
Moderator
Avatar
Gender:
Location: zwischen Augsburg und Ulm
Age: 59
Posts: 2134
Registered: 03 / 2003
Subject:

Re: micro sd read write

 · 
Posted: 24.04.2021 - 21:34  ·  #10
Hallo,

eine Frage zwischendurch: Hat einer von euch schon mal eine SD-Karte bei laufendem uC gesteckt oder gezogen? Natürlich kontrolliert also kein Zugriff auf die SD. Wie habt ihr das gemacht? Spannung der SD vorher abgeschaltet?

Gruss
Harry
golf
Benutzer
Avatar
Gender:
Location: Donauwörth
Age: 71
Posts: 256
Registered: 11 / 2009
Subject:

Re: micro sd read write

 · 
Posted: 25.04.2021 - 05:44  ·  #11
Hallo Harry,
ich hab mal einen Audio (Infraschall)-Recorder gebaut mit einstellbaren Sampleraten 8000,4000,2000,...,250 Hz. Wollte den Lärm der anliegenden Bundesstraße mal dokumentieren. Da hab ich oft nach Aufnahme Stop die SD-Karte bei Stromversorgung der Platine gezogen und über den PC die aufgezeichneten Wavefiles angeschaut. Das gab bei mir keine Probleme.
golf
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1409
Registered: 03 / 2005
Subject:

Re: micro sd read write

 · 
Posted: 25.04.2021 - 10:42  ·  #12
Hi Harry. You will have a problem if you pull the card during a write operation. Not sure if you do it during a read operation, but I think that will be OK for the card (maybe not for the application). Otherwise it should be fine. Pretty much the same as for a PC, but since write operations are immediate there is no eject. (Eject forces pending write operations to be completed and any locks to be released on a PC). But it being powered should not be an issue.
TheBeginner
Schreiberling
Avatar
Gender: n/a
Location: Wunsiedel Bayern
Age: 67
Posts: 767
Registered: 06 / 2013
Subject:

Re: micro sd read write

 · 
Posted: 25.04.2021 - 12:52  ·  #13
Guten morgen,

Also beim Lesen habe ich keine Probleme mehr, das haut 100% hin

Aber beim schreiben bin ich von WriteLn runter gekommen und nehme jetzt
Block_Write weil ich über Res sehen möchte das der Block auch gescjrieben
wurde.

Beim zurück lesen habe ich nach ein paar Zeilen das selbe Problem.

Gruß Frank



Code

//==============================
// Block Write
Procedure MMC_Block_Write;   //460
Begin
  Res:= 0;
  EmpfStr:= EmpfStr + #13+#10;
  www:= word(length(EmpfStr));
  ptr:= @EmpfStr;
  Inc(ptr);
  F16_BlockWrite(F, ptr, www, Res);
  Repeat
    nop;
  until res = www;
  SendeStr:= 'ok'; Sende_an_Host;
end;
Harry
Moderator
Avatar
Gender:
Location: zwischen Augsburg und Ulm
Age: 59
Posts: 2134
Registered: 03 / 2003
Subject:

Re: micro sd read write

 · 
Posted: 25.04.2021 - 13:06  ·  #14
Hello Merlin,

I never pull out an SD card when a file is open. I wanted to know if you should turn off the voltage before pulling.

Regards
Harry
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1409
Registered: 03 / 2005
Subject:

Re: micro sd read write

 · 
Posted: 25.04.2021 - 14:31  ·  #15
Hi Frank.

Edited! I was wrong in a few places!
There are a few issues here.

Code
www: = word (length (RECStr));


If you are using block write you need to include the length byte of the string, so

Code
www: = word (length (RECStr)) + 1;


Code
  ptr: = @EmpfStr;
  Inc (ptr);


This does not look right at all. Should it not be

Code
  ptr: = @RecStr[1];
?

or maybe

Code
  ptr: = @RecStr;
  inc (ptr);


Code
  F16_BlockWrite (F, ptr, www, res);
  Repeat
    nop;
  until res = www;


if www<>res first time this will always fail because nowhere can either www or res change! In any event it will write garbage at the end of the line because www measures the length of RecStr but you are writing EmpfStr but without the length byte. So even if your write is successful it will be unreadable. But as long as you are writing less than 512 bytes (which you always will be) it will either succeed or fail. Hence you can use the boolean result to determine that. If it fails then it will always fail and there is no point in waiting for the record count to match.

So just

Code
  if F16_BlockWrite(F, ptr, www, Res) then
 
    if Res = www then
       SendeStr:= 'ok'; Sende_an_Host;
    else
      // whatever
    endif;
  else
     SendeStr:= 'fail'; Sende_an_Host;
  endif;




Regards

Merlin
TheBeginner
Schreiberling
Avatar
Gender: n/a
Location: Wunsiedel Bayern
Age: 67
Posts: 767
Registered: 06 / 2013
Subject:

Re: micro sd read write

 · 
Posted: 25.04.2021 - 16:59  ·  #16
Hello Merlin, I'm currently testing


Gruß Frank
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • Page 2 of 6
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   137   151 · Page-Gen-Time: 0.027918s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI