⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sst25vf020.c

📁 EP9315的wince下载程序。download.exe
💻 C
📖 第 1 页 / 共 2 页
字号:
    //    
    sst25vf020_transaction( tBuffer, rBuffer, 1);

    //
    // Send the write command to status register
    //
    tBuffer[0] = SST25VF020_WRITE_STATUS_REGISTER; 
    tBuffer[1] = 0;
    
    //
    // Finish the phase of writing status register
    //  
    sst25vf020_transaction( tBuffer, rBuffer, 2);
 
    //
    // Send the write_enable command to status register
    //
    tBuffer[0] = SST25VF020_WRITE_ENABLE;  
    
    //
    // Finish the phase of writing enable command
    //  
    sst25vf020_transaction( tBuffer, rBuffer, 1);

    //
    // Send the sector_erase command and the address to eeprom 
    //
    tBuffer[0] = SST25VF020_SECTOR_ERASE;
    tBuffer[1] = addr >> 16;
    tBuffer[2] = addr >> 8;
    tBuffer[3] = addr;
    
    //
    // Finish the phase of writing sector_erase command
    //  
    sst25vf020_transaction( tBuffer, rBuffer, 4);

    //
    // Get the ready status of status register
    //
    while( !sst25vf020_get_ready() )
    {
        delay_usec(1);
    }
		
    } 
     
    return 1;

}
//-----------------------------------------------------------------------------
// program_sst25vf020 chip write
//-----------------------------------------------------------------------------
int program_sst25vf020(unsigned int addr, unsigned char *pBuffer, int length)
{
    int  wlen;
    int i;
    unsigned char tBuffer[8];
    unsigned char rBuffer[8];
    volatile unsigned char * pData;
    unsigned long pulTest;
        
    addr &= 0x3ffff;
    pData = pBuffer;
    
    wlen = length;
    i=0;

    while(length > 0)
    {			
    //
    // Send the write_enable command to status register
    // 			
    tBuffer[0] = SST25VF020_WRITE_ENABLE;
       
    //
    // Finish the phase of writing enable command
    //  
    sst25vf020_transaction( tBuffer, rBuffer, 1);
    
    //
    // Send byte_program command and the address to eeprom
    // 
    tBuffer[0] = SST25VF020_BYTE_PROGRAM;
    tBuffer[1] = (addr >> 16) & 0xFF;
    tBuffer[2] = (addr >> 8) & 0xFF;
    tBuffer[3] =  addr & 0x0FF;
       
    //
    // Write the byte to eeprom
    // 
    tBuffer[4] =  pData[i++];
        
    //
    // Finish the phase of writing the datas to eeprom
    //     
    sst25vf020_transaction( tBuffer, rBuffer, 5);

    delay_usec(5);
    
    //
    // Get the ready status of status register
    //
    while( !sst25vf020_get_ready() )
    {
        delay_usec(1);
    }
        
    delay_usec(5);
        
    //
    //Read-back verification
    // 
    pulTest = read_sst25vf020(addr,(unsigned char *)(0),4);        
    if((pulTest&0xff)!= pData[i-1])
    {
    	return -1;
    }    
    //
    // Decrease the length of the buffer that will be sent 
    // and increase the address of the eeprom
    //
    length -= 1;
    addr   += 1;
    }

    return wlen;
  
}

unsigned long read_sst25vf020(unsigned int start, unsigned char *pBuffer, int numBytes)
{
	
    unsigned long ulRet, ulTemp;
    //unsigned long count=0;
  
    unsigned long ulOffset = start;
  
 
  
    out(SSP1DR,0x03);
    out(SSP1DR, (ulOffset >>16) & 255);
    out(SSP1DR, (ulOffset >>8) & 255);
    out(SSP1DR,  ulOffset & 255);
    
    do{
      ulTemp = in(SSP1SR);
    } while(!(ulTemp & 0x04));
     ulTemp = in(SSP1DR);
     
     out(SSP1DR,0x00);
     out(SSP1DR,0x00);
     out(SSP1DR,0x00);
     out(SSP1DR,0x00);
     
     do{ 
     	 ulTemp = in(SSP1SR);
     } while(!(ulTemp & 0x04));
       ulTemp = in(SSP1DR);
     
     do{ 
     	ulTemp = in(SSP1SR);
     } while(!(ulTemp & 0x04));
       ulTemp = in(SSP1DR);
     
     do{ 
     	 ulTemp =in(SSP1SR);
     }while (!(ulTemp & 0x04));
      ulTemp = in(SSP1DR);
     
      do{
     	ulTemp =in(SSP1SR);
     } while(!(ulTemp & 0x04));
       ulRet = in(SSP1DR);
     
     do{
        ulTemp = in(SSP1SR);
      } while(!(ulTemp & 0x04));
       ulTemp = in(SSP1DR);
       ulRet |= ulTemp<<8;
       
      do{
         ulTemp = in(SSP1SR);
        } while(!(ulTemp & 0x04));
          ulTemp = in(SSP1DR);
          ulRet |= ulTemp<<16;
      
      do{
         ulTemp = in(SSP1SR);
        } while(!(ulTemp & 0x04));
          ulTemp = in(SSP1DR);
          ulRet |= ulTemp <<24;
          
       do{ 
          ulTemp = in(SSP1SR);
        } while(!(ulTemp & 0x01));
        
        
        do{ 
           ulTemp = in(SSP1SR);
           if(ulTemp & 0x04)
             ulTemp = in(SSP1DR);
        } while (ulTemp & 0x04);
        
        return ulRet;
  
  
 /*
   do
   {
    
    out(SSP1DR,0x03);
    out(SSP1DR, (start >>16) & 255);
    out(SSP1DR, (start >>8) & 255);
    out(SSP1DR, (start & 255));
       
    ulTemp = in(SSP1DR);
   
    out(SSP1DR,0x00);
    out(SSP1DR,0x00);
    out(SSP1DR,0x00);
    out(SSP1DR,0x00);
    
    while(!(in(SSP1SR) & 0x04));
    ulTemp = in(SSP1DR);
    
    while(!(in(SSP1SR) & 0x04));
    ulTemp = in(SSP1DR);
    
    while(!(in(SSP1SR) & 0x04));
    ulTemp = in(SSP1DR);

    
    
    for(i=0; (i < 4) & (count < numBytes); i++)
        {
            while(!(in(SSP1SR) & 0x04));
            pBuffer[count]=(unsigned char)in(SSP1DR);
            count++;
        }
  //  while(!(in(SSP1SR) & 0x04));
  //  ulRet = in(SSP1DR);
  //  while(!(in(SSP1SR) & 0x04));
  //  ulRet |=in(SSP1DR) << 8;
  //  while(!(in(SSP1SR) & 0x04));
  //  ulRet |=in(SSP1DR) <<16;
  //  while(!(in(SSP1SR) & 0x04));
  //  ulRet |=in(SSP1DR) <<24;
       
    while(!in(SSP1SR) & 0x01);
   
   do {
         ulTemp = in(SSP1SR);
        if (ulTemp & 0x04)
            ulTemp = in(SSP1DR);
    } while (ulTemp & 0x04);
    
} while (count < numBytes); 
    
     return numBytes;

 	
 */
 
 /*
 
    int i=0, temp;
    int delay;

    
    while(SSP1->SSPSR.Field.TFE == 0);
    while(SSP1->SSPSR.Field.RNE == 1)
    {
        temp = SSP1->SSPDR.Value;
    }                    

    
    start &= 0x1ffff;

    
    do
    {

        SSP1->SSPDR.Value = CMD_READ_DATA; //| ((start & 0x100) >> 5);
        
  
        
      //  SSP1->SSPDR.Value = 0;
        SSP1->SSPDR.Value = start>>16;
        SSP1->SSPDR.Value = start>>8;
        SSP1->SSPDR.Value = start;
        
        temp = SSP1->SSPDR.Value;
        
        SSP1->SSPDR.Value = 0x00;
        SSP1->SSPDR.Value = 0x00;
        SSP1->SSPDR.Value = 0x00;
        SSP1->SSPDR.Value = 0x00;
        
        temp = SSP1->SSPDR.Value;
        temp = SSP1->SSPDR.Value;
        temp = SSP1->SSPDR.Value;
        

        while(SSP1->SSPSR.Field.TFE == 0);

        
   //     while(SSP1->SSPSR.Field.RNE == 1)               // Throw away unwanted values
      //  while(!SSP1->SSPSR.Field.RNE);
     //   {                                               // Keep only the last one
    //        pBuffer[i] =(unsigned char)SSP1->SSPDR.Value;
       //     for(delay=10;delay >0; delay--);
         
     //   }
        for(i=0; (i < 4) & (count < numBytes); i++)
        {
            while(!(in(SSP1SR) & 0x04));
            pBuffer[count]=(unsigned char)SSP1->SSPDR.Value;
            count++;
        }
        
        start +=4;
                                  
                                    
   //     for(delay=64;delay >0; delay--);
       
    } while(count < numBytes);

 //   for(delay=64;delay >0; delay--);
    
   

    return(numBytes);
 
 
 */
 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -