This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C129ENCPDT: TM4C129ENCPDT I2C AT24C256 EEPROM READ WRITE PROBLEM

Part Number: TM4C129ENCPDT

Hello, I want to read/write some datas to external eeprom ( AT24C256) . I can read/write byte but while reading and writing word and especially double word I face with some problems. 

1) When reading a word I see 0xFFFF front of first byte. That happens sometimes not all the time.
2) I am not able to read and write double word correcty. I will write what I expect and what I see.

Waiting for help.

Here you can see related code part :

INITIALIZE

void InitI2C(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C5);
SysCtlPeripheralReset(SYSCTL_PERIPH_I2C5);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB4_I2C5SCL);
GPIOPinConfigure(GPIO_PB5_I2C5SDA);
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_4);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_5);
I2CMasterInitExpClk(I2C5_BASE, SysCtlClockGet(), false);
HWREG(I2C5_BASE + I2C_O_FIFOCTL) = 80008000;
I2CMasterEnable(I2C5_BASE);
EEPROM_WRITE_PROTECTION_ENABLE();
}

void EEPROM_WRITE_PROTECTION_ENABLE(void)
{
GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_3);
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3, GPIO_PIN_3);
}
void EEPROM_WRITE_PROTECTION_DISABLE(void)
{
GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_3);
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3, 0);
}

void Write_Eeprom_Byte(Uint16 address, int16 data)
{
EEPROM_WRITE_PROTECTION_DISABLE();

I2CMasterSlaveAddrSet(I2C5_BASE,SLAVE_ADDRESS, false);

I2CMasterDataPut(I2C5_BASE, ((address >> 8) & 0x00FF));
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_START);
SysCtlDelay(10000);
while(I2CMasterBusy(I2C5_BASE));

I2CMasterDataPut(I2C5_BASE, (address & 0x00FF ));
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
SysCtlDelay(10000);
while(I2CMasterBusy(I2C5_BASE));

I2CMasterDataPut(I2C5_BASE, data & 0xFF );
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
SysCtlDelay(10000);
while(I2CMasterBusy(I2C5_BASE));

EEPROM_WRITE_PROTECTION_ENABLE();
}


int16 Read_Eeprom_Byte(Uint16 address)
{
int16 temp = 0;
I2CMasterSlaveAddrSet(I2C5_BASE, SLAVE_ADDRESS, false);

I2CMasterDataPut(I2C5_BASE,((address >> 8) & 0x00FF));
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_START);
SysCtlDelay(10000);
while(I2CMasterBusy(I2C5_BASE));

I2CMasterDataPut(I2C5_BASE, (address & 0x00FF ));
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
SysCtlDelay(10000);
while(I2CMasterBusy(I2C5_BASE));

I2CMasterSlaveAddrSet(I2C5_BASE, SLAVE_ADDRESS, true);

I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
SysCtlDelay(10000);
while(I2CMasterBusy(I2C5_BASE));
temp = (I2CMasterDataGet(I2C5_BASE) & 0xFF);
return( temp );
}

void Write_Eeprom_Word(Uint16 address, int16 data)
{
EEPROM_WRITE_PROTECTION_DISABLE();

I2CMasterSlaveAddrSet(I2C5_BASE,SLAVE_ADDRESS, false);

I2CMasterDataPut(I2C5_BASE, ((address >> 8) & 0x00FF));
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_START);
SysCtlDelay(1000);
while(I2CMasterBusy(I2C5_BASE));

I2CMasterDataPut(I2C5_BASE, (address & 0x00FF));
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
SysCtlDelay(1000);
while(I2CMasterBusy(I2C5_BASE));

I2CMasterDataPut(I2C5_BASE, ((data >> 8) & 0x00FF ));
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
SysCtlDelay(1000);
while(I2CMasterBusy(I2C5_BASE));

I2CMasterDataPut(I2C5_BASE, (data & 0x00FF));
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
SysCtlDelay(1000);
while(I2CMasterBusy(I2C5_BASE));

EEPROM_WRITE_PROTECTION_ENABLE();
}

int16 Read_Eeprom_Word(Uint16 address)
{
int16 temp = 0;
I2CMasterSlaveAddrSet(I2C5_BASE, SLAVE_ADDRESS, false);

I2CMasterDataPut(I2C5_BASE, ((address >> 8) & 0x00FF));
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_START);
SysCtlDelay(1000);
while(I2CMasterBusy(I2C5_BASE));

I2CMasterDataPut(I2C5_BASE, (address & 0x00FF ));
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
SysCtlDelay(1000);
while(I2CMasterBusy(I2C5_BASE));

I2CMasterSlaveAddrSet(I2C5_BASE, SLAVE_ADDRESS, true);


I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
SysCtlDelay(1000);
while(I2CMasterBusy(I2C5_BASE));
temp = (I2CMasterDataGet(I2C5_BASE) << 8 );

I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
SysCtlDelay(1000);
while(I2CMasterBusy(I2C5_BASE));
temp += (I2CMasterDataGet(I2C5_BASE));

I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
return( temp );
}

void Write_Eeprom_Double_Word(Uint16 address, int32 data)
{
EEPROM_WRITE_PROTECTION_DISABLE();

I2CMasterSlaveAddrSet(I2C5_BASE,SLAVE_ADDRESS, false);

I2CMasterDataPut(I2C5_BASE, ((address >> 8) & 0x00FF));
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_START);
SysCtlDelay(10000);
while(I2CMasterBusy(I2C5_BASE));

I2CMasterDataPut(I2C5_BASE, (address & 0x00FF));
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
SysCtlDelay(10000);
while(I2CMasterBusy(I2C5_BASE));

I2CMasterDataPut(I2C5_BASE, ((data >> 24) & 0x00FF ));
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
SysCtlDelay(10000);
while(I2CMasterBusy(I2C5_BASE));

I2CMasterDataPut(I2C5_BASE, ((data >> 16) & 0x00FF ));
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
SysCtlDelay(10000);
while(I2CMasterBusy(I2C5_BASE));

I2CMasterDataPut(I2C5_BASE, ((data >> 8) & 0x00FF ));
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
SysCtlDelay(10000);
while(I2CMasterBusy(I2C5_BASE));

I2CMasterDataPut(I2C5_BASE, (data & 0x00FF ));
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
SysCtlDelay(10000);
while(I2CMasterBusy(I2C5_BASE));

EEPROM_WRITE_PROTECTION_ENABLE();
}

uint32_t Read_Eeprom_Double_Word(Uint16 address)
{
uint16_t temp2,temp3,temp4,temp5;
uint32_t temp;
I2CMasterSlaveAddrSet(I2C5_BASE, SLAVE_ADDRESS, false);

I2CMasterDataPut(I2C5_BASE, ((address >> 8) & 0x00FF));
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_START);
SysCtlDelay(10000);
while(I2CMasterBusy(I2C5_BASE));

I2CMasterDataPut(I2C5_BASE, (address & 0x00FF ));
I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
SysCtlDelay(10000);
while(I2CMasterBusy(I2C5_BASE));

I2CMasterSlaveAddrSet(I2C5_BASE, SLAVE_ADDRESS, true);

I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
SysCtlDelay(10000);
while(I2CMasterBusy(I2C5_BASE));
temp2 = (I2CMasterDataGet(I2C5_BASE) );

I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
SysCtlDelay(10000);
while(I2CMasterBusy(I2C5_BASE));
temp3 = (I2CMasterDataGet(I2C5_BASE) );

I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
SysCtlDelay(10000);
while(I2CMasterBusy(I2C5_BASE));
temp4 = (I2CMasterDataGet(I2C5_BASE) );

I2CMasterControl(I2C5_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
SysCtlDelay(10000);
while(I2CMasterBusy(I2C5_BASE));
temp5 = (I2CMasterDataGet(I2C5_BASE));

temp = (temp2 << 24) | (temp3 << 16) | (temp4 << 8) | temp5;
return( temp );
}

int main {

uint16_t  eeprom_read_array[33000],i,j;

Write_Eeprom_Word(6, 0x9C3A);
SysCtlDelay(100000);
Write_Eeprom_Word(8, 0x409B);
SysCtlDelay(100000);
Write_Eeprom_Word(10, 0x23FD);
SysCtlDelay(100000);
Write_Eeprom_Word(12, 0x3344);
SysCtlDelay(100000);

Write_Eeprom_Double_Word(30, 0x103080B0);

SysCtlDelay(100000);

for(i=0,j=6;i<4;i++,j+=2)
eeprom_read_array[i] = Read_Eeprom_Word(j);

I see as output FFFF9C3A, 409B, 23FD, 3344. As I mentioned before I see some 0xFFFF datas before first byte and that happens sometimes. Sometimes I read it correctly.


uint32_t temp_value_int32;


temp_value_int32 = Read_Eeprom_Double_Word(30);

I see          : 41B03080
Expected  : 103080B0

I think I miss something about bitwising. 



}

  • ChandlerBing said:
    I think I miss something about bitwising. 

    Even the (real) Chandler would have difficulty w/ "bitwising."

    Might "Big-End vs. Little-End" prove a better description.

    Would it not serve you to understand, "Which method is (most) "in play" - at both the MCU and EEProm - and then design to a common format?

    Note that much of your code (especially the write protect) is outside the "thrust/objective" of your issue - and its presence distracts AND forces added time/effort upon your hapless helpers.     Would not your creation of the "Minimal Code Listing" which "Well illustrates your objective - and failings" best serve (both) yourself and helpers?

  • Hello Chandler,

    The source code may be useful as the discussions goes on, but for the moment I would suggest the following:

    1) Using a logic state analyzer to confirm the commands being sent and data being read
    2) Debugging within the functions to find out if you are getting the right values from your I2C calls

    This will help track down if the issues are in application code, or with how you have configured the EEPROM reads/writes and thus are causing the I2C to send in incorrect values. I suspect the issue is in application code though, if the FFFF is appended to the first byte as you seem to indicate.

    How are you outputting the data values? I don't see any functions that do that.

    Where in the process does the FFFF show up? Within the eeprom_read_array variable after the Read_Eeprom_Word API? Or just when being output?

    Still a lot of missing info for us to be able to offer some constructive advice.
  • Hello Ralph,

    Thank you for comment. I will try to do more effective explanations about problems.

    I realize that FFFF issue occurs when data is more than 0x7FFF.

    If I write 0x7FFF in code ;written data 0x7FFF, read data 0x7FFF.

    If I write 0x8000 or bigger data in code, I see FFFF's in front of both written and read datas. 0xFFFF8000

  • Hello Chandler,

    That's quite interesting for sure, and good to know, but it doesn't really help me in diagnosing what could be going on wrong.

    Right now the issue could come anywhere from the EEPROM data output, to the TM4C I2C peripheral, to your own functions, to how you are reading out the data.

    Let's start with something simple. How are you outputting the data values? As in, where do you see the FFFF? Is it in a buffer during debug? On an o-scope capture of I2C lines? On a terminal after UART Printing?
  • Hello Chandler,

    Are you still facing issues with this? If so and you are still seeking support, please help address my questions from my post on February 9th.
  • Hello Chandler,

    I am going to close this thread. If you are still facing this issue, you can respond to my message to re-open it (or re-post and link this thread if it locks due to timeout).