Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

SD Card Speed Clock

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
mansur

Bascom Member



Joined: 21 Feb 2013
Posts: 29
Location: Jakarta

indonesia.gif
PostPosted: Wed May 16, 2018 2:27 am    Post subject: SD Card Speed Clock Reply with quote

Dear All,
How many the maximum speed if we use atxmega to write the uSD Card (class 6) with logic converter (3v3 level). we want to use the pll clock until 48 MHZ or 64MHZ.
Yesterday i try to write the uSD card with logic converter with crystal set=32 MHZ and SPI clock CLK2 the result is success, but i try to edit and change the main clock to 48 MHZ, the uSD card not respons if CLK2, i'ts mean the logic converter not match with this clock.
any body already try without logic converter and pll clock?

(BASCOM-AVR version : 2.0.8.1 , Latest : 2.0.8.1 )

_________________
Mansur. H
Automation & Instrument Engineer
Back to top
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2071

netherlands.gif
PostPosted: Wed May 16, 2018 1:02 pm    Post subject: Reply with quote

Max default clock speed for a sd card is 48Mhz.
If you power up an sd-card it will always work on 3.3V, 1 bit bus and max. 45mhz clock. This to make all the new fast cards downwards compatible.
If you want a higher clock speed, lower voltage (1.8V) or change bus width you have to negotiate with the card to change the settings. Ask the card what he (or she) is capable of and then change the settings.

I did it in C, but never in Bascom. Hope you can find some examples else it's a long way to go.

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
mansur

Bascom Member



Joined: 21 Feb 2013
Posts: 29
Location: Jakarta

indonesia.gif
PostPosted: Tue May 22, 2018 5:24 am    Post subject: Reply with quote

[quote=\"Evert Smile\"]Max default clock speed for a sd card is 48Mhz.
If you power up an sd-card it will always work on 3.3V, 1 bit bus and max. 45mhz clock. This to make all the new fast cards downwards compatible.
If you want a higher clock speed, lower voltage (1.8V) or change bus width you have to negotiate with the card to change the settings. Ask the card what he (or she) is capable of and then change the settings.

I did it in C, but never in Bascom. Hope you can find some examples else it\'s a long way to go.[/quote]

Hi evert,
thanks for your advice, i will try to replace the logic converter for sd card.

_________________
Mansur. H
Automation & Instrument Engineer
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 551

poland.gif
PostPosted: Tue May 22, 2018 1:56 pm    Post subject: Reply with quote

With Xmega you dont need the level converter. Xmega 3.3V ... SDCard 3.3V
To the Xmega I always link SDCard directly.
Back to top
View user's profile Visit poster's website
mansur

Bascom Member



Joined: 21 Feb 2013
Posts: 29
Location: Jakarta

indonesia.gif
PostPosted: Tue Jun 05, 2018 6:27 am    Post subject: Reply with quote

EDC wrote:
With Xmega you dont need the level converter. Xmega 3.3V ... SDCard 3.3V
To the Xmega I always link SDCard directly.


Dear All,

Code:

The xmega with clock PLL to 48 MHZ success to write and read the SD card with class 10 capacity 32GB, the SPI clock prescaler set to CLK2.
$regfile = "xm32A4def.dat"
$crystal = 48000000                                         ' frequency used
$hwstack = 200
$swstack = 200
$framesize = 200


Config Osc = Enabled , 32mhzosc = Enabled , 32khzosc = Enabled       ', 32khzosc = Enabled       'Enable the 32MHz and 32.768KHz Oscillator

Bitwait Osc_status.1 , Set                                  'Check if 32MHz Oscillator is ready
Bitwait Osc_status.2 , Set                                  'Check if internal 32.768 KHz Oscillator is ready

'Init and enable the DFLL (Digital Frequency Locked Loop) for automatic run-time calibration of the internal 32MHz Oscillator

Osc_dfllctrl = &B00000000                                   'The internal 32.768 KHz Oscillator is used for calibration
Set Dfllrc32m_ctrl.0                                        'Enable DFLL and autocalibration


'Set the Multiplication factor and select the clock Reference for the PLL
Osc_pllctrl = &B10_0_00110                                  ' 32MHz clock Source and Multiplication factor = 16
                '^    '^
                '^    'Multiplication factor = 8
                '^
                'PLL Source = 32MHz internal Oscillator (divided by 4 in hardware)
Set Osc_ctrl.4                                              ' PLL enable
Bitwait Osc_status.4 , Set                                  'Check if PLL is ready
Config Sysclock = pll , Prescalea = 1 , Prescalebc = 1_1  ' configure the systemclock ---> use PLL
Waitms 2
'config twic=1000
Const Ds3231w = &HD0                                        ' Addresses of Ds1307 clock
Const Ds3231r = &HD1
'(i2cinit
Dim Twi_start As Byte
Config Clock = User                                         ' this will dim the bytes automatic
config date=DMY, separator=slash
'dim other needed variables
Dim Weekday As Byte
'Time$ = "07:58:00"                                          ' to watch the day changing value
'Date$ = "14-05-18"
')

Config Com1 = 500000 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Config Priority = Static , Vector = Application , Lo = Enabled       'config interrupts
Enable Interrupts

'$include "CONFIG_AVR-DOS.bas"
$include "Config_MMCSD_HC.bas"


'=====[ Global Vars ]==========================================================
Dim Btemp1 As Byte                                         ' Needed for Fat Drivers
Dim Input_string As String * 100
Dim Output_string As String * 100
Dim File_handle As Byte
Dim File_name As String * 14
Dim X As Long

'Btemp1 = Initfilesystem(1)

Print "Starting... SDHC with ATXMEGA...."
'Print

'------------------------------------------------------------------------------

'=====[ Includes ]============================================================


'$include "config_MMCSD_HC.inc"

Print "SD Card Type = " ;
Select Case Mmcsd_cardtype
Case 0 : Print "can't init the Card"
Case 1 : Print "MMC"
Case 2 : Print "SDSC Spec. 1.x "
Case 4 : Print "SDSC Spec. 2.0 or later"
Case 12 : Print "SDHC Spec. 2.0 or later"
End Select

'Print


If Gbdriveerror = 0 Then                                   'from.... Gbdriveerror = Driveinit()
  $include "Config_AVR-DOS.bas"                           ' Include AVR-DOS Configuration and library


  Print "Init File System ... " ;
  Btemp1 = Initfilesystem(1)                               ' Reads the Master boot record and the partition boot record (Sector) from the flash card and initializes the file system
                                                  '1 = Partitionnumber
  If Btemp1 <> 0 Then
    Print "Error: " ; Btemp1 ; " at Init file system"
  Else
    Print " OK  --> Btemp1= " ; Btemp1 ; " / Gbdriveerror = " ; Gbdriveerror
    Print "Filesystem = " ; Gbfilesystem
    Print "FAT Start Sector: " ; Glfatfirstsector
    Print "Root Start Sector: " ; Glrootfirstsector
    Print "Data First Sector: " ; Gldatafirstsector
    Print "Max. Cluster Nummber: " ; Glmaxclusternumber
    Print "Sectors per Cluster: " ; Gbsectorspercluster
    Print "Root Entries: " ; Gwrootentries
    Print "Sectors per FAT: " ; Glsectorsperfat
    Print "Number of FATs: " ; Gbnumberoffats
  End If

  Print
  Print

    '-------------------------------------------------------------------------
    ' Write Text to file
     File_handle = Freefile()                             ' get a file handle
     File_name = "My_file.txt"
    Open File_name For Output As #file_handle             ' open file for output with file_handle
    ' If the file exist already, the file will be overwritten !
    Print #file_handle , "This is my 1 first Text to File with XMEGA !"
    Close #file_handle

    Print "Write to file done !"

    '-------------------------------------------------------------------------
    'Now we want to read back the text we wrote to file and print it over Serial Interface
     File_handle = Freefile()
    Open "My_file.txt" For Input As #file_handle         ' we can use a constant for the file too
    Print "File length = " ; Lof(#file_handle)
    Line Input #file_handle , Input_string               ' read a line
    Print Input_string                               'print the line
    Close #file_handle




      'WRITE TO FILE
    Print "write to file"
    File_name = "Test.txt"
    Input_string = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"


    Open File_name For Output As #10

      While X < 10000                                     '10000 * 102 Byte / 100 = 10200 Byte
          Print #10 , Input_string
          X = X + 100
      Wend

    Close #10


     X = Filelen(file_name)
    Print "Total bytes written: " ; X



    'READ FROM FILE

    Open File_name For Input As #10
      While Eof(#10) = 0
        Line Input #10 , Output_string                     ' read a line
        If Input_string <> Output_string Then
          Print "Buffer Error! near byte: " ; X ; "   " ; "[" ; Output_string ; "]"
          else
          print "Good Data" ;; "[" ; Output_string ; "]"
          'Waitms 2000
        End If
    Wend
    Close #10


    Print "Write and Readback test done !"



    '-------------------------------------------------------------------------
    'Print the file name which was created before
    Print "Dir function demo"
     Input_string = Dir( "*.*")
    'The first call to the DIR() function must contain a file mask The * means everything.
    ' Print File Names
    While Len(input_string) > 0                           ' if there was a file found
        Print Input_string ; "  " ; Filedate() ; "  " ; Filetime() ; "  " ; Filelen()
      '   print file , the date the fime was created/changed , the time and the size of the file
        Input_string = Dir()                               ' get next
    Wend

    '-------------------------------------------------------------------------

    'Print
    'Print "Diskfree = " ; Diskfree()
    'Print "Disksize = " ; Disksize()

    'Print "Date Time : " ; Date$ ; " " ; Time$

End If                                                     'If Gbdriveerror = 0 Then


End

'(Getdatetime:
  I2cstart                                                  ' Generate start code
  I2cwbyte Ds3231w                                          ' send address
  I2cwbyte 0                                                ' start address in 1307

  I2cstart                                                  ' Generate start code
  I2cwbyte Ds3231r                                          ' send address
  I2crbyte _sec , Ack
  I2crbyte _min , Ack                                       ' MINUTES
  I2crbyte _hour , Ack                                      ' Hours
  I2crbyte Weekday , Ack                                    ' Day of Week
  I2crbyte _day , Ack                                       ' Day of Month
  I2crbyte _month , Ack                                     ' Month of Year
  I2crbyte _year , Nack                                     ' Year
  I2cstop
  _sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
  _day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year)
Return

Setdate:
  _day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year)
  I2cstart                                                  ' Generate start code
  I2cwbyte Ds3231w                                          ' send address
  I2cwbyte 4                                                ' starting address in 1307
  I2cwbyte _day                                             ' Send Data to SECONDS
  I2cwbyte _month                                           ' MINUTES
  I2cwbyte _year                                            ' Hours
  I2cstop
Return

Settime:
  _sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
  I2cstart                                                  ' Generate start code
  I2cwbyte Ds3231w                                          ' send address
  I2cwbyte 0                                                ' starting address in 1307
  I2cwbyte _sec                                             ' Send Data to SECONDS
  I2cwbyte _min                                             ' MINUTES
  I2cwbyte _hour                                            ' Hours
  I2cstop
Return
 


_________________
Mansur. H
Automation & Instrument Engineer
Back to top
View user's profile
mansur

Bascom Member



Joined: 21 Feb 2013
Posts: 29
Location: Jakarta

indonesia.gif
PostPosted: Wed Jul 25, 2018 10:35 am    Post subject: solved Reply with quote

i have tried for xmega256a3u with pll clock upto 72mhz.
the prescale of spi for sd card is clk2 for sd card 32gb class 10.
the read and write success. but if increase the clock over 72mhz is not able to read. class 10 has speed limit.
i this 72 mhz is more fast enough.

_________________
Mansur. H
Automation & Instrument Engineer
Back to top
View user's profile
mmarlette

Bascom Member



Joined: 30 Nov 2007
Posts: 296
Location: Delano, MN

usa.gif
PostPosted: Thu Aug 09, 2018 8:44 pm    Post subject: Reply with quote

This is an interesting example.

Quick look it appears that you are running in SPI divide by 4 mode. So 72/4=18MHZ SPI Clk

My understanding is that the max SPI clock rate is 25MHZ. So it must be a board layout or maybe you are using wires to connect to the SPI bus to the SD card?

Also read somewhere you must init at a lower rate, determine card speed and then increase clk accordingly. Not sure about this as I haven't seen it in the spec yet.

I am going to look in to this a bit more with my Xmega.

Thanks for sharing.

Regards,

Mark
Back to top
View user's profile
mmarlette

Bascom Member



Joined: 30 Nov 2007
Posts: 296
Location: Delano, MN

usa.gif
PostPosted: Wed Sep 26, 2018 9:18 pm    Post subject: Reply with quote

Finally got back to this to run some test with this and no problem at 24MHZ SPI SCK.

Here are some pictures from the verification process.





Back to top
View user's profile
mmarlette

Bascom Member



Joined: 30 Nov 2007
Posts: 296
Location: Delano, MN

usa.gif
PostPosted: Wed Sep 26, 2018 9:58 pm    Post subject: Reply with quote

Same test software, re-targeted to the Ardunio M2560 board and IDE/ATA/SATA interface defined this time.

This board has a 16MHZ sysclock and the SPI is at /2 or 8MHZ.

The test drive is a Samsung EVO 860 256GB uSATA drive. This thing is SMOK'IN FAST!!!!

Need to make a level translator to do IDE/ATA/SATA on the Xmega, so that test is next.

Hoping to get almost 2MBs there...... Smile

Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum