- 3D-Druck Einstieg und Tipps         
Seite 3 von 3 ErsteErste 123
Ergebnis 21 bis 23 von 23

Thema: SD Karte

  1. #21
    Erfahrener Benutzer Roboter Genie
    Registriert seit
    16.02.2006
    Beiträge
    1.113
    Anzeige

    Powerstation Test
    Hallo,
    @sechsrad
    es ist bestimmt sinnvoll, auch mal die Hintergründe verstanden zu haben und die Kommunikation mit der Karte selbst auf die Beine gestellt zu haben.
    Aber wenn du schon ohne DOS arbeiten willst, dann würde ich die Funktionen DriveReadSector() und DriveWriteSector() benutzen. Da hast du auch den ganzen DOS Overhead nicht und es braucht wesentlich weniger Speicher.
    Deine Routinen kompilieren bei mir zu 3744 Byte, was einen Mega8 schon zur Hälfte voll macht. Ein vergleichbares Programm mit den beiden Befehlen compiliert zu 1356 Byte.
    Code:
    $regfile = "M8def.dat"
    $crystal = 8000000
    
    $baud = 115200
    
    Dim Mmc_error As Byte
    Dim In_ptr As Word                                          ' Address-Pointer for read
    Dim In_sect As Long
    Dim In_buffer As String * 512
    Print "Wait for Drive"
    '$include "Config_MMC.bas"
             Const Cmmc_soft = 1
    
             #if Cmmc_soft = 0
    
             ' --------- Start of Section for HW-SPI ----------------------------------------
    
                ' define Chip-Select Pin
                Config Pinb.6 = Output                          ' define here Pin for CS of MMC/SD Card
                Mmc_cs Alias Portb.6
                Set Mmc_cs
    
                ' Define here SS Pin of HW-SPI of the CPU (f.e. Pinb.0 on M128)
                ' 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.6 = Output                                   ' define here Pin of SPI SS
                'Spi_ss Alias Portb.6
                '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.0 = Output
                Mmc_cs Alias Portb.0
                Set Mmc_cs
    
                ' MOSI - Pin  => Pin 2 of MMC/SD
                Config Pinb.4 = Output
                Set Pinb.4
                Mmc_portmosi Alias Portb
                Bmmc_mosi Alias 4
    
                ' MISO - Pin  => Pin 7 of MMC/SD
                Config Pinb.3 = Input
                Mmc_portmiso Alias Pinb
                Bmmc_miso Alias 3
    
                ' 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
    
    'Hier werden als Test die ersten 1000 Sektoren der Karte eingelesen und auf den UART ausgegeben.
    In_ptr = Varptr(in_buffer)
    If Gbdriveerror = 0 Then
       Mmc_error = Driveinit()
       If Mmc_error = 0 Then
          Print "Driveinit Ok. "
          For In_sect = 0 To 1000
             Mmc_error = Drivereadsector(in_ptr , In_sect)
             If Mmc_error = 0 Then
                Print "ReadSector(" ; In_sect ; ") ok."         'Zum Inhalt drucken, Kommentare entfernen !!!!!!!!!!
                Print In_buffer                                 'Dann wird es aber langsamer, 115200 baud beim übertragen
             Else
                Print "Error during ReadSector(" ; In_sect ; ") : " ; Mmc_error
             End If
             Mmc_error = Drivewritesector(in_ptr , In_sect)
             If Mmc_error = 0 Then
                Print "WriteSector(" ; In_sect ; ") ok."        'Zum Inhalt drucken, Kommentare entfernen !!!!!!!!!!
                Print In_buffer                                 'Dann wird es aber langsamer, 115200 baud beim übertragen
             Else
                Print "Error during WriteSector(" ; In_sect ; ") : " ; Mmc_error
             End If
          Next In_sect
       Else
          Print "Error during Driveinit(): " ; Mmc_error
       End If
    End If
    
    End
    Und was die Geschwindigkeit betrifft würde es mich schwer wundern, wenn du mit deinen Bascom Befehlen besser dran bist als die Lib Funktionen.

    @Feratu
    Na ja, ob AVR-DOS die kleine, einfache Variante ist, bezweifel ich. Lies dir mal durch, womit all die anderen zu kämpfen hatten, die Files öffnen, Text in bestimmter Formatierung schreiben und File wieder schließen wollten.
    Da ist es sicherlich einfacher, einen Sektor zu beschreiben.

    Gruß

    Rolf

  2. #22
    Erfahrener Benutzer Fleißiges Mitglied
    Registriert seit
    14.01.2008
    Beiträge
    164
    Lib Funktionen.
    ich mag die fertigen lib-funktionen nicht.
    ich möchte es selber proggen, vielleicht mal selber eine lib.

    mfg

  3. #23
    Erfahrener Benutzer Begeisterter Techniker
    Registriert seit
    24.09.2006
    Ort
    Nähe Mannheim
    Beiträge
    269
    mh wohl doch nich ganz so einfach wie ich gehofft hatte.
    Der tiefere sinn der SD Karte soll ja sein eine Textdatei auf der SD Karte mit dem Atmga zu öffnen und einzelne Strings rauszukopieren.
    Sollte ja mit der do it yourself methode funktionieren.

Seite 3 von 3 ErsteErste 123

Berechtigungen

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

Solar Speicher und Akkus Tests