VRS51L1050
//---------------------------------------------------//
//---------------------------------------------------//
//; EE_I²C_Read
//
EE_I²C_ByteWrite
//---------------------------------------------------//
//---------------------------------------------------//
char EE_I²C_ByteWrite( char device, int address, char txdata)
{
char EE_I²C_Read( char device)
{
Int
adrstemp = address;
//--Wait Bus idle
while((I2CCTRL1 & 0x08) != 0x00){};
//--Wait Bus idle
while((I2CCTRL1 & 0x08) != 0x00){};
//Configure I²C ID and device number
device = (device << 1)& 0x0E;
I2CADDR = 0xA0 + device;
I2CCTRL2 = 0x01;
//Configure I²C ID and device number
device = (device << 2)& 0x0E;
I2CADDR = 0xA0 + device;
//Set device in Read mode and restart
//wait RXIF flag to get set
I2CMASTER = 1;
//--Wait for Data Byte to be loaded into I2CTX
while(!I2CRXIF){};
//Configure master mode Data direction = Write
I2CCTRL2 &= 0xFE;
//I²C Master Write
//Generate a Stop
I2CMASTER = 0;
return I2CRX ;
//Start I²C
I2CMASTER = 1;
//--Send MSB of address
}//end of EE_I²C_RandomByteRead
while((I2CSTATUS & 0x40) == 0x00){}; //wait TXIF flag to get set
I2CTX = (adrstemp >> 8)& 0x1F;
//Send lower 5 bit of MCB address
//---------------------------------------------------//
//--Send LSB of address
while(!I2CTXIF){};
I2CTX = address & 0x00FF;
//
I²C_MCONFIG
//wait TXIF flag to get set
//Send lLSB of address
//---------------------------------------------------//
void I²C_MConfig(void )
{
//--Send Data
while(!I2CTXIF){};
I2CTX = txdata;
//wait TXIF flag to get set
//Send Data
//Activate I²C SCL and SDA access to P1
I2CPWME = 0xC0;
while(!I2CTXIF){};
I2CSTATUS &= 0xFD;
//wait TXIF flag to get set
//Clear MASTER -> Generate STOP
//Set I²C Speed=Fosc/512 (43kHz @ 22.1184MHz)
I2CCTRL1 = 0x84;
if(I2CTXACK)
return OK
else
while((I2CCTRL1 & 0x08) == 0x08){};
//Wait I2CBUSY == 0
//if NAKIF Flag == 0 -> ACK received
I2CCTRL2 = 0x00;
return BUG; //else device is nt responding
}//end of EE_I²C_ByteWrite
//configure I²C in master Transmit
I2CADDR = 0xA0;
//EEPROM Device Address
}///end of I²C_MConfig
//--------------------------------------------------------------//
//; EE_I²C_RandomByteRead
//--------------------------------------------------------------//
char EE_I²C_RandomByteRead( char device, int address)
{
int
adrstemp = address;
while((I2CCTRL1 & 0x08) != 0x00){};
//--Wait Bus idle
//Configure I²C ID and device number + Write address
device = (device << 1)& 0x0E;
I2CADDR = 0xA0 + device;
I2CMASTER = 1;
//Start I²C Transaction
//--Send MSB of address
while(!I2CTXIF){};
//wait TXIF flag to get set
I2CTX = (adrstemp >> 8)& 0x1F;
//Send lower 5 bit of MCB address
//--Send LSB of address
while(!I2CTXIF){};
I2CTX = address & 0x00FF;
//wait TXIF flag to get set
//Send lLSB of address
while(!I2CTXIF){};
I2CCTRL2 = 0x09;
//wait TXIF flag to get set
//Set device in Read mode and restart
//--Wait for Data Byte to be loaded into I2CTX
while(!I2CRXIF){};
//wait RXIF flag to get set
//Generate a Stop
I2CSTATUS = 0x00;
return I2CRX ;
}//end of FRAM_I²C_RandomByteRead
______________________________________________________________________________________________
www.ramtron.com page 31 of 49