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.

TMS320F28379D: I2C Repeated Start Over Write Problem

Part Number: TMS320F28379D

Tool/software:

Hi,

I am currently working on programming 24CSM01  EEPROM via I2C. You can find my configuration and send/read functions below. When I read Security Register of EEPROM, firstly I need to send write command with address then I send read command to EEPROM. At Write Command I do not send STOP condition because EEPROM wants start condition again at read command. If I don't put a delay between write and read sequence, MCU only sends read command. If I put delay between write and read sequence, MCU sends write command and then receives all datas. I do not want to put a delay between them, how can i check that transmit is completed before read command?

void I2C_Init(s_I2C_Handler_t* p_s_I2C_Handler) {
	I2C_initController(p_s_I2C_Handler->I2C_BASE_U32, DEVICE_SYSCLK_FREQ, p_s_I2C_Handler->I2C_BAUDRATE_U32, p_s_I2C_Handler->e_I2C_DUTYCYCLE);
  I2C_setBitCount(p_s_I2C_Handler->I2C_BASE_U32, p_s_I2C_Handler->e_I2C_BITCOUNT_U32);
  I2C_setEmulationMode(p_s_I2C_Handler->I2C_BASE_U32, I2C_EMULATION_FREE_RUN);
}

void I2C_Interrupt_Init(s_I2C_Handler_t* p_s_I2C_Handler, I2C_TxFIFOLevel e_tx_fifolevel, I2C_RxFIFOLevel e_rx_fifolevel) {
  I2C_clearInterruptStatus(p_s_I2C_Handler->I2C_BASE_U32, I2C_INT_RXFF | I2C_INT_TXFF);
	I2C_setFIFOInterruptLevel(p_s_I2C_Handler->I2C_BASE_U32, e_tx_fifolevel, e_rx_fifolevel);
  I2C_enableInterrupt(p_s_I2C_Handler->I2C_BASE_U32, I2C_INT_STOP_CONDITION | I2C_INT_REG_ACCESS_RDY);
}

void I2C_Start(s_I2C_Handler_t* p_s_I2C_Handler) {
  I2C_enableModule(p_s_I2C_Handler->I2C_BASE_U32);
}

void I2C_FIFO_Enable(s_I2C_Handler_t* p_s_I2C_Handler) {
  I2C_enableFIFO(p_s_I2C_Handler->I2C_BASE_U32);
}

void I2C_FIFO_Disable(s_I2C_Handler_t* p_s_I2C_Handler) {
  I2C_disableFIFO(p_s_I2C_Handler->I2C_BASE_U32);
}

void I2C_SendMessage(s_I2C_Handler_t* p_s_I2C_Handler, uint16_t slaveAddress_u16, const uint16_t* p_msgbuffer_u16, uint16_t length_u16) {
	uint16_t i2c_message_index_u16 = 0u;
  while(I2C_isBusBusy(p_s_I2C_Handler->I2C_BASE_U32)) {
  }
	I2C_FIFO_Disable(p_s_I2C_Handler);
	I2C_FIFO_Enable(p_s_I2C_Handler);
	I2C_setTargetAddress(p_s_I2C_Handler->I2C_BASE_U32, slaveAddress_u16);
  I2C_setConfig(p_s_I2C_Handler->I2C_BASE_U32, I2C_MASTER_SEND_MODE | p_s_I2C_Handler->e_I2C_ADDRESSMODE);
  I2C_setDataCount(p_s_I2C_Handler->I2C_BASE_U32, length_u16);
  for(i2c_message_index_u16 = 0u; i2c_message_index_u16 < length_u16; i2c_message_index_u16++) {
    I2C_putData(p_s_I2C_Handler->I2C_BASE_U32, p_msgbuffer_u16[i2c_message_index_u16]);
  }
  I2C_sendStartCondition(p_s_I2C_Handler->I2C_BASE_U32);

}

void I2C_ReadMessage(s_I2C_Handler_t* p_s_I2C_Handler, uint16_t slaveAddress_u16, uint16_t* p_readmsgbuffer_u16, uint16_t length_u16) {
	uint16_t i2c_message_index_u16 = 0u;
	I2C_FIFO_Disable(p_s_I2C_Handler);
	I2C_FIFO_Enable(p_s_I2C_Handler);
	I2C_setTargetAddress(p_s_I2C_Handler->I2C_BASE_U32, slaveAddress_u16);
  I2C_setConfig(p_s_I2C_Handler->I2C_BASE_U32, I2C_MASTER_RECEIVE_MODE | p_s_I2C_Handler->e_I2C_ADDRESSMODE);
  I2C_setDataCount(p_s_I2C_Handler->I2C_BASE_U32, length_u16);
  I2C_sendStartCondition(p_s_I2C_Handler->I2C_BASE_U32);
  for(i2c_message_index_u16 = 0u; i2c_message_index_u16 < length_u16; i2c_message_index_u16++) {
  	*(p_readmsgbuffer_u16 + i2c_message_index_u16) = I2C_getData(p_s_I2C_Handler->I2C_BASE_U32);
  }

}

void I2C_StopTransmit(s_I2C_Handler_t* p_s_I2C_Handler) {
  I2C_sendStopCondition(p_s_I2C_Handler->I2C_BASE_U32);
  while(I2C_getStopConditionStatus(p_s_I2C_Handler->I2C_BASE_U32)!=0);
  while(I2C_getStatus(p_s_I2C_Handler->I2C_BASE_U32) & I2C_STS_TX_EMPTY != I2C_STS_TX_EMPTY);
  I2C_sendStopCondition(p_s_I2C_Handler->I2C_BASE_U32);
}

void I2C_StopReceive(s_I2C_Handler_t* p_s_I2C_Handler) {
  I2C_sendStopCondition(p_s_I2C_Handler->I2C_BASE_U32);
  while(I2C_getStopConditionStatus(p_s_I2C_Handler->I2C_BASE_U32)!=0);
  I2C_sendStopCondition(p_s_I2C_Handler->I2C_BASE_U32);
}

void eeprom24Csm01ReadSecurityRegister(s_I2C_Handler_t* psI2CHandler, const uint16_t hwSlaveAddressU16, const uint16_t addressU16, uint16_t* pdataBufferU16, const uint16_t lengthU16) {
	uint16_t writeBufferU16[2u] = {0u};
	if(addressU16 > 255u)
		writeBufferU16[0] = EEPROM_SECURITY_READ_ADDRESS | 0x01;
	else
		writeBufferU16[0] = EEPROM_SECURITY_READ_ADDRESS| 0x00;
	writeBufferU16[1] = addressU16 & 0xFF;
	I2C_SendMessage(psI2CHandler, EEPROM_24CSM01_SECURITY_COMMAND | hwSlaveAddressU16, writeBufferU16, 2u);
//	DELAY_US(200);
    I2C_ReadMessage(psI2CHandler, EEPROM_24CSM01_SECURITY_COMMAND | hwSlaveAddressU16, pdataBufferU16, lengthU16);
	I2C_StopReceive(psI2CHandler);
}

without delay:

with delay