micro sd read write

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • Page 3 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: 25.04.2021 - 17:58  ·  #17
Hello Merlin, I'm desperate. Nothing works anymore
I'll show you everything I have now
1.MicroSD freshly formatted

My code on the computer, I get
1.EmpfStr = 'FileAssign'
2.EmpfStr = 'FileRewrite'
back, so everyone ok.

On the computer I step through all the lines from
the RichEdit that are sent and get 'ok' back every time

In my RichEdit I have 3 lines to send.


After writing, I immediately get an error while reading.
Error inserting a line in RichEdit


Code

Procedure MMC_Write_File;
var
   i : integer;
begin
   MMC_Sende_Assign;
  //warte bis 'open file' kommt
  if EmpfStr = 'FileAssign' then
  begin
        MMC_Sende_ReWrite;  //MMC_Sende_Append;
        //warte auf  FileRewrite
        if EmpfStr = 'FileRewrite' then   //antwort   FileRewrite  oder FileAppend
        begin
               //Jetzt sende die Zeilen
                for I:= 1 to Form1.RichEdit1.Lines.Count do
                begin     //460=MMC_Block_Write
                   SendeStr:= '460' + Form1.RichEdit1.Lines[i-1];  //sende Daten
                   Form1.TCPClient.IOHandler.Write(SendeStr , IndyTextEncoding_ASCII);
                   EmpfStr:= Form1.TCPClient.IOHandler.ReadLn(IndyTextEncoding_ASCII);
//Stop ->EmpfStr    3 x 'ok'     //<======= Stop check EmpfStr 
                end;

                MMC_Sende_FileClose;  //'ok'
                ShowMessage('Fertig');
        end;
  end;
end;



From here the code in the Xmega 256A3U


Code

//==============================
// Block Write
Procedure MMC_Block_Write;   //460
Begin
  EmpfStr:= EmpfStr + #13+#10;
  www:= word(length(EmpfStr));
  ptr:= @EmpfStr;
  Inc(ptr);

  if F16_BlockWrite(F, ptr, www, Res) then
    if Res = www then
       SendeStr:= 'ok'; Sende_an_Host;
    else
      SendeStr:= 'www no Res'; Sende_an_Host;
    endif;
  else
     SendeStr:= 'Block Write ERROR'; Sende_an_Host;
  endif;
end;



//=============================
//...Function F16_FileRewrite (f : File; [], aTime, aDate);   >417<
Procedure MMC_File_Rewrite;
Begin
  F16_FileRewrite(F,[], 0, 0);
  SendeStr:= 'FileRewrite'; Sende_an_Host;
end;


//=============================
//...F16_FileAssign + F16_FileReset   >413<
Procedure MMC_Open_File;
Begin
  Fn:= EmpfStr;  //FileName übergabe
  if F16_FileAssign(F, '', Fn) then    //
    SendeStr:= 'FileAssign'; Sende_an_Host;
  else
    SendeStr:= 'ERROR open file'; Sende_an_Host;
  endif;
end;

//=============================
//...MMC_Close_File                  >414<
Procedure MMC_Close_File;
begin
  F16_FileClose(F);
  SendeStr:= 'file close'; Sende_an_Host;
end;




I can read a 330KByte file without problems,
which I wrote on the micro SD on the computer.


Gruß Frank
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1409
Registered: 03 / 2005
Subject:

Re: micro sd read write

 · 
Posted: 25.04.2021 - 21:12  ·  #18
Hi Frank.

Unless EmpfStr and RecStr are the same thing (which I don't believe that they are), then your code cannot work. Ptr points to the text of EmpfStr but you are appending CRLF to RecStr, and using the length of RecStr to decide how much of EmpfStr to write. That cannot be correct.

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: 26.04.2021 - 07:32  ·  #19
Good Morning,
@Merlin that can't be, SendeStr is not EmpfStr.
There are 2 strings.

Why does Append work and not ReWrite?
I can write and read with Append

First thing I do
MMC_INIT; //1
MMC_RESET; // 2
MMC_CheckDisk; // 3

If I do that ...
1. Assign
2. ReWrite
3. F16_BlockWrite
4.CloseFile
And now I can't read anything anymore


But if I do
1. Assign
2. Append
3. F16_BlockWrite
4. CloseFile
I can read and rewrite.


Where is the mistake ?

Gruß Frank


Code

var 
  EmpfStr   : TW5x00String;
  SendeStr  : string[254];

Procedure Sende_an_Host;
Begin
 SendeStr:= SendeStr + #13+#10;
 W5x00StartSendString( cPCSocket, @SendeStr );
end;






Code

//==============================//460
// Block Write
Procedure MMC_Block_Write;
Begin
  EmpfStr:= EmpfStr + #13+#10;
  www:= word(length(EmpfStr));
  ptr:= @EmpfStr;
  Inc(ptr);

  if F16_BlockWrite(F, ptr, www, Res) then
    if Res = www then
       SendeStr:= 'ok'; Sende_an_Host;
    else
      SendeStr:= 'www no Res'; Sende_an_Host;
    endif;
  else
     SendeStr:= 'Block Write ERROR'; Sende_an_Host;
  endif;
end;
//=============================//417
//...Function F16_FileRewrite (f : File; [], aTime, aDate);
Procedure MMC_File_Rewrite;
Begin
  if  F16_FileRewrite(F,[faArchive], 0, 0) then
    SendeStr:= 'FileRewrite'; Sende_an_Host;
  else
    SendeStr:= 'ERROR FileRewrite'; Sende_an_Host;
  endif;
end;
//=============================//416
//...F16_FileAppend;
//...F16_FileAppend (f : File) : boolean;
Procedure MMC_File_Append;
Begin
  if  F16_FileAppend(f) = true then
      SendeStr:= 'FileAppend'; Sende_an_Host;
  else
      SendeStr:= 'ERROR FileAppend'; Sende_an_Host;
  endif;
end;
//=============================
//...MMC_Close_File                  >414<
Procedure MMC_Close_File;
begin
 if  F16_FileClose(F) = true then
    SendeStr:= 'file close'; Sende_an_Host;
 else
    SendeStr:= 'ERROR file close'; Sende_an_Host;
 endif;
end;


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

Re: micro sd read write

 · 
Posted: 26.04.2021 - 09:14  ·  #20
Hi Frank.

I am sorry - maybe something lost in translation :-)

Quote
@Merlin that can't be, SendeStr is not EmpfStr.
There are 2 strings.


I didn't mention SendeStr, I was talking about RecStr. And that was my point. They are different strings but you mix them up. You write

  RecStr: = RecStr + # 13 + # 10;
  www: = word (length (RECStr));
  ptr: = @EmpfStr;
  Inc (ptr);

  if F16_BlockWrite (F, ptrwww, Res) then


I have put in bold those bits referring to RecStr and bold italics those bits referring to RecStr. The parameters in F16_BlockWrite should either be bold or bold italics but not a mixture of the two.

You ask
Quote
Why does Append work and not ReWrite?
I can write and read with Append


I don't think you can. I think both write rubbish to the file. But with append you are adding at the end of an existing file, and so will be able to read the original text. With rewrite you are replacing the file entirely and be able to read only garbage with no CRLF character. You can test this by trying to put different text strings in append mode. I will bet that you read back the original lines not the new ones.

I hope that helps.

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

Re: micro sd read write

 · 
Posted: 26.04.2021 - 20:00  ·  #21
Guten Nabend,
eine kleine Frage an alle.

Ich habe niicht dran gedacht das die Pullup Widerstände an der MicroSD Karte
beim design fehlen.

Die Karte hängt an einen XMega256A3U
reichen die internen Pullup Widerstände ?


Gruß Frank
Attachments
micro sd read write
Filename: MicroSd_2.jpg
Filesize: 187.56 KB
Title:
Download counter: 153
Harry
Moderator
Avatar
Gender:
Location: zwischen Augsburg und Ulm
Age: 59
Posts: 2134
Registered: 03 / 2003
Subject:

Re: micro sd read write

 · 
Posted: 26.04.2021 - 20:10  ·  #22
Hi Frank,

gibt es für den 4-Bit-Mode ein Schaltplanbeispiel? Wie sollte es ausschauen?

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

Re: micro sd read write

 · 
Posted: 26.04.2021 - 20:13  ·  #23
Ich habe es so gemacht.

https://de.wikipedia.org/wiki/MicroSD
Attachments
micro sd read write
Filename: MicroSd.jpg
Filesize: 86.41 KB
Title:
Download counter: 141
micro sd read write
Filename: MicroSd_1.jpg
Filesize: 110.84 KB
Title:
Download counter: 141
Harry
Moderator
Avatar
Gender:
Location: zwischen Augsburg und Ulm
Age: 59
Posts: 2134
Registered: 03 / 2003
Subject:

Re: micro sd read write

 · 
Posted: 27.04.2021 - 07:30  ·  #24
Und wo und für was braucht man da PullUp-Widerstände?

Harry
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • Page 3 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: 17 · Cache Hits: 15   141   156 · Page-Gen-Time: 0.026804s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI