• 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 » Problem in Reading from Flash Memory Location
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 >
  • Problem in Reading from Flash Memory Location

    Problem in Reading from Flash Memory Location

    This question is not answered
    Priyanka Dhomne
    Posted by Priyanka Dhomne
    on Aug 16 2012 08:25 AM
    Intellectual365 points

    I am working on MSP430F5438, I am facing some problems in reading from flash memory location ,I have to write data continousouly on flash and after that read it from flash memory ,If i Read -Write 4 byte at one location of Flash it  is Working Properly  , Pls go through code given Below and Solve my Problems ,Where I mistaken ,Thankyou .

    unsigned long BUF[ ] = {0X10000,0X20000};

    unsigned long *Flash_ptr = BUF;

    unsigned long Flash_ptr_start = 0X10000;  

    /**** write value into flash Memory****/

    void flash_write_val()
    {
    char temp[5];

    while (FCTL3 & BUSY);                                      // Check if Flash being used
    FCTL3 = FWKEY;
    FCTL1 = FWKEY+BLKWRT;                               // Enable long-word write

    (*(unsigned long *)Flash_ptr) = rec_long;        // Write to Flash

    check = (*(unsigned long *)Flash_ptr); 


    temp[0] = check ; //LSB
    temp[1] = (check >> 8) ;
    temp[2] = (check >> 16);
    temp[3] = (check >> 24);
    temp[4] = '\0';


    halLcdPrintLine("valwrt2flash..",4,OVERWRITE_TEXT);          // Here we get Value which is Written into Flash Mem Location
    halLcdPrintLine(temp,5,OVERWRITE_TEXT);

    Flash_ptr++;                                                                                    // Increment Flash mem location to read val frm next location
    while (FCTL3 & BUSY );                                                                 // Check if Flash being used
    FCTL1 = FWKEY;                                                                             // Clear WRT bit
    FCTL3 = FWKEY+LOCK;                                                                // Set LOCK bit
    }

    /****Read  value from flash Memory****/

    void flash_read_val()
    {
             char temp[5];

              // unsigned long *Flash_ptr_start = BUF;                          // if i set flash_ptr_start value equal to directly buffer it will not go into the loop why ??
             unsigned long Flash_end = 0X10001;

             while( Flash_ptr_start < 0X10001 )
           {
                 P1OUT |= LED2;
                Flash_data = 0;
                Flash_data = *(unsigned long *)Flash_ptr_start;

                 P1OUT &= ~LED2;

                   temp[0] = Flash_data ; //LSB
                   temp[1] = (Flash_data >> 8) ;
                   temp[2] = (Flash_data >> 16);
                    temp[3] = (Flash_data >> 24);
                     temp[4] = '\0';

                halLcdPrintLine("valrd frm flash..",6,OVERWRITE_TEXT);          // while reading from same memory location i get result zero why ????
                halLcdPrintLine(temp,7,OVERWRITE_TEXT);
                 Flash_ptr_start++; 

               delay(500);
        }
    }

    /*******************************************UART*************************************/

    #pragma vector=USCI_A1_VECTOR
    __interrupt void USCI_A1_ISR (void)
    {


    UartReceiveBuffer[bufferSize++] = UCA1RXBUF;

    }

    void main()

    {

    flashEraseBank(BUF[0]);

    if( bufferSize > 3 )
    {
    send_XOFF();

    //P1OUT |= LED2; // LED1 ON
    rec_long   =  UartReceiveBuffer [ 0 ];
    rec_long   =  (rec_long << 8) | UartReceiveBuffer[ 1 ];
    rec_long   =  (rec_long << 8) | UartReceiveBuffer[ 2 ];
    rec_long   =  (rec_long << 8) | UartReceiveBuffer[ 3 ];

    bufferSize = 0;

    send_XON ();

    }

    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 17 2012 09:10 AM
      Guru140650 points

      Priyanka Dhomne
      unsigned long Flash_ptr_start = 0X10000;  

      Priyanka Dhomne
              // unsigned long *Flash_ptr_start = BUF;

      You have two different definitions of Flash_ptr_start.

      The global one is a long int variable, the one define din the function is a pointer variable that points to a long int value.

      If you use the pointer definition inside your funciton, it will shadow the global long int variable (don't ou get a compiler warning about this?).

      You're going through some implicit typecasting here.

      _____________________________________
      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.
    • Priyanka Dhomne
      Posted by Priyanka Dhomne
      on Aug 19 2012 23:53 PM
      Intellectual365 points

      unsigned long *Flash_ptr_start = BUF;        

      This assignment is commented in code...........i had not used in this code.only global one is used.

      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 20 2012 13:51 PM
      Guru140650 points

      Priyanka Dhomne
      This assignment is commented in code...........i had not used in this code.only global one is used.

      I interpreted the comment behind this line and your initial description that it works with one and not with the other (e.g. one version has it commented, the other one not).

      If you give an either/or description of the problem ("If I..." implies that it works if you don't), you should also give the two different code versions. I assumed that this comment was the difference.

      _____________________________________
      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.
    • Priyanka Dhomne
      Posted by Priyanka Dhomne
      on Aug 21 2012 00:21 AM
      Intellectual365 points

      k.......... i tell you what whole problem is .

      In code when we intialize  unsigned long *Flash_ptr = BUF; (it will point to first mem location  0x10000 ), Writing into Flash is Proper ,while Reading from Flash it will not into loop itself ?

      unsigned long BUF[ ] = {0X10000,0X20000};

      unsigned long *Flash_ptr = BUF;

      unsigned long Flash_ptr_start = 0X10000;  

      /**** write value into flash Memory****/

      void flash_write_val()
      { 
      char temp[5];

      while (FCTL3 & BUSY);                                      // Check if Flash being used
      FCTL3 = FWKEY; 
      FCTL1 = FWKEY+BLKWRT;                               // Enable long-word write

      (*(unsigned long *)Flash_ptr) = rec_long;        // Write to Flash

      check = (*(unsigned long *)Flash_ptr); 


      temp[0] = check ; //LSB
      temp[1] = (check >> 8) ;
      temp[2] = (check >> 16);
      temp[3] = (check >> 24);
      temp[4] = '\0';


      halLcdPrintLine("valwrt2flash..",4,OVERWRITE_TEXT);          // Here we get Value which is Written into Flash Mem Location
      halLcdPrintLine(temp,5,OVERWRITE_TEXT);

      Flash_ptr++;                                                                                    // Increment Flash mem location to read val frm next location
      while (FCTL3 & BUSY );                                                                 // Check if Flash being used
      FCTL1 = FWKEY;                                                                             // Clear WRT bit
      FCTL3 = FWKEY+LOCK;                                                                // Set LOCK bit
      }

      /****Read  value from flash Memory****/

      void flash_read_val()
      { 
               char temp[5];

                // unsigned long *Flash_ptr_start = BUF;                          // if i set flash_ptr_start value equal to directly buffer it will not go into the loop why ??
               unsigned long Flash_end = 0X10001;

               while( Flash_ptr_start < 0X10001 )
             {
                   P1OUT |= LED2;
                  Flash_data = 0;
                  Flash_data = *(unsigned long *)Flash_ptr_start;

                   P1OUT &= ~LED2;

                     temp[0] = Flash_data ; //LSB
                     temp[1] = (Flash_data >> 8) ;
                     temp[2] = (Flash_data >> 16);
                      temp[3] = (Flash_data >> 24);
                       temp[4] = '\0';

                  halLcdPrintLine("valrd frm flash..",6,OVERWRITE_TEXT);          // while reading from same memory location i get result zero why ????
                  halLcdPrintLine(temp,7,OVERWRITE_TEXT);
                   Flash_ptr_start++; 

                 delay(500);
          }
      }

       This code is not worked thats why i tried and   initalize   unsigned long *Flash_ptr = 0X10000(Directly pointing to memory location);  In this Case it will go into the loop but give output zero.

      Is problem in this code wrt  pointer increment ,while incrementing it is not pointing to another location(0X10001),I Hope you Understand my Problem ,Thank You 

      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 21 2012 07:51 AM
      Guru140650 points

      Okay, I see some oddities...

      1) the loop is controlled by Flash_ptr_start, so it makes no difference where Flash_ptr points to.

      2) I'm not sure whether your constants are right. Ic you write 0x10000, this is an int, not a long int, and migh tbe truncated to 0x0000 by the parser before it is assigned. Try using 0x10000L instead. I'm not sure what the C standard and teh compiler docu tells about long integer constants, but IIRC, some past problems in this forum were solved by adding the long modifier to the constant.
      If this is the case, then 0x10000 truncates to 0x0000, which is smaller than (0x10001 truncated to) 0x0001 in the if. However, BUF is > 0x0001 and won't enter the loop.

      3) (usigned long *)Flash_ptr_start may result in a 16 bit pointer if you don't use large data model. In small data model (the default), data pointers are 16 bit only, so the cast truncates the value of Flash_ptr_start and you're reading from address 0x00000 instead of 0x10000.

      _____________________________________
      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.
    • Priyanka Dhomne
      Posted by Priyanka Dhomne
      on Aug 22 2012 05:20 AM
      Intellectual365 points

      2) I'm not sure whether your constants are right. Ic you write 0x10000, this is an int, not a long int, and migh tbe truncated to 0x0000 by the parser before it is assigned. Try using 0x10000L instead. I'm not sure what the C standard and teh compiler docu tells about long integer constants, but IIRC, some past problems in this forum were solved by adding the long modifier to the constant.
      If this is the case, then 0x10000 truncates to 0x0000, which is smaller than (0x10001 truncated to) 0x0001 in the if. However, BUF is > 0x0001 and won't enter the loop

      I Tried to run my Code using 0x10000L ,Still not going  into the Loop.I understand that what you are trying to tell me that pointer is points not pointing to 0x10000 ,but it will point to 0x0000 .

      Do you have any code Examples  Regarding Flash Read  Write,Which would help me for reading and writing large amount of data from flash.


      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 22 2012 08:32 AM
      Guru140650 points

      Priyanka Dhomne
      Do you have any code Examples  Regarding Flash Read  Write,Which would help me for reading and writing large amount of data from flash.

      Sorry, my flash writing code is hand-crafted assembly for MSPGCC.

      However, I suggest starting writing to the info memory area below 64k first. If this works, you can go and extend the code for >64k memory.

      _____________________________________
      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