00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "Ramtron.h"
00027
00028
00029
00030
00031
00032
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
00053
00054
00055
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
00081
00082
00083
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
00137
00138
00139
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 }