projekty/Source/example1/src/Ramtron.c

Go to the documentation of this file.
00001 /*
00002  * $Id: Ramtron.c,v 1 2006/28/05 10:05:00 BorisK Exp $
00003  *
00004  * Copyright (C) 2006 ONTRACK s.r.o.
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA    
00019  * 02111-1307, USA.
00020  *
00021  * [1] Ramtron FM24C256ds_r3.1.pdf
00022  * Written by Boris Kralik <kralikbo@yahoo.com>, 2006
00023  * FM24C256 = 256kbit, 32kbyte
00024  *
00025  */
00026 #include "Ramtron.h"
00027 
00028 /***********************************************************************************
00029         Name:           RamtronWriteString
00030         Description:    Write chString to Ramtron FRAM at uiAddress
00031         Parameters:     unsigned        char *
00032         Return:         unsigned        char *
00033 ************************************************************************************/
00034 unsigned        char    *RamtronWriteString(uint8_t uiAddress,unsigned char *chString)
00035 {
00036         uint8_t i=0;
00037         do{
00038                         if (RamtronWriteByte(uiAddress++,chString[i]) != chString[i++])
00039                         {
00040                                 printf("\n\r\tError Write String !!!");
00041                                 return NULL;
00042                         }
00043                 #if 0
00044                         printf("\n\r\tchar:%d[%c],i=%d",chString[i-1],chString[i-1],i);
00045                 #else
00046                         ;
00047                 #endif
00048         }while(chString[i]!='\x0');
00049         return  chString;
00050 }
00051 /***********************************************************************************
00052         Name:           RamtronInit
00053         Description:    Initaialize RAMTRON FM24C256 Memory 
00054         Parameters:     void
00055         Return:         uint8_t
00056 ************************************************************************************/
00057 uint8_t RamtronInit(void)
00058 {
00059         I2C_SetSTO();
00060         WD_Reset();
00061         if ((SendSlaveAdress(FRAM_W) != 0 ) || (I2C_I2STAT == 0x20))
00062                 {
00063                         #if 0
00064                                 printf("\n\rError Set slave address, I2STAT=0x%X",I2C_I2STAT);
00065                         #endif
00066                         WD_Reset();
00067                         return -1;
00068                         } 
00069                         else {
00070                         #if 0
00071                                 printf("\n\rSTA:0x%X",I2C_I2STAT);
00072                         #endif
00073                         WD_Reset();
00074                         return 0;
00075                         }
00076         WD_reset();
00077         return 0;
00078 }
00079 /***********************************************************************************
00080         Name:           RamtronReadByte
00081         Description:    Read Byte from FM24C256 Memory 
00082         Parameters:     uint8_t - address
00083         Return:         unsigned char
00084 ************************************************************************************/
00085 unsigned char RamtronReadByte(uint8_t uiAddress)
00086 {
00087         uint8_t uiAddH=0,uiAddL=0;
00088         unsigned char ret=0;
00089         #if 0
00090                 printf("\n\r***RamtronRead\n\ruiAddress=0x%X",uiAddress);
00091         #endif
00092         uiAddL=((uiAddress & 0x00FF));WD_Reset();
00093         uiAddH=((uiAddress & 0xFF00)>>8);WD_Reset();
00094         #if 0
00095                 printf("\n\r\tuiAddL=0x%X",uiAddL);
00096                 printf("\n\r\tuiAddH=0x%X",uiAddH);
00097         #endif
00098         
00099         if (SendSlaveAdress(FRAM_W) != 0 )
00100                 {
00101                 #if 1
00102                         printf("\n\rError Set slave address (1), I2STAT=0x%X",I2C_I2STAT);WD_Reset();
00103                 #else
00104                         WD_Reset();
00105                 #endif
00106                         return -1;
00107                 } 
00108                         else {
00109                         #if 0
00110                                 printf("\n\rSTA:0x%X",I2C_I2STAT);
00111                         #endif
00112                         WD_Reset();
00113                         }
00114         WriteOnI2C(uiAddH);WD_Reset();
00115         WriteOnI2C(uiAddL);WD_Reset();
00116         if (SendSlaveAdress(FRAM_R) != 0 )
00117                 {
00118                 #if 1
00119                         printf("\n\rError Set slave address (1), I2STAT=0x%X",I2C_I2STAT);
00120                 #endif
00121                 return 0;} 
00122                         else {
00123                         #if 0
00124                                 printf("\n\rSTA:0x%X",I2C_I2STAT);
00125                         #endif
00126                                 ;
00127                                 }
00128         ret = ReadOnI2C();WD_Reset();
00129         I2C_SetSTO();WD_Reset();
00130         #if 0
00131                 printf("\n\rRead=0x%X",ret);
00132         #endif
00133         return ret;
00134 }
00135 /***********************************************************************************
00136         Name:           RamtronWriteByte
00137         Description:    Write Byte to FM24C256 Memory 
00138         Parameters:     uint8_t - address, uint8_t - Data
00139         Return:         uint8_t, if OK, return Data
00140 ************************************************************************************/
00141 uint8_t RamtronWriteByte(uint8_t uiAddress,uint8_t uiData)
00142 {
00143         uint8_t uiAddH=0,uiAddL=0;
00144         #if 0
00145                 printf("\n\r***RamtronWrite\n\ruiAddress=0x%X\n\ruiData=0x%X",uiAddress,uiData);
00146         #endif
00147         uiAddL=((uiAddress & 0x00FF));
00148         uiAddH=((uiAddress & 0xFF00)>>8);
00149         #if 0
00150                 printf("\n\r\tuiAddL=0x%X",uiAddL);
00151                 printf("\n\r\tuiAddH=0x%X",uiAddH);
00152                 printf("\n\r\tuiDataL=0x%X",uiData);
00153         #endif
00154         if (SendSlaveAdress(FRAM_W) != 0 )
00155                 {
00156                 #if 1
00157                         printf("\n\rError Set slave address (1), I2STAT=0x%X",I2C_I2STAT);
00158                 #endif
00159                 return 0;
00160                 } 
00161                         else {
00162                         #if 0
00163                                 printf("\n\rSTA:0x%X",I2C_I2STAT);
00164                         #endif
00165                                 ;
00166                                 }
00167         WriteOnI2C(uiAddH);
00168         WriteOnI2C(uiAddL);
00169         WriteOnI2C(uiData);
00170         I2C_SetSTO();
00171         return uiData;
00172 }

Generated on Fri Sep 21 13:41:54 2007 for example1 by  doxygen 1.4.7