-         

Ergebnis 1 bis 4 von 4

Thema: mmc-karte mit bascom

  1. #1
    Benutzer Stammmitglied
    Registriert seit
    12.05.2007
    Beiträge
    31

    mmc-karte mit bascom

    Anzeige

    ' Declare here you SPI-Mode
    ' using HW-SPI: cMMC_Soft = 0
    ' not using HW_SPI: cMMC_Soft = 1

    Const cMMC_Soft = 0

    #IF cMMC_Soft = 0

    ' --------- Start of Section for HW-SPI ----------------------------------------

    ' define Chip-Select Pin
    Config PinB.4 = Output ' define here Pin for CS of MMC/SD Card
    Mmc_cs Alias PortB.4
    Set Mmc_cs

    ' Define here SS Pin of HW-SPI of the CPU (f.e. Pinb.0 on M12
    ' If an other Pin than SS is used for MMC_SS, SS must be set to OUTPUT and high for proper work of SPI
    ' otherwise AVR starts SPI-SLAVE if SS-Pin is INPUT and goes to LOW
    Config Pinb.4 = Output ' define here Pin of SPI SS
    Spi_ss Alias PortB.4
    Set Spi_ss ' Set SPI-SS to Output and High por Proper work of
    ' SPI as Master

    ' HW-SPI is configured to highest Speed
    Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 1
    ' Spsr = 1 ' Double speed on ATMega128
    Spiinit ' Init SPI

    ' --------- End of Section for HW-SPI ------------------------------------------

    #ELSE ' Config here SPI pins, if not using HW SPI

    ' --------- Start of Section for Soft-SPI --------------------------------------

    ' Chip Select Pin => Pin 1 of MMC/SD
    Config PinB.3 = Output
    MMC_CS Alias PortB.3
    Set MMC_CS

    ' MOSI - Pin => Pin 2 of MMC/SD
    Config PinB.5 = Output
    Set PinB.5
    MMC_PortMOSI Alias PortB
    bMMC_MOSI Alias 5

    ' MISO - Pin => Pin 7 of MMC/SD
    Config PinB.6 = Input
    MMC_PortMISO Alias PinB
    bMMC_MISO Alias 6

    ' SCK - Pin => Pin 5 of MMC/SD
    Config PinB.7 = Output
    Set PinB.7
    MMC_PortSCK Alias PortB
    bMMC_SCK Alias 7

    ' --------- End of Section for Soft-SPI ----------------------------------------

    #ENDIF

    ' ========== End of user definable range =======================================


    ' Error
    Const Cperrdrivereset = 225 ' Error response Byte at Reset command
    Const Cperrdriveinit = 226 ' Error response Byte at Init Command
    Const Cperrdrivereadcommand = 227 ' Error response Byte at Read Command
    Const Cperrdrivewritecommand = 228 ' Error response Byte at Write Command
    Const Cperrdrivereadresponse = 229 ' No Data response Byte from MMC at Read
    Const Cperrdrivewriteresponse = 230 ' No Data response Byte from MMC at Write
    Const Cperrdrive = 231
    Const Cperrdrivenotsupported = 232 ' return code for DriveGetIdentity, not supported yet

    Waitms 1 ' Wait some time before initialising MMC/SD
    Dim Gbdriveerror As Byte ' General Driver Error register
    Dim Gbdriveerrorreg As Byte ' Driver load Error-Register of HD in case of error
    Dim Gbdrivestatusreg As Byte ' Driver load Status-Register of HD on case of error
    Dim Gbdrivedebug As Byte
    $lib "MMC.LIB" ' link driver library
    $EXTERNAL _mmc
    Gbdriveerror = Driveinit() ' Init MMC/SD Card

    hallo, wenn ich auf hardware gehe und für den AVR portb4 nehme , kommt eine fehlermeldung . warm?

    mfg

  2. #2
    Erfahrener Benutzer Fleißiges Mitglied
    Registriert seit
    19.08.2004
    Beiträge
    197
    Keine Kontrollereinstellung zu sehen, woher weiß der Compiler, wenn du es nicht deklarierst, was für ein Kontroller er nehmen soll und ob er überhaupt Port4 hat. Also nimmt er den der voreingestellt ist.
    Das Listing oben muß noch angepaßt werden Stack Quarz usw.

  3. #3
    Benutzer Stammmitglied
    Registriert seit
    12.05.2007
    Beiträge
    31
    ich rufe es hier mit auf :



    $Regfile = "M8def.dat"
    $Crystal = 8000000
    $HWStack = 32
    $SWStack = 32
    $FrameSize = 64
    $Baud = 19200

    Declare Sub Sramdump(byval pwsrampointer As Word , Byval Pwlength As Word)
    $Include "Config_MMC.bas"

    If gbDriveError <> 0 then
    Print "MMC/SD Initialisierung fehlgeschlagen"
    end
    Endif

    Dim bError as Byte
    dim a as Byte
    Dim aBuffer(512) as Byte ' SRAM-Bereich für den Transfer
    Dim wSRAMPointer as Word ' Adress-Pointer für den Drive... Routine
    Dim lSectorNumber as Long ' Variable für Sektor-Nummer

    ' Adresse des Buffers in die Variable

    wSRAMPointer =VarPtr(aBuffer(1))

    for a=1 to 255
    aBuffer(a) =a
    next a

    lSectorNumber=0
    bError = DrivewriteSector( wSRAMPointer , lSectorNumber)
    lSectorNumber=1
    bError = DrivewriteSector( wSRAMPointer , lSectorNumber)


    For lSectorNumber = 0 to 1

    bError = DriveReadSector( wSRAMPointer , lSectorNumber)
    ' Konnte der Sektor eingelesen werden?
    if bError > 0 then
    Print "Drive Fehler: " ; bError ; " bei Sektor " ; lSectorNumber
    exit for
    endif

    Print "Sektor " ; lSectorNumber

    ' Sektor ausgeben
    SRAMDump wSRAMPointer, 512
    waitms 400
    next
    end

    Sub Sramdump(byval pwsrampointer As Word , Byval Pwlength As Word)
    ' Dump a Part of SRAM to Print-Output #1
    ' pwSRAMPointer: (Word) Variable which holds the address of SRAM to dump
    ' pwLength: (Word) Count of Bytes to be dumped (1-based)
    Local Lsdump As String * 16
    Local Lbyte1 As Byte , Lbyte2 As Byte
    Local Lword1 As Word , Lword2 As Word
    Local Llong1 As Long

    If Pwlength > 0 Then
    Decr Pwlength
    For Lword1 = 0 To Pwlength
    Lword2 = Lword1 Mod 8
    If Lword2 = 0 Then
    If Lword1 > 0 Then
    Print " " ;
    End If
    End If
    Lword2 = Lword1 Mod 16
    If Lword2 = 0 Then
    If Lword1 > 0 Then
    Print " " ; Lsdump
    End If
    Llong1 = Lword1
    Print Hex(llong1) ; " " ;
    Lsdump = " "
    Lbyte2 = 1
    End If
    Lbyte1 = Inp(pwsrampointer)
    Incr Pwsrampointer
    Print Hex(lbyte1) ; " " ;
    If Lbyte1 > 31 Then
    Mid(lsdump , Lbyte2 , 1) = Lbyte1
    Else
    Mid(lsdump , Lbyte2 , 1) = "."
    End If
    Incr Lbyte2
    Next
    Print " " ; Lsdump
    End If
    Incr Pwlength
    End Sub

  4. #4
    Erfahrener Benutzer Fleißiges Mitglied
    Registriert seit
    19.08.2004
    Beiträge
    197

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •