• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Microcontrollers » MSP430™ Microcontrollers » MSP430 Ultra-Low Power 16-bit Microcontroller Forum » Writing to SD Card with MSP430G2231
Share
MSP430™ Microcontrollers
  • Forum
  • Announcements
  • E2E Wiki
Options
  • Subscribe via RSS
MSP430 Resources
  • MSP430 Product Folder
  • MSP-EXP430G2 - MSP430 LaunchPad Value Line Development kit
  • MSP430 Getting Started Guide
  • MSP430 Microcontroller Projects
  • More Resources >
  • Writing to SD Card with MSP430G2231

    Writing to SD Card with MSP430G2231

    This question is answered
    MaxE
    Posted by MaxE
    on Aug 21 2012 04:28 AM
    Intellectual385 points

    Hi,

    I am trying to write to a 512 MB Kingston SD card using the MSP430G2231 interfacing the card via SPI.

    The code I use is the slaa281b provided by TI. Now the card initializes correctly and I can write to the card

    but when I look at it in the Hex editor I can´t find the data.

    The MSP430G2231 has just 128 bytes of RAM so I defined a 8 bytes buffer and not like it´s done in the code

    examples a 512 bytes buffer.

    To write a block of 512 bytes I programmed a loop which sends the buffer 64 times to the card.

    Could it be a problem that the buffer isn´t written at once ??

    Or can anyone think of another problem ??

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    All Replies
    • Jens-Michael Gross
      Posted by Jens-Michael Gross
      on Aug 21 2012 10:51 AM
      Guru141810 points

      See my answer in the other SD card thread for your exact same question.

      _____________________________________
      Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.
      If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • MaxE
      Posted by MaxE
      on Aug 22 2012 15:48 PM
      Intellectual385 points

      Hi Jens,

      by now I managed to initialize the SD card with ACMD41.

      To wait a bit longer for the reponse I added a delay_cycles function.

      //Send one byte via SPI
      unsigned short spiSendByte(const unsigned short data)
      {
        while (SPITXREADY ==0);    // wait while not ready for TX
        SPI_SEND(data);            // write
        while (SPIRXREADY ==0);    // wait for RX buffer (full)
        __delay_cycles(1500);
        return (SPIRXBUF);
      }

      The SPIRXREADY I found out is set to 1 by a define and never unset so the code would never wait for

      the buffer to be full I guess.

      So when I send CMD0 and let it run I get 0x01.

      Then I send CMD55 and wait for the reponse and then send ACMD41 and wait for the response.

      This is going on until the card reponds with 0x00 what it does after sending the CMD55, ACMD41

      sequence the second time.

      So the mos recent success is that the card initializes now correctly and I even don´t have to single

      step through the code.

      But I still can`t write anything to the card. The commands for setting blocklength and writing are

      responded correct but the data isn´t on the card when I look at it in my hex editor.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jens-Michael Gross
      Posted by Jens-Michael Gross
      on Aug 23 2012 07:36 AM
      Verified Answer
      Verified by MaxE
      Guru141810 points

      MaxE
      But I still can`t write anything to the card. The commands for setting blocklength and writing are responded correct but the data isn´t on the card when I look at it in my hex editor.

      First, if the card is no SDHC/SDXC card, the address is a byte address. So an address of "0x00000200" writes to segment 1, not segment 512.
      Also, Windows (or whatever OS your hex editor runs on) may fool you about the sector number by adding an offset for some OS-handled formatting stuff in the first sector, depending on how the card has been formatted.

      _____________________________________
      Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.
      If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • MaxE
      Posted by MaxE
      on Aug 24 2012 05:35 AM
      Intellectual385 points

      Ok so if I use the SDWriteBlock like this :

      SDWriteBlock(512ul,512ul,buffer);

      It should write to sector one shouldn´t it ??

      Now I formated the card with FAT16. My OS is Windows 7.

      Do you have a guess at which offset I can expect the data I wanted to write??

      It should be one sector full of ones.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jens-Michael Gross
      Posted by Jens-Michael Gross
      on Aug 24 2012 09:37 AM
      Guru141810 points

      MaxE
      It should write to sector one shouldn´t it ??

      Yes

      MaxE
      Now I formated the card with FAT16. My OS is Windows 7.

      Which has most likely overwritten Sector 1 and maybe reset the whole card content to 0xff except the root directory and the media descriptior parts.

      Better first format the card, then write to a sector that's definitely in the data area. (don't ask me where. It's been a while since I looked at disk sectors for unerasing data)

      _____________________________________
      Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.
      If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • MaxE
      Posted by MaxE
      on Aug 24 2012 10:34 AM
      Intellectual385 points

      Jens-Michael Gross

      Better first format the card, then write to a sector that's definitely in the data area. (don't ask me where. It's been a while since I looked at disk sectors for unerasing data)

      Sorry that I told this a bit confusingly but I actually formated the SD Card before I wrote to it.

      Now I analyzed the whole procedure with a logic analyzer and everything seems to work correct.

      Even I read out the CSD register after the transaction as told by the specs and there are no errors.

      So I guess the data is successfully written to the card. Now the only problem is to find it !!

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • MaxE
      Posted by MaxE
      on Aug 24 2012 14:40 PM
      Intellectual385 points

      Yiiiiiiiiihaaaaaaaaa,

      it works.

      Just experimented a lot with the adressoffset and wrote 1000 sectors on the card.

      Now I found my data.

      Many thanks to you Jens and to Mark Green. You guys gave me such a strong support in the

      last few weeks and guided me to success.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jens-Michael Gross
      Posted by Jens-Michael Gross
      on Aug 27 2012 06:40 AM
      Guru141810 points

      MaxE
      it works.

      Congratulations!

      MaxE
      Now I found my data.

      Where? Onthe card, I suppose, but at which 'windows-filtered storage device' sector? I mean: where did you write it on the MSP and where did it appear under windows?

      _____________________________________
      Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.
      If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • MaxE
      Posted by MaxE
      on Aug 27 2012 15:03 PM
      Intellectual385 points

      I wrote beginning in sector 500 up to sector 1500 and it appeared on the card under windows

      beginning at sector 265. The next thing to do is to implement some functions to write to the fat16

      so when I read out the fat16 boot record maybe I can make more of a guess about

      the adressoffset.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jens-Michael Gross
      Posted by Jens-Michael Gross
      on Aug 28 2012 12:22 PM
      Guru141810 points

      Wow. 235 sectors offset. I wonder what Windows stores in these sectors.
      Or did the hex editor access 'clusters' rather than raw sectors? Then of course this offset contains the FAT.

      There are one or two free FAT file system available for the MSP430. All they need are the low-level functions that read and write a sector - which you now have.
      The links are somewhere her ein the forum (I don't remember - I downlaoded the code but lsot the link)

      _____________________________________
      Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.
      If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    TI E2E™ Community
    • Support Forums
    • Blogs
    • Videos
    • Groups
    • Site Support & Feedback
    • Settings
    TI E2E™ Community Groups
    • TI University Program
    • Make the Switch
    • Microcontroller Projects
    • Motor Drive & Control
    Other Communities
    • Deyisupport
    • Designsomething.org
    • beagleboard.org
    • TI on Element 14
    • TI on TechXchangeSM
    Other Technical & Support Resources
    • WEBENCH® Design Center
    • Product Information Centers
    • Technical Documents
    • TI Design Network
    • TI Technical Articles
    • TI Training

    All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

    Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

    Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
    TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

    TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
    embedded processors, along with software, tools and the industry’s largest sales/support staff.

    © Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
    Trademarks | Privacy Policy | Terms of Use