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.

TMS320F28075: TMS320F28075 iic

Part Number: TMS320F28075
Other Parts Discussed in Thread: CONTROLSUITE

I am using the  IIc peripheral to write some message to a EEPROM : M24C01 .

I have some confused places in the example program:D:\controlSUITE\device_support\F2807x\v210\F2807x_examples_Cpu1\i2c_eeprom\cpu01

Could you tell me why  a memory address should be writed twice ? 

I2cbRegs.I2CDXR.all = msg->MemoryHighAddr;
I2cbRegs.I2CDXR.all = msg->MemoryLowAddr;

my email is  fylxakj@163.com 

  • Hi,

    yuanling fang said:
    Could you tell me why  a memory address should be writed twice ? 

    Depends on the slave device, you can refer the following code too:

    //////////////////////////
    // Write data to EEPROM //
    //////////////////////////
    //I2C_SLAVE_ADDR = 0x50 address of the EEPROM
    //I am writing 'h','e','l','l','o' to the EEPROM and then read it back later
    //I2C_NUMBYTES = 5
    //[MemoryHighAddr:MemoryLowAddr] -Address within the eeprom where you want to read/write
    //Data[] has the word 'hello' and RxdData[] will store data read from the eeprom
       I2caRegs.I2CSAR = I2C_SLAVE_ADDR; 			//Set slave address
       I2caRegs.I2CCNT = I2C_NUMBYTES + 2; 			//Set count to 5 characters plus 2 address bytes
       I2caRegs.I2CDXR = MemoryHighAddr;			//Send eeprom high address            
       I2caRegs.I2CMDR.bit.TRX = 1; 				//Set to Transmit mode
       I2caRegs.I2CMDR.bit.MST = 1; 				//Set to Master mode
       I2caRegs.I2CMDR.bit.FREE = 1;				//Run in FREE mode
       I2caRegs.I2CMDR.bit.STP = 1; 				//Stop when internal counter becomes 0
       I2caRegs.I2CMDR.bit.STT = 1; 				//Send the start bit, transmission will follow
       while(I2caRegs.I2CSTR.bit.XRDY == 0){}; 		//Do nothing till data is shifted out
       I2caRegs.I2CDXR = MemoryLowAddr;  			//Send eeprom low address
       
       for(i = 0; i < I2C_NUMBYTES; i++){
       	while(I2caRegs.I2CSTR.bit.XRDY == 0){}; 	//Do nothing till data is shifted out
       	I2caRegs.I2CDXR = Data[i]; 					//Send out the message
       } 
    //////////////////////////
    // Read data from EEPROM//
    //////////////////////////
       I2caRegs.I2CSAR = I2C_SLAVE_ADDR; 			//Set slave address
       I2caRegs.I2CCNT = 2; 						//Set count to 2 address bytes
       I2caRegs.I2CDXR = MemoryHighAddr;			//Send eeprom high address            
       I2caRegs.I2CMDR.bit.TRX = 1; 				//Set to Transmit mode
       I2caRegs.I2CMDR.bit.MST = 1; 				//Set to Master mode
       I2caRegs.I2CMDR.bit.FREE = 1;				//Run in FREE mode
       I2caRegs.I2CMDR.bit.STP = 0; 				//Dont release the bus after Tx
       I2caRegs.I2CMDR.bit.STT = 1; 				//Send the start bit, transmission will follow
       
       while(I2caRegs.I2CSTR.bit.XRDY == 0){}; 		//Do nothing till data is shifted out
       I2caRegs.I2CDXR = MemoryLowAddr; 			//Send eeprom low address
       I2caRegs.I2CCNT = I2C_NUMBYTES;				//read 5 bytes from eeprom
       I2caRegs.I2CMDR.bit.TRX = 0; 				//Set to Recieve mode
       I2caRegs.I2CMDR.bit.MST = 1; 				//Set to Master mode
       I2caRegs.I2CMDR.bit.FREE = 1;				//Run in FREE mode
       I2caRegs.I2CMDR.bit.STP = 1; 				//Stop when internal counter becomes 0
       I2caRegs.I2CMDR.bit.STT = 1; //Repeated start, Reception will follow
       for(i = 0; i < I2C_NUMBYTES; i++){
       	while(I2caRegs.I2CSTR.bit.RRDY == 0){}; 	//I2CDRR not ready to read?
       	RxdData[i] = I2caRegs.I2CDRR;
       }

    Regards,

    Gautam