من این تابع رو برای خوندن و نوشتن رو سکتور نوشتم . ببینید عیبی نداره ؟؟؟
فقط نوع آدرس دهی های قاطی میکنه ؟؟؟؟ مثلا من می خوام رو سکتور 5 بنویسم آدرس 5 را نباید بفرستم . (اینجور که چند جا خوندم ) . باید آدرسو محاسبه کنم .
کد:
Function Writemmc_sector(byval Num As Long) As Byte
Local Command As Byte
Local K As Byte
Local Response As Byte
Local Address As Long
Local Repeat As Integer
Address = Num
Print Address
Set Cs
Command = &HFF
Spiout Command , 1
Reset Cs
Command = &H58
Spiout Command , 1
Spiout Address , 4
Command = &HFF
Spiout Command , 1
Spiout Command , 1
Spiin Response , 1
While Response <> 0
Spiin Response , 1
Wend
Print Hex(response)
Command = &HFE
Spiout Command , 1
Command = 10
For Repeat = 1 To 512
Command = Sect(repeat)
Spiout Command , 1
Next Repeat
Command = &HFF
Spiout Command , 1
Command = &HFF
Spiout Command , 1
Spiin Response , 1
Spiin Response , 1
Spiin Response , 1
While Response = 0
Spiin Response , 1
Wend
Writemmc_sector = 1
End Function
کد:
Function Read_mmc_sector(byval Num As Long) As Byte
Local Command As Byte
Local Response As Byte
Local Reads(512) As Byte
Local Address As Long
Local Repeat As Integer
Address = num
Print Address
Set Cs
Print "step 1"
Command = &HFF
Spiout Command , 1
Reset Cs
Print "step 2"
Command = &H51
Spiout Command , 1
'Address = &H00
Print "step 3"
Spiout Address , 4
'Command = &HFF
Print "step 4"
'Spiout Command , 1
Spiin Response , 1
Print "step 5"
Wait 1
While Response <> 0
Spiin Response , 1
Wend
Print "step 6"
While Response <> &HFE
Spiin Response , 1
Wend
Waitms 100
Print "step 7"
For Repeat = 1 To 512
Spiin Response , 1
Sect(repeat) = Response
Next I
Waitms 100
Print "step 8"
Set Cs
Set Read_mmc_sector
End Function
این برنامه تست شده است و فقط رو سکتور 1 جواب میده ....!!!