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 EEPROM 编程 ACK 问题

Guru**** 2343770 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1501768/tms320f28379d-i2c-eeprom-programming-ack-problem

部件号:TMS320F28379D

工具/软件:

您好!

我目前正在  通过 I2C 对24CSM01 EEPROM 进行编程。 您可以在下面找到我的配置和发送/读取函数。 对于读取/写入、我设置了从器件地址0x50并发送地址、但 MCU 未从 EEPROM 接收到确认。 问题可能是什么?  

A0:0

A1:0

24CSM01数据表

typedef struct {
	volatile const uint32_t I2C_BASE_U32;
	const uint32_t I2C_BAUDRATE_U32;
	const I2C_DutyCycle e_I2C_DUTYCYCLE;
	const I2C_BitCount e_I2C_BITCOUNT_U32;
	const I2C_EmulationMode e_I2C_EMULATIONMODE;
	const I2C_AddressMode e_I2C_ADDRESSMODE;
	s_I2C_Com_Handler_t s_Com;
}s_I2C_Handler_t;

s_I2C_Handler_t s_I2CB_Handler = {
		.I2C_BASE_U32 = I2CB_BASE,
		.I2C_BAUDRATE_U32 = 100000U,
		.e_I2C_BITCOUNT_U32 = I2C_BITCOUNT_8,
		.e_I2C_DUTYCYCLE = I2C_DUTYCYCLE_50,
		.e_I2C_EMULATIONMODE = I2C_EMULATION_FREE_RUN,
		.e_I2C_ADDRESSMODE = I2C_ADDR_MODE_7BITS
};

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);

  //
  // Enable stop condition and register-access-ready interrupts
  //
  I2C_enableInterrupt(p_s_I2C_Handler->I2C_BASE_U32, I2C_INT_STOP_CONDITION |
                      I2C_INT_REG_ACCESS_RDY);

  //
  // FIFO configuration
  //
  I2C_enableFIFO(p_s_I2C_Handler->I2C_BASE_U32);
  I2C_clearInterruptStatus(p_s_I2C_Handler->I2C_BASE_U32, I2C_INT_RXFF | I2C_INT_TXFF);
  //to do
//  I2C_clearInterruptStatus(p_s_I2C_Handler->I2C_BASE_U32, I2C_INT_ARB_LOST | I2C_INT_NO_ACK);
//  I2C_enableInterrupt(p_s_I2C_Handler->I2C_BASE_U32, I2C_INT_ADDR_SLAVE | I2C_INT_ARB_LOST | I2C_INT_NO_ACK | I2C_INT_STOP_CONDITION);

  //
  // Configuration complete. Enable the module.
  //
  I2C_enableModule(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) {
	static uint16_t i2c_message_index_u16 = 0u;
	I2C_setTargetAddress(p_s_I2C_Handler->I2C_BASE_U32, slaveAddress_u16);
  while(I2C_isBusBusy(p_s_I2C_Handler->I2C_BASE_U32))  {
  }
  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_setConfig(p_s_I2C_Handler->I2C_BASE_U32, I2C_MASTER_SEND_MODE | p_s_I2C_Handler->e_I2C_ADDRESSMODE);
  I2C_sendStartCondition(p_s_I2C_Handler->I2C_BASE_U32);
  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);
	DELAY_US(500);
}

void I2C_ReadMessage(s_I2C_Handler_t* p_s_I2C_Handler, uint16_t slaveAddress_u16, uint16_t* p_readmsgbuffer_u16, uint16_t length_u16) {
	static uint16_t i2c_message_index_u16 = 0u;
	I2C_setTargetAddress(p_s_I2C_Handler->I2C_BASE_U32, slaveAddress_u16);
  I2C_setDataCount(p_s_I2C_Handler->I2C_BASE_U32, length_u16);
  I2C_setConfig(p_s_I2C_Handler->I2C_BASE_U32, I2C_MASTER_RECEIVE_MODE | p_s_I2C_Handler->e_I2C_ADDRESSMODE);
  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);
  }
  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);
}

Yasin