Exemplo n.º 1
0
/*********************************************************************//**
 * @author             
 * @brief 	
 * @date 
 * @version  
 * @description 
 * @param[in]		None.
 * @param[out]		None.
 * @return 				             
 *                         
 **********************************************************************/
void SFlash_Write_AAI_All(uint8_t data[], uint8_t len, uint32_t address)
{
	uint32_t i;
	SFlash_Write_Status_Rregister(0x00);
	SFlash_Write_Enable();
	
	SPI_FLASH_CS_LOW();					
	Flash_ReadWriteByte(PROGRAM_AAI_OPCODE);
	Flash_ReadWriteByte(address >> 16);
	Flash_ReadWriteByte(address >> 8);
	Flash_ReadWriteByte(address);
	Flash_ReadWriteByte(data[0]);
	Flash_ReadWriteByte(data[1]);
	SPI_FLASH_CS_HIGH();
	//delay_ms(1);
	WaitBusy();
	//while (SFlash_Read_Status_Register() & 0x01);
	//while (Flash_ReadWriteByte(RDSR_OPCODE) & 0x01);/* Send Read Status Register command */
	//len = len-2;
	for (i = 2; i<len; i+=2)
	{
		SPI_FLASH_CS_LOW();
		Flash_ReadWriteByte(PROGRAM_AAI_OPCODE);
		Flash_ReadWriteByte(data[i]);
		Flash_ReadWriteByte(data[i+1]);	
		SPI_FLASH_CS_HIGH();
		//delay_ms(1);
		//while (SFlash_Read_Status_Register() & 0x01);
		//while (Flash_ReadWriteByte(RDSR_OPCODE) & 0x01);/* Send Read Status Register command */
		WaitBusy();
	}	
	
}
Exemplo n.º 2
0
void PageWriteMainMemo(WORD page,WORD p_addr,BYTE  num,BYTE *dat) { 
	if (( num == 0 ) || (dat == NULL))
    return; 

	if ((p_addr + num) > AT_45_PAGE_SIZE) {
    num = AT_45_PAGE_SIZE - p_addr; 
  }

  WaitBusy();
	ClearCSSWSPI(); 
	WriteMainMemoToBuffer1(page); 
	WaitBusy(); 
	WriteBuffer1(p_addr, num, dat); 
	WriteBuffer1ToMainMemo(page); 
	SetCSSWSPI(); 
} 
Exemplo n.º 3
0
/*********************************************************************//**
 * @author             
 * @brief 	
 * @date 
 * @version  
 * @description 
 * @param[in]		None.
 * @param[out]		None.
 * @return 				             
 *                         
 **********************************************************************/
void SFlash_Chip_Erase(void)
{
	SFlash_Write_Status_Rregister(0x00);
	SFlash_Write_Enable();
	
	SPI_FLASH_CS_LOW();					
	Flash_ReadWriteByte(ERASE_CHIP_OPCODE);
	SPI_FLASH_CS_HIGH();
	delay_ms(1000);
	WaitBusy();
}
void WriteData(u8 data)  //д���ݺ�����
{
	  WaitBusy(); 
    GPIO_SetBits(DisIOB,RS);  //RS = 1. 
    GPIO_ResetBits(DisIOB,RW);  //RW = 0. 
    GPIO_SetBits(DisIOB,EN);    //EN = 1.
    DisIOA->ODR=((DisIOA->ODR & 0xff00)|data);  //ͬ�ϡ�
    Delay_us(100);
    GPIO_ResetBits(DisIOB,EN);  //EN = 0;
    Delay_us(100); 
}
Exemplo n.º 5
0
/*********************************************************************//**
 * @author             
 * @brief 	
 * @date 
 * @version  
 * @description 
 * @param[in]		None.
 * @param[out]		None.
 * @return 				             
 *                         
 **********************************************************************/
void SFlash_Sector_Erase_4KB(uint32_t sectorAddress)
{
	SFlash_Write_Status_Rregister(0x00);
	SFlash_Write_Enable();

	SPI_FLASH_CS_LOW();					
	Flash_ReadWriteByte(ERASE_SECTOR_OPCODE);
	Flash_ReadWriteByte(sectorAddress >> 4);		// sectorAddress << 12 then sectorAddress >> 16
	Flash_ReadWriteByte(sectorAddress << 4);		// sectorAddress << 12 then sectorAddress >> 8
	Flash_ReadWriteByte(0);
	SPI_FLASH_CS_HIGH();
	delay_ms(100);
	WaitBusy();
}
void WriteCmd(u8 cmd)    //д�������
{
  	WaitBusy(); 
    GPIO_ResetBits(DisIOB,RS);  //RS = 0.
    GPIO_ResetBits(DisIOB,RW);  //RW = 0. 
    GPIO_SetBits(DisIOB,EN);    //EN = 1.
    DisIOA->ODR=((DisIOA->ODR & 0xff00)|cmd); //�˴���ֻ��ֱ�Ӳ����Ĵ�������
                  //�ﵽ��ֻ�ı�������ݼĴ���ODR�ĵ�8λ������λ
                  //�����Ŀ�ġ���Ϊ��ֻ�е�8λ���������ţ�
                  //����λ�����ǿ������ţ����ܸı䡣
    Delay_us(100);
    GPIO_ResetBits(DisIOB,EN);  //EN = 0;
    Delay_us(100); 	
}
Exemplo n.º 7
0
/*********************************************************************//**
 * @author             
 * @brief 	
 * @date 
 * @version  
 * @description 
 * @param[in]		None.
 * @param[out]		None.
 * @return 				             
 *                         
 **********************************************************************/
void SFlash_Write_Byte(uint8_t writeByte, uint32_t address)
{
	SFlash_Write_Status_Rregister(0x00);
	SFlash_Write_Enable();
	
	SPI_FLASH_CS_LOW();					
	Flash_ReadWriteByte(PROGRAM_BYTE_OPCODE); 			/* Send byte data programming command */
	Flash_ReadWriteByte(address >> 16);  				/* Send 3 byte address command */
	Flash_ReadWriteByte(address >> 8);
	Flash_ReadWriteByte(address);
	Flash_ReadWriteByte(writeByte);						/* Write data */
	SPI_FLASH_CS_HIGH();
	
	WaitBusy();
}
Exemplo n.º 8
0
  BYTE AT45DBXX_Read( BYTE * bufOut, DWORD addr, WORD len ){
#endif

  WORD i;
  BYTE * pByte;

  if ( WaitBusy() == FALSE ){
    return -1;
  }

  if ( !len ){
    return 0;
  }

  ClearCSSWSPI();

  // comando de leitura diretamente da SDRAM
  SWSPIWrite( FLASH_CMD_MAIN_MEM_PAGE_RD );

  // endereços e páginas concatenados
  WriteFlashAddr( addr );

  // envia DUMMY_BYTES
  i = FLASH_CMD_MAIN_MEM_PAGE_RD_DMY_BYTE;
  do{
    SWSPIWrite( 0xFF );
  }while( --i );

   pByte = bufOut;
  do{
    *pByte++ = ReadSWSPI();
  }while( --len );

  SetCSSWSPI();
  return i;
}