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.

CCS/TMS320F28027: CCS/TMS320F28027: I2C EEPROM

Part Number: TMS320F28027

Tool/software: Code Composer Studio

helllo ,

good day .

a,which kind of EEPROM is needed for Example_2802xI2C_eeprom.c  Atmel(AT24c04) or microchip(93C46)?

regards

Dave

  • Hi Dave,

    I feel the example is for ONSEMI's 24WC256 that's on ezdsp board. Its an outdated part.

    Regards,
    Gautam
  • Hi,thanks dear Gautam.

    you mean I can't use AT24C08 instead of that?
  • Hi Dave,

    You would need to edit the example program. I'd suggest looking at the AT24C08 datasheet as it has a slightly different protocol than the 24WC256 for reads/writes.

    When setting up a read/write for the 24WC256 you send two 8-bit address words (HIGH and LOW addresses) before actually sending or receiving data:

        //
        // Setup number of bytes to send MsgBuffer + Address
        //
        I2caRegs.I2CCNT = msg->NumOfBytes+2;
    
        //
        // Setup data to send
        //
        I2caRegs.I2CDXR = msg->MemoryHighAddr;
        I2caRegs.I2CDXR = msg->MemoryLowAddr;
    
        for (i=0; i<msg->NumOfBytes; i++)
        {
            I2caRegs.I2CDXR = *(msg->MsgBuffer+i);
        }

    For your AT24C08, if you look at its datasheet, reads/writes only use one 8-bit address word instead of two. There may be some other caveats as well, that's just what I noticed looking at the DS.

    Best,

    Kevin

  • Dear Kevin thanks for suggestion.

    eventually I could write and read 2byte to/from EEPROM by removing  

    MemoryHighAddr form I2CA_WriteData(struct I2CMSG *msg) and Uint16 I2CA_ReadData(struct I2CMSG *msg) functions and changing  I2caRegs.I2CCNT register. 

    for I2CA_WriteData function I2caRegs.I2CCNT register is equal 3(1 address ,2 data) and for I2CA_ReadData function I2caRegs.I2CCNT register is equal 1(1 address ).

    So ,now I need to store 25 word into EEPROM ,and read them ,so to continue to work I removed for(;;) form pass and fail functions.

    to program be in main loop at all time .

    void pass()
    {
     //   asm("   ESTOP0");
     //   for(;;);
    }
    
    void fail()
    {
     //   asm("   ESTOP0");
     //  for(;;);
    }

    and also for storing 25 word I wrote

    		     //cnt initialize cnt=0
                         cnt++;
    		     I2cMsgOut1.MsgBuffer[0]=cnt;
    		     cnt++;
    		     I2cMsgOut1.MsgBuffer[1]=cnt;
                         
                         //adrs initialize adrs=0
    		     adrs++;
    		     I2cMsgOut1.MemoryLowAddr = adrs;

    if(adrs==25) {for(;;);} CurrentMsgPtr = &I2cMsgOut1; I2cMsgOut1.MsgStatus == I2C_MSGSTAT_SEND_WITHSTOP;

    so by doing that we expect to store 25 word 

     but sadly none of datas was stored.

    I got confused please help me to solve my problem ,

      // Application loop
       for(;;)
       {
    
    
                 // for making delay on every write/ read
    	     for(j=0;j<10000;j++)
    
    		     I2cMsgOut1.MsgStatus=I2C_MSGSTAT_SEND_WITHSTOP;
    		     I2cMsgOut1.SlaveAddress=I2C_SLAVE_ADDR;
    		     I2cMsgOut1.NumOfBytes=I2C_NUMBYTES;
    		     I2cMsgOut1.MemoryHighAddr=I2C_EEPROM_HIGH_ADDR;
    
    		     cnt++;
    		     I2cMsgOut1.MsgBuffer[0]=cnt;
    		     cnt++;
    		     I2cMsgOut1.MsgBuffer[1]=cnt;
    		     adrs++;
    		     I2cMsgOut1.MemoryLowAddr = adrs;
    
    		     CurrentMsgPtr = &I2cMsgOut1;
    
    		     I2cMsgOut1.MsgStatus == I2C_MSGSTAT_SEND_WITHSTOP;
    
    
          //////////////////////////////////
          // Write data to EEPROM section //
          //////////////////////////////////
          // Check the outgoing message to see if it should be sent.
          // In this example it is initialized to send with a stop bit.
          if(I2cMsgOut1.MsgStatus == I2C_MSGSTAT_SEND_WITHSTOP)
          {
             Error = I2CA_WriteData(&I2cMsgOut1);
             // If communication is correctly initiated, set msg status to busy
             // and update CurrentMsgPtr for the interrupt service routine.
             // Otherwise, do nothing and try again next loop. Once message is
             // initiated, the I2C interrupts will handle the rest. Search for
             // ICINTR1A_ISR in the i2c_eeprom_isr.c file.
             if (Error == I2C_SUCCESS)
             {
                CurrentMsgPtr = &I2cMsgOut1;
                I2cMsgOut1.MsgStatus = I2C_MSGSTAT_WRITE_BUSY;
             }
          }  // end of write section
    
    // for making delay on every write/ read
    for(j=0;j<100000;j++){}
    
     
        I2cMsgIn1.MsgStatus=I2C_MSGSTAT_SEND_NOSTOP;
         I2cMsgIn1.SlaveAddress=I2C_SLAVE_ADDR;
         I2cMsgIn1.NumOfBytes=I2C_NUMBYTES;
        I2cMsgIn1.MemoryHighAddr=I2C_EEPROM_HIGH_ADDR;
    
       //It will read the previous Data from EEPROM
        I2cMsgIn1.MemoryLowAddr = adrs-1;
    
          ///////////////////////////////////
          // Read data from EEPROM section //
          ///////////////////////////////////
          // Check outgoing message status. Bypass read section if status is
          // not inactive.
          if (I2cMsgOut1.MsgStatus == I2C_MSGSTAT_INACTIVE)
          {
             // Check incoming message status.
             if(I2cMsgIn1.MsgStatus == I2C_MSGSTAT_SEND_NOSTOP)
             {
                // EEPROM address setup portion
                while(I2CA_ReadData(&I2cMsgIn1) != I2C_SUCCESS)
                {
                   // Maybe setup an attempt counter to break an infinite while
                   // loop. The EEPROM will send back a NACK while it is performing
                   // a write operation. Even though the write communique is
                   // complete at this point, the EEPROM could still be busy
                   // programming the data. Therefore, multiple attempts are
                   // necessary.
                }
                // Update current message pointer and message status
                CurrentMsgPtr = &I2cMsgIn1;
                I2cMsgIn1.MsgStatus = I2C_MSGSTAT_SEND_NOSTOP_BUSY;
             }
    
             // Once message has progressed past setting up the internal address
             // of the EEPROM, send a restart to read the data bytes from the
             // EEPROM. Complete the communique with a stop bit. MsgStatus is
             // updated in the interrupt service routine.
             else if(I2cMsgIn1.MsgStatus == I2C_MSGSTAT_RESTART)
             {
                // Read data portion
                while(I2CA_ReadData(&I2cMsgIn1) != I2C_SUCCESS)
                {
                   // Maybe setup an attempt counter to break an infinite while
                   // loop.
                }
                // Update current message pointer and message status
                CurrentMsgPtr = &I2cMsgIn1;
                I2cMsgIn1.MsgStatus = I2C_MSGSTAT_READ_BUSY;
             }
           }  // end of read section
    
       }   // end of for(;;)
    }   // end of main
    

     I need to store 25 word into EEPROM ,and read them, I really need your help to solve my problem .

    Regards.


    Dave.


  • Hi Dave,

    By default this example has interrupts enabled which end up affecting the message status (I2cMsgIn1.MsgStatus) and flow of the program. Do you still have these interrupts enabled?

    I think it would be good to take a step back and understand how this example program works. Then you can change/edit it to fit your application as it looks like you still have a lot of remnants of the original example. Please look at one of my prior E2E threads that explains the example:

    e2e.ti.com/.../2627724

    Understanding the example better and checking the datasheet of your specific EEPROM device should help you with your specific project requirements. Also, do you have a logic analyzer handy? Using one to check the I2C waveforms is very helpful for this sort of debug.

    Hope this helps,
    Kevin
  • thanks dear Kevin

    I am going to see e2e.ti.com/.../2627724

    then I will tell you if my issue is solved or not .

    regards

    Dave.