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.

Example code for EEPROM - F28M35x Evaluation board

Hello,

   I am looking for some example code or API documentation for I2C operation on EEPROM. The CONTROL-SUITE has examples on i2c-eeprom for different other controllers. It would be helpful if someone can provide me documents on how to use the TI APIs for I2C.

Thanks

Anoja

  • Anoja,

    This example is not available for this device family and we don't have any plans to update it.

    But, you should be able to easily take i2c_eeprom example from other devices say F2806x / F2803x and adapt it to F28M35x device.

    Regards,
    Manoj
  • Thank you for the reply. From the datasheet of CAT24C256 EEPROM, I could figure out the sequence of how to read and write to it. The current issue is that I am reading 0xFF everytime I read the location I wrote into. Can you suggest any modification or let me know if my code is wrong.

    // Sending a EEPROM write byte packet

    I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, I2C_WRITE);
    ulDataTx[0] = 0x00;
    ulDataTx[1] = 0x00;
    ulDataTx[2] = 0x12;
    ulDataTx[3] = 0x35;
    ulDataTx[4] = 0xA1;
    ulDataTx[5] = 0x11;
    ulDataTx[6] = 0xF0;
    ulDataTx[7] = 0x01;

    I2CMasterDataPut(I2C0_MASTER_BASE, ulDataTx[0]);
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    while(I2CMasterBusy(I2C0_MASTER_BASE)){}

    I2CMasterDataPut(I2C0_MASTER_BASE, ulDataTx[1]);
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    while(I2CMasterBusy(I2C0_MASTER_BASE)){}

    I2CMasterDataPut(I2C0_MASTER_BASE, ulDataTx[2]);
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    while(I2CMasterBusy(I2C0_MASTER_BASE)){}

    I2CMasterDataPut(I2C0_MASTER_BASE, ulDataTx[3]);
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    while(I2CMasterBusy(I2C0_MASTER_BASE)){}

    I2CMasterDataPut(I2C0_MASTER_BASE, ulDataTx[4]);
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    while(I2CMasterBusy(I2C0_MASTER_BASE)){}

    I2CMasterDataPut(I2C0_MASTER_BASE, ulDataTx[5]);
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    while(I2CMasterBusy(I2C0_MASTER_BASE)){}

    I2CMasterDataPut(I2C0_MASTER_BASE, ulDataTx[6]);
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    while(I2CMasterBusy(I2C0_MASTER_BASE)){}

    I2CMasterDataPut(I2C0_MASTER_BASE, ulDataTx[7]);
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
    while(I2CMasterBusy(I2C0_MASTER_BASE)){}

    //Read 3 bytes

    I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, I2C_WRITE);

    // Dummy Write to set the future read address
    I2CMasterDataPut(I2C0_MASTER_BASE, 0); // address zero in the EEPROM memory
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    while(I2CMasterBusy(I2C0_MASTER_BASE)){}

    I2CMasterDataPut(I2C0_MASTER_BASE, 0); // address zero in the EEPROM memory
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    while(I2CMasterBusy(I2C0_MASTER_BASE)){}

    // Start reading the address 0x00
    I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, I2C_READ);

    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
    while(I2CMasterBusy(I2C0_MASTER_BASE)){}
    ulDataRx[0] = I2CMasterDataGet(I2C0_MASTER_BASE);

    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
    I2CWhileMasterBusy
    ulDataRx[1] = I2CMasterDataGet(I2C0_MASTER_BASE);

    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
    I2CWhileMasterBusy
    ulDataRx[2] = I2CMasterDataGet(I2C0_MASTER_BASE);

     

    Thanks

    Anoja

  • Anoja,

    Are you waiting long enough have EEPROM write command is issued? Do you see I2C talking to EEPROM? Is the EEPROM acknowledging the data / command received?

    Regards,
    Manoj
  • Hello,

    I have just above 5ms time wait after the STOP bit in the write sequence.

    I can see I2C talking to EEPROM at random times: I wrote 1,2,3,4 at starting address and was able to read it in debugging mode. Not sure at what condition it read it.

    EEPROM is acknowledging the data/command received.

    Can you explain where all I need to wait? 

    // Initialize the receive buffer.
    for(ulindex = 0; ulindex < NUM_I2C_DATA; ulindex++)
    {
    ulDataRx[ulindex] = 0;
    }

    // Sending a EEPROM write byte packet
    I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, false);
    ulDataTx[0] = 0x00;
    ulDataTx[1] = 0x00;
    ulDataTx[2] = 0x01;
    ulDataTx[3] = 0x02;
    ulDataTx[4] = 0x03;
    ulDataTx[5] = 0x04;

    I2CMasterDataPut(I2C0_MASTER_BASE, ulDataTx[0]);
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    while(I2CMasterBusy(I2C0_MASTER_BASE)){}

    int i;
    for(i=1;i<=4;i++){
    I2CMasterDataPut(I2C0_MASTER_BASE, ulDataTx[i]);
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    while(I2CMasterBusy(I2C0_MASTER_BASE)){}
    }

    I2CMasterDataPut(I2C0_MASTER_BASE, ulDataTx[5]);
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
    while(I2CMasterBusy(I2C0_MASTER_BASE)){}

    unsigned long wait =0;
    for(wait =0; wait <= 50000; wait++);

    //Read byte

    I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, I2C_WRITE);

    // Dummy Write to set the future read address
    I2CMasterDataPut(I2C0_MASTER_BASE, 0); // address zero in the EEPROM memory
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    I2CWhileMasterBusy

    I2CMasterDataPut(I2C0_MASTER_BASE, 0); // address zero in the EEPROM memory
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    I2CWhileMasterBusy

    // Start reading the address 0x00
    I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, I2C_READ);

    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
    I2CWhileMasterBusy
    ulDataRx[0] = I2CMasterDataGet(I2C0_MASTER_BASE);

    for(i=1;i<=2;i++){
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
    I2CWhileMasterBusy
    ulDataRx[i] = I2CMasterDataGet(I2C0_MASTER_BASE);
    }

    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
    I2CWhileMasterBusy
    ulDataRx[3] = I2CMasterDataGet(I2C0_MASTER_BASE);

    Anoja

  • Anoja,

    Wait time depends upon EEPROM specs and not on I2C. You may have to check EEPROM datasheet.

    Regards,
    Manoj
  • Hi,

       I  have reduced my code to do a single byte read and write.

    I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, false);
    ulDataTx[0] = 0x00;
    ulDataTx[1] = 0xff;
    ulDataTx[2] = 0x03;

    I2CMasterDataPut(I2C0_MASTER_BASE, ulDataTx[0]);
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    while(I2CMasterBusy(I2C0_MASTER_BASE)){}

    I2CMasterDataPut(I2C0_MASTER_BASE, ulDataTx[1]);
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    while(I2CMasterBusy(I2C0_MASTER_BASE)){}

    I2CMasterDataPut(I2C0_MASTER_BASE, ulDataTx[2]);
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
    while(I2CMasterBusy(I2C0_MASTER_BASE)){}

    unsigned long wait =0;
    for(wait =0; wait <= 50000; wait++);


    //Read byte

    // Initialize the receive buffer.
    for(ulindex = 0; ulindex < NUM_I2C_DATA; ulindex++)
    {
    ulDataRx[ulindex] = 0;
    }
    I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, I2C_WRITE);

    // Dummy Write to set the future read address
    I2CMasterDataPut(I2C0_MASTER_BASE, 0); // address zero in the EEPROM memory
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
    I2CWhileMasterBusy

    I2CMasterDataPut(I2C0_MASTER_BASE, 0XFF); // address zero in the EEPROM memory
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
    I2CWhileMasterBusy

    // Start reading the address 0x00
    I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, I2C_READ);

    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
    I2CWhileMasterBusy
    ulDataRx[0] = I2CMasterDataGet(I2C0_MASTER_BASE);

     

    From the datasheet of EEPROM, the write cycle time is found to be 5ms. Please find the attachment. I am reading 0xff in any case.

  • Anoja,

    If you are trying to write 0x3 to EEPROM address 0x0. Then you need to follow these steps:-

    I2CWrite
    1) Configure I2C slave address of EEPROM into I2CSAR register
    2) Configure I2C and I2CFIFO to enable TX FIFO.
    3) Set I2CCNT = 3
    4) Write I2CDXR = 0 (A15-A8)
    5) Write I2CDXR = 0 (A7-A0) <-- Writing EEPROM address 0
    6) Write I2CDXR = 3 <-- Writing to data 3 to EEPROM (This will fill the TXFIFO)
    7) Send start bit, transmit and master mode. (I2caRegs.I2CMDR.all = 0x6E20)
    8) Wait for 5ms

    I2CRead
    1) Configure I2C slave address of EEPROM into I2CSAR register
    2) Configure I2C and I2CFIFO to enable TX FIFO.
    3) Set I2CCNT = 2
    4) Write I2CDXR = 0 (A15-A8)
    5) Write I2CDXR = 0 (A7-A0) <-- Writing EEPROM address 0
    6) Send start bit, transmit and master mode (I2caRegs.I2CMDR.all = 0x2620)
    7) Set I2CCNT = 1
    8) Send start bit, receive and master mode (I2caRegs.I2CMDR.all = 0x2C20)

    Regards,
    Manoj
  • Hi Manoj,

       I guess the steps you mentioned above is for C28 core and not for M3. I am trying to read EEPROM using M3.

    Anoja

  • Anoja,

    There is a clear flowchart explained in TRM. Please check Figure23-10. Master Receive with repeated start.

    Regards,
    Manoj
  • Flow chart helped. Thank you.