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: I2C EEPROM read

Part Number: TMS320F28027
Other Parts Discussed in Thread: MOTORWARE

Tool/software: Code Composer Studio

Hello

Good day !

I am working with F28027F and trying to store data into eeprom(ATMEL 24C04) via I2C interface .for that I use

C:\ti\motorware_1_01_00_16\sw\solutions\instaspin_foc\boards\hvkit_rev1p1\f28x\f2802xF\projects\ccs5\Example_F2802xI2C_eeprom\Example_2802xI2C_eeprom.c

Happily It worked fairly well ,but I have some questions.

  1. The things that I want is, to store 32bit(float)data into EEPROM which can be sort of this

 

address

Data

0x0000

0x23

0x0001

0x54

0x0002

0x42

0x0003

0x26

0x0004

0x34

0x0005

0x76

0x0006

0x56

0x0007

0x45

 

As shown in table 0x0000 -0x0003 is belong to one 32bit float data and from 0x0004-0x0007 is belong to another 32bit float data and etc…

How to do it ?

2. pay attention to this code..

#define I2C_SLAVE_ADDR        0x50
#define I2C_NUMBYTES          2
#define I2C_EEPROM_HIGH_ADDR  0x00
#define I2C_EEPROM_LOW_ADDR   0x30

// Global variables
// Two bytes will be used for the outgoing address,
// thus only setup 14 bytes maximum
struct I2CMSG I2cMsgOut1={I2C_MSGSTAT_SEND_WITHSTOP,
                          I2C_SLAVE_ADDR,
                          I2C_NUMBYTES,
                          I2C_EEPROM_HIGH_ADDR,
                          I2C_EEPROM_LOW_ADDR,
                          0x10, // Msg Byte 1
                          0x20  // Msg Byte 2
                          };                  

struct I2CMSG I2cMsgIn1={ I2C_MSGSTAT_SEND_NOSTOP,
                          I2C_SLAVE_ADDR,
                          I2C_NUMBYTES,
                          I2C_EEPROM_HIGH_ADDR,
                          I2C_EEPROM_LOW_ADDR
};


a.Are those (#define I2C_EEPROM_HIGH_ADDR 0x00 and #define I2C_EEPROM_LOW_ADDR 0x30) as an EEPROM Address ?
if so,then why it (I2C_EEPROM_LOW_ADDR 0x30) did not start from 0x00?!
I would be happy if you explain more about 2C_EEPROM_HIGH_ADDR and I2C_EEPROM_LOW_ADDR .

b. I got a bit confuse about the comments in that project.(
" Two bytes will be used for the outgoing address, thus only setup 14 bytes maximum)" what that supposed to mean?

if I set I2C_NUMBYTES to more than 2 I have to also set #define I2C_MAX_BUFFER_SIZE to more than 4
which makes another problem ... take a look at code in below.


// I2C Message Structure
struct I2CMSG {
  Uint16 MsgStatus;                // Word stating what state msg is in:
                                  //   I2C_MSGCMD_INACTIVE = do not send msg
                                  //   I2C_MSGCMD_BUSY = msg start has been sent,
                                  //                     awaiting stop
                                  //   I2C_MSGCMD_SEND_WITHSTOP = command to send
                                  //       master trans msg complete with a stop bit
                                  //   I2C_MSGCMD_SEND_NOSTOP = command to send
                                  //       master trans msg without the stop bit
                                  //   I2C_MSGCMD_RESTART = command to send a restart
                                  //       as a master receiver with a stop bit
  Uint16 SlaveAddress;            // I2C address of slave msg is intended for
  Uint16 NumOfBytes;            // Num of valid bytes in (or to be put in MsgBuffer)
  Uint16 MemoryHighAddr;        // EEPROM address of data associated with msg (high byte)
  Uint16 MemoryLowAddr;            // EEPROM address of data associated with msg (low byte)
  Uint16 MsgBuffer[I2C_MAX_BUFFER_SIZE];    // Array holding msg data - max that
                                              // MAX_BUFFER_SIZE can be is 4 due to
                                              // the FIFO's
};

As you can see the I2C_MAX_BUFFER_SIZE can not set to more then 4...

Uint16 MsgBuffer[I2C_MAX_BUFFER_SIZE]; // Array holding msg data - max that
// MAX_BUFFER_SIZE can be is 4 due to
// the FIFO's

please let me know how to store EEPROM  byte by byte?

and does it need to be sequential(getdata(Address = 0x0000,0x0001,0x0002,0x0003,...0xFFFF))  addressing EEPROM or we can do it Random(I need random addressing)?

thanks for attention .

Best regards.

Dave.

  • Dave,

    I hope  I have answered your questions below

    a. This was likely the Example creator's choice to show an address access and not just starting the address from 0. You can change the starting address of the write to whatever you need. the example provides the option to address a 16-bit address I2C. The _HIGH_ADDR is the upper 8 bits of the address in this case.

    b. This looks like a carry over from other devices which included a 16 byte deep FIFO. On the F2802x, there is only a 4 byte deep FIFO. The later comment is the correct one. 

    If you need to store/read more than 2 data bytes, you will need to modify the example. This might include adding another state that writes contiunous data after the word address is written to the device, then you continue by writing the data payload in another state. 

    Essentially the example is doing a random access sequential read. first the data address is written followed by a 2-byte sequential read. change the address and the length of data to read, and you have a random sequential read from any address on the eeprom.

    Thanks,
    Mark

  • dear Mark
    thanks for comment .
    I did not know that " On the F2802x, there is only a 4 byte deep FIFO." that was interesting !

    Are you sure about those two const ( I2C_EEPROM_HIGH_ADDR and I2C_EEPROM_LOW_ADDR )that are for Memory Address in EEPROM?
    Since I write two bytes(Data=0x10 ,Data=0x20) in 0x0030 Memory address and also two bytes (Data=0x30 ,Data=0x40) in 0x0032 Memory address for testing ,then I read EEPROM ( I2C_EEPROM_HIGH_ADDR and I2C_EEPROM_LOW_ADDR = 0x0030 Memory address ) something that I got was (Data=0x30 ,Data=0x40) !!! and also I read EEPROM ( I2C_EEPROM_HIGH_ADDR and I2C_EEPROM_LOW_ADDR = 0x0032 Memory address ) something that I got was (Data=0x30 ,Data=0x40) in every Memory address I got the same values!!!!

     Question 2 how single Memory address for example 0x0030 can store two bytes,

    does it go some thing like this ,Am I right ? 

    Memory address Data
    0x0030 0x10
    0x0031 0x20

    regards

    Dave.

  • I am sure, and just verified it as such.

    I programmed a few different locations on my eeprom. at address 0x30 -> 0x42, i programmed the address as data. I then jumped to another memory address (not data = address) and the results came back as expected.

    Be careful when you are setting up the test runs. If you are only modifying the # defines at the beginning of the example, the results will always read back as that is what the example does.

    Thanks,

    Mark

  • Dear Mark
    Thanks for Immediate reply :).

    Question 2 how single Memory address for example 0x0030 can store two bytes,

    does it go some thing like this ,Am I right ?

    Memory address Data
    0x0030 0x10
    0x0031 0x20

    regards

    Dave.
  • Each memory address is storing only one byte. Your table is correct. The EEPROM has the sequential read and write functions which the example takes advantage of.
  • thanks a lot dear Marks :).
    Best wishes.
    Dave.