hello there,
I am trying to achieve communication with EERPOM IC using I2C protocol.
M learning the protocol and implementing it for first time on own,
But I am stuck here where i am not able to get where to go.
I am using bit banging to implement I2C protocol in TM4C123GXL eval board.
I am trying to achieve the following..
But when i dont get the data from EEPROM though EEPROM gives ACK when i write the address and control byte.
I have observed waveforms on CRO and its as observed in debug...ACK is received but not transmission of DATA from IC,
I am posting the code...i just wanted to confrm that is there anything wrong in my code.
I am trying to read 6 bytes of code from EEPROM, from address FA to FF.
//******************************************************************8
unsigned char I2CFlag;
#define _I2CError (I2CFlag & (char) 0x40)
#define _ClrI2CError (I2CFlag &= (unsigned char)(~0x40))
#define _SetI2CError (I2CFlag |= (unsigned char)0x40)
#define _SetSDA GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_1, GPIO_PIN_1);
#define _ClrSDA GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_1, 0x00);
#define _SetSCL GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_0, GPIO_PIN_0);
#define _ClrSCL GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_0, 0x00);
#define _IsSDA ((GPIOPinRead(GPIO_PORTG_BASE,GPIO_PIN_1)) & GPIO_PIN_1 )
#define _SetSDAOutput() {GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_1);}
#define _SetSDAInput() {GPIOPinTypeGPIOInput(GPIO_PORTG_BASE, GPIO_PIN_1);}
#define _SetSCLOutput() {GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_0);}
#define _SetSCLInput() {GPIOPinTypeGPIOInput(GPIO_PORTG_BASE, GPIO_PIN_0);}
void delay(unsigned int delCounter)
{
unsigned int cnt;
for(cnt = 0; cnt < delCounter; cnt++)
{
}
}
void Delay8bit(unsigned char i)
{
delay(1000*i);
}
void I2CStartRou(void)
{
Delay8bit(1);
_SetSDA;
Delay8bit(1);
_SetSCL;
Delay8bit(6);
_ClrSDA;
Delay8bit(4);
_ClrSCL;
Delay8bit(2);
}
//------------------------------------------------------------
void I2CStopRou(void)
{
Delay8bit(1);
_ClrSDA;
Delay8bit(2);
_SetSCL;
Delay8bit(2);
_SetSDA;
Delay8bit(1);
}
void I2CClockRou(void)
{
Delay8bit(3);
_SetSCL;
_ClrI2CError;
Delay8bit(6);
if(_IsSDA){ _SetI2CError;}
_ClrSCL;
Delay8bit(3);
}
void I2CNack(void)
{
Delay8bit(3);
_SetSDA;
Delay8bit(3);
I2CClockRou();
}
void I2COutByteRecAck(unsigned char EEPData)
{
unsigned char bit_cnt;
for(bit_cnt = (unsigned char)0x08;bit_cnt!=(unsigned char)0x00; bit_cnt--)
{
_ClrSDA;
if(EEPData & (char)0x80){_SetSDA;}
EEPData <<= (char)0x01;
I2CClockRou();
}
Delay8bit(2);
_SetSDAInput();
Delay8bit(2);
I2CNack();
Delay8bit(2);
_SetSDAOutput();
}
unsigned char I2CReadByte(void)
{
unsigned char bit_cnt, EEPData=0;
_SetSDAInput();
Delay8bit(2);
for(bit_cnt=8;bit_cnt != (char)0x00; bit_cnt--)
{
I2CClockRou();
EEPData <<= (char)0x01;
if(_I2CError){EEPData |= (char)0x01 ;}
}
_SetSDAOutput();
return EEPData;
}
//--------------------------------------
//I2C initialization
void I2CIoInit(void){
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
_SetSDAOutput();
_SetSCLOutput();
}
unsigned char eeptr =0xfa;
unsigned char pucMACAddrMit[8];
//To Write and read the data
void i2c_main(void){
unsigned char i;
pucMACAddrMit[6] =0x33;
for(i=0;i<6;i++){ //i2c Write loop
I2CStartRou();
I2COutByteRecAck(0xA0); //Device addr
I2COutByteRecAck(eeptr+i); //starting address of MAC
I2COutByteRecAck(pucMACAddrMit[6]+i);
pucMACAddrMit[i] = 00;
I2CStopRou();
Delay8bit(100);
}
for(i=0;i<6;i++){ //i2c Raad loop
I2CStartRou();
I2COutByteRecAck(0xA0); //Device addr
I2COutByteRecAck(i + eeptr); //starting address of MAC
I2CStartRou();
I2COutByteRecAck(0xA1);
pucMACAddrMit[i] = I2CReadByte();
I2CStopRou();
}
}