Hallo liebes Forum,
bei mir tritt die Situation auf, das F16_Blockread sporadisch "true" liefert, obwohl die SD-Card während des Betriebs entfernt wurde. Die Anzahl gelesener Bytes beträgt in diesem Fall laut F16_Blockread 512 Bytes.
Ich möchte die Ursache klären und brauche dazu die Hilfe aus diesem tollen Forum.
Gruß
Thomas.AC
program test;
{ $W+}
{$NOSHADOW}
Device = xmega128A4U, VCC = 3.3;
Import SysTick;
Import FAT16_32, SerPortE0;
From System Import Longword, SystemTime32;
Define
OSCtype = int2MHz,PLLmul=16,prescA=1,prescB=1,prescC=1,overdrive;
SysTick = 10, adj;
StackSize = 64, iData;
FrameSize = 256, iData;
SerPortE0 = 19200; // USART to PC
TxBufferE0 = 32, iData;
RxBufferE0 = 32, iData;
//SysLEDblink = mSec300; {10..1000 msec}
//SysLEDBlink0 = PortQ.3, low; {LEDon = low level}
//FAT16 = SDIO, PortA.0, PortD.5, PortD.7, iData; //4-bit port,CMD,CLK
FAT16 = SPI_D, PortD.4, iData; // SPI_X, SS-Port, SS-PIN, data area
F16_FileHandles = 2;
F16_DirLevels = 1;
F16_MMCspeed = superfast; // standard, slow, fast, superfast
F16_StrLen = 20;
//uses SerialIOmod;
Uses UFAT16_32;
Implementation
{$IDATA}
const
var
fileBuffer0,fileBuffer1 : array[0..511] of byte;
F0,F1 : File of Byte;
SR : TSearchRec;
FileName : tFileName;
c : char;
count : word;
flag : boolean;
procedure InitPorts;
begin
// pullup on SPI MISO
end;
// -----------------------------------------------------------------------------
Function ListDir : boolean;
var LastDir : TSearchRec;
begin
Writeln(SeroutE0, 'List Volume Items');
if F16_FindFirst ('', '*.*', faAnyFile, SR) then
repeat
Filename:= SR.Name;
Writeln(SeroutE0, ' - ' + SR.name);
until not F16_FindNext(SR);
endif;
return(true);
end;
// -----------------------------------------------------------------------------
function InitSDCard : boolean;
var
bool : boolean;
SizeMB : longword;
begin
Writeln(SeroutE0, 'TEST');
if F16_DiskInit then
Writeln(SeroutE0, 'MMC init ok!');
else
Writeln(SeroutE0, 'MMC init fail!');
Return(false);
endif;
if F16_DiskReset then
Writeln(SeroutE0, 'MMC reset ok!');
else
Writeln(SeroutE0, 'MMC reset fail!');
Return(false);
endif;
if F16_CheckDisk then // we check for an existing FAT16 system
SizeMB := F16_GetDiskSize;
Writeln(SeroutE0, 'Card Size total ' + LongToStr(SizeMB) + ' kbyte');
SizeMB := F16_GetDiskFree;
Writeln(SeroutE0, 'Unused size ' + LongToStr(SizeMB) + ' kbyte');
SizeMB := F16_GetDiskUsed;
Writeln(SeroutE0, 'Used size ' + LongToStr(SizeMB) + ' kbyte');
else
Writeln(SeroutE0, 'CheckDisk fail!');
Return(false);
endif;
ListDir;
Return(true);
end;
{ Main Program }
{******************************************************************************}
begin
EnableInts($87);
PIN6CTRLD := PIN6CTRLD or %00011000; // pullup on SPI MISO
InitSDCard;
if F16_FileAssign(F0, '', '1.wav') then
Writeln(SeroutE0,'FileAssign F0 with 1.wav OK');
else
Writeln(SeroutE0,'FileAssign F0 with 1.wav fail!');
endif;
if F16_FileReset(F0) then
Writeln(SeroutE0,'FileReset F0 OK');
else
Writeln(SeroutE0,'FileReset F0 fail!');
endif;
if F16_FileAssign(F1, '', '1.wav') then
Writeln(SeroutE0,'FileAssign F1 with 1.wav OK');
else
Writeln(SeroutE0,'FileAssign F1 with 1.wav fail!');
endif;
if F16_FileReset(F1) then
Writeln(SeroutE0,'FileReset F1 OK');
else
Writeln(SeroutE0,'FileReset F1 fail!');
endif;
loop
// remove SD card and watch your terminal
if F16_BlockRead(F0,@fileBuffer0,512,count) then
if flag then
Writeln(SeroutE0,'Whats that? BlockRead okay after removing card?'
+IntToStr(count));
endif;
else
flag := true;
endif;
mDelay(4);
endloop;
end test.
bei mir tritt die Situation auf, das F16_Blockread sporadisch "true" liefert, obwohl die SD-Card während des Betriebs entfernt wurde. Die Anzahl gelesener Bytes beträgt in diesem Fall laut F16_Blockread 512 Bytes.
Ich möchte die Ursache klären und brauche dazu die Hilfe aus diesem tollen Forum.
Gruß
Thomas.AC
Code
program test;
{ $W+}
{$NOSHADOW}
Device = xmega128A4U, VCC = 3.3;
Import SysTick;
Import FAT16_32, SerPortE0;
From System Import Longword, SystemTime32;
Define
OSCtype = int2MHz,PLLmul=16,prescA=1,prescB=1,prescC=1,overdrive;
SysTick = 10, adj;
StackSize = 64, iData;
FrameSize = 256, iData;
SerPortE0 = 19200; // USART to PC
TxBufferE0 = 32, iData;
RxBufferE0 = 32, iData;
//SysLEDblink = mSec300; {10..1000 msec}
//SysLEDBlink0 = PortQ.3, low; {LEDon = low level}
//FAT16 = SDIO, PortA.0, PortD.5, PortD.7, iData; //4-bit port,CMD,CLK
FAT16 = SPI_D, PortD.4, iData; // SPI_X, SS-Port, SS-PIN, data area
F16_FileHandles = 2;
F16_DirLevels = 1;
F16_MMCspeed = superfast; // standard, slow, fast, superfast
F16_StrLen = 20;
//uses SerialIOmod;
Uses UFAT16_32;
Implementation
{$IDATA}
const
var
fileBuffer0,fileBuffer1 : array[0..511] of byte;
F0,F1 : File of Byte;
SR : TSearchRec;
FileName : tFileName;
c : char;
count : word;
flag : boolean;
procedure InitPorts;
begin
// pullup on SPI MISO
end;
// -----------------------------------------------------------------------------
Function ListDir : boolean;
var LastDir : TSearchRec;
begin
Writeln(SeroutE0, 'List Volume Items');
if F16_FindFirst ('', '*.*', faAnyFile, SR) then
repeat
Filename:= SR.Name;
Writeln(SeroutE0, ' - ' + SR.name);
until not F16_FindNext(SR);
endif;
return(true);
end;
// -----------------------------------------------------------------------------
function InitSDCard : boolean;
var
bool : boolean;
SizeMB : longword;
begin
Writeln(SeroutE0, 'TEST');
if F16_DiskInit then
Writeln(SeroutE0, 'MMC init ok!');
else
Writeln(SeroutE0, 'MMC init fail!');
Return(false);
endif;
if F16_DiskReset then
Writeln(SeroutE0, 'MMC reset ok!');
else
Writeln(SeroutE0, 'MMC reset fail!');
Return(false);
endif;
if F16_CheckDisk then // we check for an existing FAT16 system
SizeMB := F16_GetDiskSize;
Writeln(SeroutE0, 'Card Size total ' + LongToStr(SizeMB) + ' kbyte');
SizeMB := F16_GetDiskFree;
Writeln(SeroutE0, 'Unused size ' + LongToStr(SizeMB) + ' kbyte');
SizeMB := F16_GetDiskUsed;
Writeln(SeroutE0, 'Used size ' + LongToStr(SizeMB) + ' kbyte');
else
Writeln(SeroutE0, 'CheckDisk fail!');
Return(false);
endif;
ListDir;
Return(true);
end;
{ Main Program }
{******************************************************************************}
begin
EnableInts($87);
PIN6CTRLD := PIN6CTRLD or %00011000; // pullup on SPI MISO
InitSDCard;
if F16_FileAssign(F0, '', '1.wav') then
Writeln(SeroutE0,'FileAssign F0 with 1.wav OK');
else
Writeln(SeroutE0,'FileAssign F0 with 1.wav fail!');
endif;
if F16_FileReset(F0) then
Writeln(SeroutE0,'FileReset F0 OK');
else
Writeln(SeroutE0,'FileReset F0 fail!');
endif;
if F16_FileAssign(F1, '', '1.wav') then
Writeln(SeroutE0,'FileAssign F1 with 1.wav OK');
else
Writeln(SeroutE0,'FileAssign F1 with 1.wav fail!');
endif;
if F16_FileReset(F1) then
Writeln(SeroutE0,'FileReset F1 OK');
else
Writeln(SeroutE0,'FileReset F1 fail!');
endif;
loop
// remove SD card and watch your terminal
if F16_BlockRead(F0,@fileBuffer0,512,count) then
if flag then
Writeln(SeroutE0,'Whats that? BlockRead okay after removing card?'
+IntToStr(count));
endif;
else
flag := true;
endif;
mDelay(4);
endloop;
end test.
Attachments
Filename: | blockread.png |
Filesize: | 38.31 KB |
Title: | Blockread |
Download counter: | 146 |