Hi!
   We are trying to write to info-mem. But our program
hangs while erasing sector. Can anyone help?
Best Regards,
Rajat.



Source code:

#include<msp430x14x.h>
#include<math.h>
#include<signal.h>

unsigned char *ucptrSeg1_Address;
unsigned char *ucptrSeg2_Address;
unsigned char ucFIndex;

void vfnWriteData2Flash(unsigned char
*ucptrFlashAddress,
                                                unsigned char *ucptrData,
                                                unsigned char ucNoOfBytes);

volatile unsigned int __attribute__ ((section
(".infomem"))) 
Iarray[20]; 
volatile unsigned char __attribute__ ((section
(".infomem")))
Carray[20];

int main(void)
{
        int num=1;

        vfnWriteData2Flash((unsigned char*)Iarray,(unsigned
char *)&num, (char)sizeof(num));
        
        while(1);

        return(0);
}


void vfnWriteData2Flash(unsigned char
*ucptrFlashAddress,
                                                unsigned char *ucptrData,
                                                unsigned char ucNoOfBytes)
{
          
          dint();  
      
      FCTL2 = FWKEY + FSSEL_1 + FN2 + FN4;  // MCLK IS
SELECTED  
      if(FCTL3 & LOCK)                 
        FCTL3 = FWKEY + (FCTL3 & 0x00ef);   // make
Lock = 0,if it is set
      while(FCTL3 & BUSY);          // wait till BUSY
= 0
    
      // erase SegB
      FCTL1 = FWKEY + ERASE;          // SET Erase bit
      *(unsigned char*)0x1000 = 0x00;
      while(FCTL3 & BUSY);          // wait till BUSY
= 0
        
      // Move all the data in Data segA to Backup segB
      FCTL1 = FWKEY + WRT;          // SET BLKWRT bit
    
      ucptrSeg1_Address = (unsigned char *)0x1080;    

      ucptrSeg2_Address = (unsigned char *)0x1000;
    
      for(ucFIndex=0;ucFIndex < 128;ucFIndex++)       

        *(ucptrSeg2_Address++) =
*(ucptrSeg1_Address++);    

      FCTL1 = FWKEY;    
      while(FCTL3 & BUSY);          // wait till Write
operation is going on

      // erase SegA
      FCTL1 = FWKEY + ERASE;          // SET Erase bit
      *(unsigned char*)0x1080 = 0x00;
      while(FCTL3 & BUSY);          // wait till BUSY
= 0
    
      // move back all the data from SegB from SegA
and change the data 
      FCTL1 = FWKEY + WRT;          // SET BLKWRT bit
    
      ucptrSeg1_Address = (unsigned char *)0x1080;    

      ucptrSeg2_Address = (unsigned char *)0x1000;
    
      for(ucFIndex=0;ucFIndex < 128;ucFIndex++)
      {
       if(ucptrSeg1_Address == ucptrFlashAddress)
        {
          ucNoOfBytes += ucFIndex;
          while(ucFIndex < ucNoOfBytes) 
         { 
          *(ucptrSeg1_Address++) = *(ucptrData++);
          ucFIndex++;
          ucptrSeg2_Address++;
         }
         ucFIndex--;
        }
       else
         *(ucptrSeg1_Address++) =
*(ucptrSeg2_Address++);   
      }

      FCTL1 = FWKEY;    
      while(FCTL3 & BUSY);          // wait till Write
operation is going on
      FCTL3 = FWKEY + LOCK;         // make Lock = 1,
avoiding erase or write 

      eint();  
}


                
__________________________________________________________
How much free photo storage do you get? Store your friends 'n family snaps for 
FREE with Yahoo! Photos http://in.photos.yahoo.com

Reply via email to