// This file has been prepared for Doxygen automatic documentation generation. /*! \file ******************************************************************** * * Atmel Corporation * * - File : spi_mem.h * - Compiler : IAR EWAAVR 3.20c * * - Support mail : avr@atmel.com * * - Supported devices : All AVR with a SPI interface and SRAM ( 1kB SRAM for 4 Meg SPI memory is recommended) can be used. * * * - AppNote : AVR107 - Basic AVR Drivers for SPI Serial Memory Devices * * - Description : · Devices : AT25128A/256A, AT25F1024/2048/4096 * · Full Serial Memory Functions Support * · Memory Array Burst Read * · Page Burst Write * · Write Protection Detection * · On Going Access Detection * · Non-blocking Write Access * · Access Status Information * * $Revision: 1.3 $ * $Date: Wednesday, March 02, 2005 13:33:00 UTC $ *****************************************************************************/ #ifndef __SPI_MEMORY_H #define __SPI_MEMORY_H ////////////////////////////////////////////////////////////////////////// // UNCOMMENT THE LINE CORRESPONDING TO THE CONNECTED SPI SERIAL MEMORY ///////////////////////////////////////////////////////////////////////// //#define AT25128A #define AT25256A //#define AT25F1024 //#define AT25F2048 //#define AT25F4096 #if (defined(AT25128A) | defined(AT25256A)) #define EEPROM_TYPE #endif #ifdef EEPROM_TYPE ///////////////////////////////////// // SPI SERIAL EEPROMs (AT25256A/128A) ///////////////////////////////////// #define PAGE_SIZE 64 //! page size #define NB_ADDR_BYTE 2 //!< The serial memory has a 2 bytes long address phase ///////////////////////////// // Block Write Protect Bits //////////////////////////// #define WPB_MASK 0x0C #define NONE (0x00 << 2) #define TOP_QUARTER (0x01 << 2) #define TOP_HALF (0x02 << 2) #define ALL (0x03 << 2) ///////////////////////////// // INSTRUCTION CODES //////////////////////////// #define WREN 0x06 #define WRDI 0x04 #define RDSR 0x05 #define WRSR 0x01 #define READ 0x03 #define WRITE 0x02 ///////////////////////////// // ADDRESS SPACE //////////////////////////// #ifdef AT25256A #define TOPQ_ADDR 0x6000 //!< Serial memory top quarter address #define HALF_ADDR 0x4000 //!< Serial memory half address #define TOP_ADDR 0x7FFF //!< Serial memory top address #else #define TOPQ_ADDR 0x3000 #define HALF_ADDR 0x2000 #define TOP_ADDR 0x3FFF #endif #else ///////////////////////////////////////// // SPI SERIAL FLASH (AT25F1024/2048/4096) ///////////////////////////////////////// #define PAGE_SIZE 256 //!< The page size #define NB_ADDR_BYTE 3 //!< The serial memory has a 2 bytes long address phase ///////////////////////////// // Block Write Protect Bits //////////////////////////// #define WPB_MASK 0x1C #define NONE (0x00 << 2) #define TOP_EIGHTH (0x01 << 2) #define TOP_QUARTER (0x02 << 2) #define TOP_HALF (0x03 << 2) #define ALL (0x04 << 2) ///////////////////////////// // INSTRUCTION CODES //////////////////////////// #define WREN 0x06 #define WRDI 0x04 #define RDSR 0x05 #define WRSR 0x01 #define READ 0x03 #define PROGRAM 0x02 #define SECTOR_ERASE 0x52 #define CHIP_ERASE 0x62 #define RDID 0x15 ///////////////////////////// // ADDRESS SPACE //////////////////////////// #ifdef AT25F4096 #define TOP8TH_ADDR 0x70000 //!< Serial memory top eighth address #define TOPQ_ADDR 0x60000 //!< Serial memory top quarter address #define HALF_ADDR 0x40000 //!< Serial memory half address #define TOP_ADDR 0x7FFFF //!< Serial memory top address #define BP2 4 //! Block Write Protect Bit only for AT25F4096 Devices #elif (defined(AT25F2048)) #define TOPQ_ADDR 0x30000 //!< Serial memory top quarter address #define HALF_ADDR 0x20000 //!< Serial memory half address #define TOP_ADDR 0x3FFFF //!< Serial memory top address #else #define TOPQ_ADDR 0x18000 //!< Serial memory top quarter address #define HALF_ADDR 0x10000 //!< Serial memory half address #define TOP_ADDR 0x1FFFF //!< Serial memory top address #endif #endif // STATUS REGISTER BIT #define RDY 0//! Busy Indicator Bit #define WEN 1//! Write Enable Bit #define BP0 2//! Block Write Protect Bit #define BP1 3//! Block Write Protect Bit #define WPEN 7//! Software Write Protect Enable Bit ///////////////////////////////////////// // MACROs ///////////////////////////////////////// //! Marco :Pull down the chip select line of the serial memory #define Select_Serial_Memory PORTB=(PORTB & ~(1<