/home/daqweb/fgddaq/c8051/Devices/AT25160A.h File Reference


Defines

#define AT2516_WREN   0x06
#define AT2516_WRDI   0x04
#define AT2516_RDSR   0x05
#define AT2516_WRSR   0x01
#define AT2516_READ   0x03
#define AT2516_WRITE   0x02
#define MAX_PAGE_SIZE   0x200
#define WP_START_ADDR   0x0600
#define WP_FINAL_ADDR   0x07FF
#define AT2516_MAX_BYTE   32
#define AT2516_PROTECTION   0x84
#define AT2516_WEN   0x02
#define AT2516_WPEN   0x80
#define ERROR   -1

Functions

signed char ExtEEPROM_Init (unsigned int page_size)
signed char ExtEEPROM_Read (unsigned int ReadPage, unsigned char *destination, unsigned int page_size)
signed char ExtEEPROM_Write_Clear (unsigned int WritePage, unsigned char *source, unsigned int page_size, unsigned char clear)
signed char ExtEEPROM_WriteProtect (unsigned char *source, unsigned int page_size)
void ExtEEPROM_WriteEnable (void)
void ExtEEPROM_WriteStatusReg (unsigned char status)
unsigned char ExtEEPROM_Status (void)
void ExtEEPROM_Wait (void)

Variables

sbit EEP_SCK = MSCB_SPI_SCK
sbit EEP_MOSI = MSCB_SPI_MISO
sbit EEP_MISO = MSCB_SPI_MOSI
sbit RAM_CSn = RAM_CHIP_SELECT
sbit RAM_HLDn = RAM_HOLD_DOWN
sbit RAM_WPn = RAM_WRITE_PROTECT

Define Documentation

#define AT2516_MAX_BYTE   32

#define AT2516_PROTECTION   0x84

#define AT2516_RDSR   0x05

#define AT2516_READ   0x03

#define AT2516_WEN   0x02

#define AT2516_WPEN   0x80

#define AT2516_WRDI   0x04

#define AT2516_WREN   0x06

#define AT2516_WRITE   0x02

#define AT2516_WRSR   0x01

#define ERROR   -1

#define MAX_PAGE_SIZE   0x200

#define WP_FINAL_ADDR   0x07FF

#define WP_START_ADDR   0x0600


Function Documentation

signed char ExtEEPROM_Init ( unsigned int  page_size  ) 

00024 {
00025   // Unselecting the device
00026   RAM_CSn = 1;
00027 
00028   //Initializing the SPI
00029   SPI_Init();
00030 
00031   if(page_size > MAX_PAGE_SIZE)
00032   return ERROR;
00033 
00034   ExtEEPROM_Wait();
00035 
00036   return 0;
00037 }

signed char ExtEEPROM_Read ( unsigned int  ReadPage,
unsigned char *  destination,
unsigned int  page_size 
)

00043 {
00044   unsigned int i=0;
00045 
00046   //Making sure that Write Protection pin is high
00047   RAM_WPn = 1;
00048   ExtEEPROM_WriteEnable();
00049 
00050   RAM_CSn = 0;
00051   SPI_WriteByte(AT2516_READ);      //Sending the Write Data to Memory Array command
00052   SPI_WriteUInt(ReadPage);         //Sending the address of location that we want to do the write
00053 
00054   for (i;i<page_size;i++)
00055   {
00056     *destination=SPI_ReadByteRising();
00057     destination++;
00058 
00059   }
00060   delay_us(25);
00061   RAM_CSn = 1;
00062   RAM_WPn = 0;
00063   return 0;
00064 }

unsigned char ExtEEPROM_Status ( void   ) 

00184 {
00185   unsigned char status;
00186 
00187   RAM_CSn = 0;
00188   SPI_WriteByte(AT2516_RDSR);
00189   status=SPI_ReadByteRising();
00190   delay_us(25);
00191   RAM_CSn = 1;
00192   delay_us(25);
00193 
00194   return status;
00195 }

void ExtEEPROM_Wait ( void   ) 

00198                           {
00199   unsigned char status;
00200   do {
00201     status = ExtEEPROM_Status();
00202   } while((status & 0x71) != 0);
00203 }

signed char ExtEEPROM_Write_Clear ( unsigned int  WritePage,
unsigned char *  source,
unsigned int  page_size,
unsigned char  clear 
)

00115 {
00116   unsigned int i,j;
00117   unsigned int blockSize;
00118   unsigned int counter = AT2516_MAX_BYTE;
00119 
00120   //Making sure that Write Protection pin is high
00121   RAM_WPn = 1;
00122   blockSize = page_size / AT2516_MAX_BYTE;
00123 
00124   for (i = 0; i <= blockSize; i++) {
00125     //NW
00126     write_addr = i * AT2516_MAX_BYTE;          //Updating the address of mempry
00127     if (i == blockSize) {
00128       counter = (page_size % AT2516_MAX_BYTE);
00129     }
00130 
00131     ExtEEPROM_WriteEnable();
00132 
00133     RAM_CSn = 0;
00134 
00135     SPI_WriteByte(AT2516_WRITE);           //Sending the Write Data to Memory Array command
00136     SPI_WriteUInt(write_addr);             //Sending the address of location that we want to do the write
00137 
00138     for (j=0; j<counter; j++) {
00139       if (!clear){
00140         SPI_WriteByte(*source);
00141         source++;
00142       }
00143       else
00144       SPI_WriteByte(0x00);
00145     }
00146 
00147     delay_us(25);
00148     RAM_CSn = 1;                // The low-to-high transition of the RAM_CSn must occur during
00149     delay_us(25);
00150     ExtEEPROM_Wait();
00151   }
00152 
00153   RAM_WPn = 0;
00154   return 0;
00155 }

void ExtEEPROM_WriteEnable ( void   ) 

00159 {
00160   //Enabling the write operation
00161   RAM_CSn = 0;
00162   delay_us(10);
00163   SPI_WriteByte(AT2516_WREN);
00164   delay_us(25);
00165   RAM_CSn = 1;
00166   delay_us(25);
00167   ExtEEPROM_Wait();
00168 }

signed char ExtEEPROM_WriteProtect ( unsigned char *  source,
unsigned int  page_size 
)

00068 {
00069   unsigned int i,j;
00070   unsigned int eeprom_addr, blockSize;
00071   unsigned int counter = AT2516_MAX_BYTE;
00072 
00073   //Making sure that Write Protection pin is high
00074   RAM_WPn = 1;
00075 
00076   ExtEEPROM_WriteStatusReg(0x0);
00077 
00078   blockSize = page_size / AT2516_MAX_BYTE;
00079 
00080   for (i = 0; i <= blockSize; i++) {
00081     eeprom_addr = WP_START_ADDR + (i * AT2516_MAX_BYTE);    //Updating the address of memory
00082     if (i == blockSize) {
00083       counter = (page_size % AT2516_MAX_BYTE);
00084     }
00085 
00086     ExtEEPROM_WriteEnable();
00087 
00088 
00089     RAM_CSn = 0;
00090 
00091     SPI_WriteByte(AT2516_WRITE);    // Sending the Write Data to Memory Array command
00092     SPI_WriteUInt(eeprom_addr);     // Sending the address of location that we want to do the write
00093 
00094     for (j=0; j<counter; j++) {
00095       SPI_WriteByte(*source);
00096       source++;
00097     }
00098 
00099     delay_us(25);
00100     RAM_CSn = 1;                // The low-to-high transition of the RAM_CSn must occur during
00101     delay_us(25);
00102     ExtEEPROM_Wait();
00103   }
00104 
00105   ExtEEPROM_WriteStatusReg(AT2516_PROTECTION);
00106   RAM_WPn = 0;
00107   return 0;
00108 }

void ExtEEPROM_WriteStatusReg ( unsigned char  status  ) 

00171                                                     {
00172   ExtEEPROM_WriteEnable();
00173   RAM_CSn = 0;
00174   SPI_WriteByte(AT2516_WRSR);
00175   SPI_WriteByte(status);
00176   delay_us(25);
00177   RAM_CSn = 1;
00178   delay_us(25);
00179   ExtEEPROM_Wait();
00180 }


Variable Documentation

sbit EEP_MISO = MSCB_SPI_MOSI

sbit EEP_MOSI = MSCB_SPI_MISO

sbit EEP_SCK = MSCB_SPI_SCK

sbit RAM_CSn = RAM_CHIP_SELECT

sbit RAM_HLDn = RAM_HOLD_DOWN

sbit RAM_WPn = RAM_WRITE_PROTECT


Generated on 10 Jun 2013 for FGDC8051 by  doxygen 1.4.7