SPI-Takt setzt plötzlich aus

Dies ist das deutsche Forum für alle Themen um den IO-Warrior. Beiträge bitte nur in Deutsch.

Moderator: Guido Körber

Post Reply
Franz Peter Zantis
Posts: 97
Joined: Wed Aug 03, 2011 3:46 pm
Contact:

SPI-Takt setzt plötzlich aus

Post by Franz Peter Zantis »

Eine SD-Karte ist mit einem IO-Warrior56 verbunden (Modul). Man kann Daten vom PC aus binär auf die Karte schreiben oder von der Karte lesen. Der Datenaustausch läuft über SPI. Es wird Sektorweise (512-Byte-Sektoren) gelesen. Seltsamerweise stoppt manchmal der SPI-Takt (es kommt kein Takt mehr aus dem IO-Warrior) und die Übertragung stoppt. Manchmal geschied das unmittelbar nachdem die Steuerkommandos an die SD-Karte erfolgreich übergeben wurden oder erst nachdem fast 512 Byte gelesen wurden. In jedem Fall kann das Programm dann nur noch über den Taskmanager beendet werden.
Vielleicht hatte schon jemand ein ähnliches Problem?

Viele Grüße
Franz Peter Zantis


Private Sub readsector(ByVal lsectoraddress As Long)
'this sub reads one sector (length of the sector is 512 Byte) beginning at lsectoraddress from the SC-Card
'the data are in the global array sdreadsector()
Dim lcounter As Integer = 0
Dim ln As Long 'counter
Dim lpos As Long 'for the CD-Block-Position
Dim lFFcounter As Integer 'fill the SPI-Register with FF
Dim lstring As String
Dim l4MSB As Byte 'Block address
Dim l3MID As Byte 'Block address
Dim l2MID As Byte 'Block address
Dim l1LSB As Byte 'Block address

'preparing the block address
lsectoraddress = lsectoraddress * 512 '(block address; multiple of blocksize 512)
l1LSB = CByte(lsectoraddress And &HFF)
l2MID = CByte((lsectoraddress >> 8) And &HFF)
l3MID = CByte((lsectoraddress >> 16) And &HFF)
l4MSB = CByte((lsectoraddress >> 24) And &HFF)

'Read one Block (512 Byte) from the SD-Card with CMD17
lcounter = 0
Do
'CS to high
IOdatawrite(2) = SetBit(IOdatawrite(2), 0)
intret = IowKitWrite(IOhandle, 0, IOdatawrite(0), 8)
System.Threading.Thread.Sleep(10)
lcounter = lcounter + 1
'CS to low (P1.0)
IOdatawrite(2) = ClearBit(IOdatawrite(2), 0)
intret = IowKitWrite(IOhandle, 0, IOdatawrite(0), 8)
IOspidata(0) = &H9
IOspidata(1) = &H6 'sending 6 Byte = length of CMD-command plus CRC and stop-Bit
IOspidata(2) = &H0 'not relevant
IOspidata(3) = &H51 'CMD17-command, Byte 1
IOspidata(4) = l4MSB 'Blockadresse MSB
IOspidata(5) = l3MID 'Blockadresse
IOspidata(6) = l2MID 'Blockadresse
IOspidata(7) = l1LSB 'Blockadresse LSB
IOspidata(8) = &H1 '7-Bit-CRC-checksum (not used) and one stopbit
intret = IowKitWrite(IOhandle, 1, IOspidata(0), 64)
lcounter = 0
For ln = 0 To 100
'getting answer from the SD-Card; try to get return value 0
IOspidata(0) = &H9
IOspidata(1) = 1 'reading 1 Byte
IOspidata(2) = &H0 'flags
IOspidata(3) = &HFF 'data must be permanent on high
intret = IowKitWrite(IOhandle, 1, IOspidata(0), 64)
intret = IowKitRead(IOhandle, 1, IOspidata(0), 64)
If (IOspidata(2) = 0) Then
Exit For
End If
Next ln
Loop Until (IOspidata(2) = 0) Or (lcounter > numoftries)
If lcounter > numoftries Then
Me.TxtBxStatus.Text = message1 & vbCrLf & vbCrLf & "CMD17: Read prepare" & vbCrLf & "ERROR" & vbCrLf & "Try again. Contact the electronic workshop if it not works." & vbCrLf & "zantis@physik.rwth-aachen.de"
Exit Sub
End If

lcounter = 0
Do
'getting answer from the SD-Card; try to get return value &HFE
lcounter = lcounter + 1
IOspidata(0) = &H9
IOspidata(1) = 1 'reading 1 Byte
IOspidata(2) = &H0 'flags
IOspidata(3) = &HFF 'data must be permanent on high
intret = IowKitWrite(IOhandle, 1, IOspidata(0), 64)
intret = IowKitRead(IOhandle, 1, IOspidata(0), 64)
Loop Until (IOspidata(2) = 254) Or (lcounter > numoftries)
If lcounter > numoftries Then
Me.TxtBxStatus.Text = message1 & vbCrLf & vbCrLf & "CMD17: FE missing! Cannot read!" & vbCrLf & "ERROR" & vbCrLf & "Try again. Contact the electronic workshop if it not works." & vbCrLf & "zantis@physik.rwth-aachen.de"
Exit Sub
End If

'getting data from the SD-Card; read 512 times 1 Byte = 512 Byte
lpos = 0
For lcounter = 1 To 512
For lFFcounter = 0 To 63
IOspidata(lFFcounter) = &HFF 'data must be permanent on high
Next lFFcounter
IOspidata(0) = &H9
IOspidata(1) = 1 'reading 1 Byte
IOspidata(2) = &H0 'flags
intret = IowKitWrite(IOhandle, 1, IOspidata(0), 64)
intret = IowKitRead(IOhandle, 1, IOspidata(0), 64)
sdreadsector(CInt(lcounter)) = IOspidata(2)
'Debug.Print(CStr(IOspidata(2)))
Next lcounter

'read two CRC Bytes
For lFFcounter = 0 To 63
IOspidata(lFFcounter) = &HFF 'data must be permanent on high
Next lFFcounter
IOspidata(0) = &H9
IOspidata(1) = &H2 'reading 2 Byte
IOspidata(2) = &H0 'flags
intret = IowKitWrite(IOhandle, 1, IOspidata(0), 64)
intret = IowKitRead(IOhandle, 1, IOspidata(0), 64)

'CS to high (P1.0)
IOdatawrite(2) = SetBit(IOdatawrite(2), 0)
intret = IowKitWrite(IOhandle, 0, IOdatawrite(0), 8)
lstring = dummyclock(1) 'sending 8 dummy-clocks
End Sub
Guido Körber
Site Admin
Posts: 2856
Joined: Tue Nov 25, 2003 10:25 pm
Location: Germany/Berlin
Contact:

Re: SPI-Takt setzt plötzlich aus

Post by Guido Körber »

Hallo Herr Zantis,
wir sind gerade in den letzten Vorbereitungen zur electronica. Kommen Sie da auch hin?
Das Problem müssten wir bis nach der Messe vertagen.
Franz Peter Zantis
Posts: 97
Joined: Wed Aug 03, 2011 3:46 pm
Contact:

Re: SPI-Takt setzt plötzlich aus

Post by Franz Peter Zantis »

Ich kann leider nicht hinkommen. Aber einer meiner Mitarbeiter wird kommen und auch ihren Stand besuchen.
Franz Peter Zantis
Posts: 97
Joined: Wed Aug 03, 2011 3:46 pm
Contact:

Re: SPI-Takt setzt plötzlich aus

Post by Franz Peter Zantis »

Gibt es zu diesem Thema irgendeine Erfahrung?
Post Reply