اطلاعیه

Collapse
No announcement yet.

ایکس مگا و مموری

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    ایکس مگا و مموری

    سلام
    من چند روزه درگیر راه اندازی ایکس مگا و مموری هستم قبلا با atmega از مموری توی پروژه های زیادی استفاده کردم اما ظاهرا ایکس مگا تفاوت زیادی کرده
    توی فروم که سرچ کردم دیدم دوستان چند تا نمونه کد قرار دادن که البته هیچ کدوم برای من کار نکرد یکی از کد ها طاهر فقط با ورژن قدیمی بسکام کار می کرد اما احتیاج به یه فایل لایبرری به اسم MMCSDHCXM0.LIB داشته که این فایل توی لایبرری های من نبود

    اگه ذوستان راه حلی برای این مشکل به نظرتون میاد و یا این فایل داشته باشین ممنون میشم و یه سوال دیگه ام اینه که آیا آخرین ورژن بیسکام مموری رو ساپورت می کنه یا نه؟
    ممنون

    #2
    پاسخ : ایکس مگا و مموری

    سلام
    دوستان مشکلشو بعد از کلی کلنجار رفتن پیدا کردم یه مشکل مسخره کلی وقتمو گرفت ظاهرا کد نمونه بسکام برای ورژن آخریش یعنی 2.0.7.5 درست کار نمی کنه و باید یه تغییر کوچیک بکنه یعنی باید به آخر دستور کانفیگ
    spi در حالت سخت افزاری Ss = AUTO هم اضافه بشه که در واقع به این صورت در می آید کد
    Config Spic = Hard , Master = Yes , Mode = 0 , Clockdiv = Clk2 , Data_order = Msb , Ss = AUTO


    کل کد کانفیگ مموری هم اینجا قرار می دم گه اگه کار کسی مثل خودم بهش گیر کرد راه بیوفته
    تو این کد مموری به پورت C وصل شده یعنی از spi c استفاده شده و برای cs یا همون چیپ سلکت هم از پورت Portb.1 استفاده شده البته این پورت همونظور که می دونین می تونه هر چیزی باشه اما اگه تغییرش دادین باید توی کد زیر هم تغییرش بدین همچنین اگه به یه spi از یه پورت دیگه هم وصل کردین باید باز این کد تغییر بدین

    انشالا که کارتونو راه بندازه موفق باشید


    $nocompile

    '-------------------------------------------------------------------------------
    ' Config_MMCSD_HC.INC
    ' Config File for MMC/SD/SDHC Flash Cards Driver
    ' (c) 2003-2009 , MCS Electronics / V?gel Franz Josef
    '-------------------------------------------------------------------------------
    ' Place MMCSD_HC.LIB in the LIB-Path of BASCOM-AVR installation
    '
    ' you can vary MMC_CS on HW-SPI and all pins on SOFT-SPI, check settings
    '
    ' ========== Start of user definable range =====================================
    '
    ' Declare here you SPI-Mode
    ' using HW-SPI: cMMC_Soft = 0
    Const Hardware_spi = 0
    ' not using HW_SPI: cMMC_Soft = 1
    Const Software_spi = 1

    Const Cmmc_soft = Hardware_spi

    #if Cmmc_soft = 0

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

    'Port D of ATXMEGA is used in this example as SPI Interface to SD-Card

    Portd_pin6ctrl = &B00_011_000 'Enable Pullup for MISO Pin

    ' Define here Slave Slect (SS) Pin of Hardware SPI
    Config Pinb.1 = Output ' define here Pin for CS of MMC/SD Card
    Mmc_cs Alias Portb.1
    Set Mmc_cs

    ' Define here Slave Slect (SS) Pin of Hardware SPI
    ' Config Pinb.1 = Output ' define here Pin of SPI SS
    'Spi_ss Alias Portb.1
    'Set Spi_ss ' Set SPI-SS to Output and High por Proper work of



    'FOR XMEGA DEVICES
    #if _xmega = 1

    'SPI Configuration for XMEGA
    'Used Library = $LIB "MMCSD_HC.LIB"


    'Portd.4 SS --> SD-Card Slave Select
    'Portd.5 MOSI --> SD-Card MISO
    'Portd.6 MISO --> SD-Card MOSI
    'Portd.7 CLK --> SD-Card Clock

    Config Spic = Hard , Master = Yes , Mode = 0 , Clockdiv = Clk2 , Data_order = Msb , Ss = AUTO
    Open "Spic" For Binary As #14
    Const _mmc_spi = Spic_ctrl
    #else

    ' 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
    #endif

    ' --------- 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.1 = Output
    Mmc_cs Alias Portb.1
    Set Mmc_cs

    ' MOSI - Pin => Pin 2 of MMC/SD
    Config Pinc.5 = Output
    Set Pinc.5
    Mmc_portmosi Alias Portc
    Bmmc_mosi Alias 5

    ' MISO - Pin => Pin 7 of MMC/SD
    Config Pinc.6 = Input
    Mmc_portmiso Alias Pinc
    Bmmc_miso Alias 6

    ' SCK - Pin => Pin 1 of MMC/SD
    Config Pinc.7 = Output
    Set Pinc.7
    Mmc_portsck Alias Portc
    Bmmc_sck Alias 7

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

    #endif

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


    '==== Variables For Application ================================================
    Dim Mmcsd_cardtype As Byte ' Information about the type of the Card
    ' 0 can't init the Card
    ' 1 MMC
    ' 2 SDSC Spec. 1.x
    ' 4 SDSC Spec. 2.0 or later
    ' 12 SDHC Spec. 2.0 or later

    Dim Gbdriveerror As Byte ' General Driver Error register
    ' Values see Error-Codes
    '============================================ ===================================



    ' ==== Variables for Debug ================================================== ===
    ' You can remove remarks(&#039 if you want check this variables in your application
    Dim Gbdrivestatusreg As Byte ' Driver save here Card response
    ' Dim gbDriveErrorReg as Byte at GbdriveStatusReg overlay '
    ' Dim gbDriveLastCommand as Byte ' Driver save here Last Command to Card
    Dim Gbdrivedebug As Byte
    ' Dim MMCSD_Try As Byte ' how often driver tried to initialized the card
    '============================================ ===================================


    '==== Driver internal variables ================================================
    ' You can remove remarks(&#039 if you want check this variables in your application
    ' Dim _mmcsd_timer1 As Word
    ' Dim _mmcsd_timer2 As Word
    '============================================ ===================================



    ' Error-Codes
    Const Cperrdrivenotpresent = &HE0
    Const Cperrdrivenotsupported = &HE1
    Const Cperrdrivenotinitialized = &HE2

    Const Cperrdrivecmdnotaccepted = &HE6
    Const Cperrdrivenodata = &HE7

    Const Cperrdriveinit1 = &HE9
    Const Cperrdriveinit2 = &HEA
    Const Cperrdriveinit3 = &HEB
    Const Cperrdriveinit4 = &HEC
    Const Cperrdriveinit5 = &HED
    Const Cperrdriveinit6 = &HEE

    Const Cperrdriveread1 = &HF1
    Const Cperrdriveread2 = &HF2

    Const Cperrdrivewrite1 = &HF5
    Const Cperrdrivewrite2 = &HF6
    Const Cperrdrivewrite3 = &HF7
    Const Cperrdrivewrite4 = &HF8



    $lib "MMCSD_HC.LIB"
    $external _mmc
    ' Init the Card
    Gbdriveerror = Driveinit()


    ' you can remark/remove following two Code-lines, if you dont't use MMCSD_GetSize()
    $external Mmcsd_getsize
    Declare Function Mmcsd_getsize() As Long


    ' you can remark/remove following two Code-lines, if you dont't use MMCSD_GetCSD()
    ' write result of function to an array of 16 Bytes
    $external Mmcsd_getcsd
    Declare Function Mmcsd_getcsd() As Byte


    ' you can remark/remove following two Code-lines, if you dont't use MMCSD_GetCID()
    ' write result of function to an array of 16 Bytes
    $external Mmcsd_getcid
    Declare Function Mmcsd_getcid() As Byte


    ' you can remark/remove following two Code-lines, if you dont't use MMCSD_GetOCR()
    ' write result of function to an array of 4 Bytes
    $external Mmcsd_getocr
    Declare Function Mmcsd_getocr() As Byte


    ' you can remark/remove following two Code-lines, if you dont't use MMCSD_GetSDStat
    ' write result of function to an array of 64 Bytes
    $external Sd_getsd_status
    Declare Function Sd_getsd_status() As Byte

    ' check the usage of the above functions in the sample MMCSD_Analysis.bas
    ' check also the MMC and SD Specification for the content of the registers CSD, CID, OCR and SDStat





    دیدگاه

    لطفا صبر کنید...
    X