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

📄 flashmemory.c

📁 LM3S8962 通过SSI方式读取 AT45DB161D 程序
💻 C
字号:
#include  "Heads.h"
#include  "FlashMemory.h"

uint8 kkk[528];


void  SPIInit(void)
{
    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI);                           
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SSIConfig(SSI_BASE, SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, BitRate, DataWidth);
    SSIEnable(SSI_BASE);                                                
  
    GPIOPinTypeSSI( GPIO_PORTA_BASE, (GPIO_PIN_2 | GPIO_PIN_4 | GPIO_PIN_5) );
    GPIODirModeSet(GPIO_PORTA_BASE, Flash_CS, GPIO_DIR_MODE_OUT);            
    GPIOPadConfigSet( GPIO_PORTA_BASE, Flash_CS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD );                               
    Flash_UNSelect();
}


uint8 Flash_Send_Byte(uint8 data)
{      
    uint32 NullData;
   
   
    SSIDataPut(SSI_BASE, data);	
    SSIDataGet(SSI_BASE, &NullData); 
    return (uint8)NullData;     
}


void Wait_Busy(void)
{
	Flash_Select();
    Flash_Send_Byte(0xd7);
    
    while(1)
    {
    	if(Flash_Send_Byte(0x00) & 0x80)
            break;
    }
    
    Flash_UNSelect();
}


void Write_Datas_To_Buffer(uint8 Buffer_Area, uint16 Buffer_Addr, uint8* Datas_Addr, uint16 Data_Length)
{
	uint8 Buf_Area;
	uint16 i;
	
	
	if( Buffer_Area == 1)
		Buf_Area = 0x84;
	else
		Buf_Area = 0x87;
	
	Wait_Busy();
	Flash_Select();
	Flash_Send_Byte(Buf_Area);
	Flash_Send_Byte(0x00);
	Flash_Send_Byte( (uint8)(Buffer_Addr >> 8) );
	Flash_Send_Byte((uint8)Buffer_Addr);
	
	for(i = 0; i < Data_Length; i++)
	    Flash_Send_Byte( Datas_Addr[i] );	
	Flash_UNSelect();	
}


void Write_Buffer_To_Momery(uint8 Buffer_Area, uint16 Memory_Page)
{
	uint8 Buf_Area;

	
	
	if( Buffer_Area == 1)
		Buf_Area = 0x83;
	else
		Buf_Area = 0x86;
	
	Wait_Busy();
	Flash_Select();
	Flash_Send_Byte(Buf_Area);
	Flash_Send_Byte( (uint8)(Memory_Page >> 6) );
	Flash_Send_Byte( (uint8)(Memory_Page << 2) );
	Flash_Send_Byte( 0x00 );	
	Flash_UNSelect();	
}


void Read_Momery_To_Buffer(uint8 Buffer_Area, uint16 Memory_Page)
{
	uint8 Buf_Area;

	
	
	if( Buffer_Area == 1)
		Buf_Area = 0x53;
	else
		Buf_Area = 0x55;
	
	Wait_Busy();
	Flash_Select();
	Flash_Send_Byte(Buf_Area);
	Flash_Send_Byte( (uint8)(Memory_Page >> 6) );
	Flash_Send_Byte( (uint8)(Memory_Page << 2) );
	Flash_Send_Byte( 0x00 );	
	Flash_UNSelect();	
}


void Read_Buffer(uint8 Buffer_Area, uint16 Buffer_Addr, uint8* Datas_Addr, uint16 Data_Length)
{
	uint8 Buf_Area;
	uint16 i;
	
	
	if( Buffer_Area == 1)
		Buf_Area = 0xd4;
	else
		Buf_Area = 0xd6;
	
	Wait_Busy();
	Flash_Select();
	Flash_Send_Byte(Buf_Area);
	Flash_Send_Byte(0x00);
	Flash_Send_Byte( (uint8)(Buffer_Addr >> 8) );
	Flash_Send_Byte((uint8)Buffer_Addr);
	
	Flash_Send_Byte( 0x00 );	
	for(i = 0; i < Data_Length; i++)
	    Datas_Addr[i] = Flash_Send_Byte( 0x00 );	
	Flash_UNSelect();	
}

⌨️ 快捷键说明

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