qustion on i2c_write_byte

2 posts / 0 new
Last post
zhangxw211
Offline
Last seen:5 years 2 months ago
加入:2015-04-14 08:15
qustion on i2c_write_byte

In the function i2c_eeprom_write_byte, it wait the eeprom ready at first. In i2c_wait_until_eeprom_ready(); it repeat if not ACK. However, it just sends 0x08 on the i2c data bus instead of device address. there should not any AKC on the bus. and then it will in a infinite loop here.

And when I step into SEND_I2C_COMMAND(0x08), the run button is gray, it seems the cpu is halted. and then I click the stop button the pointer is still at SEND_I2C_COMMAND.

Dose anyone know how to solve this problem?

void i2c_eeprom_write_byte(uint32_t address, uint8_t wr_data)
{
i2c_wait_until_eeprom_ready();
i2c_send_address(address);

WAIT_WHILE_I2C_FIFO_IS_FULL(); // Wait if I2C Tx FIFO is full
SEND_I2C_COMMAND(wr_data & 0xFF); // Send write data
WAIT_UNTIL_I2C_FIFO_IS_EMPTY(); // Wait until Tx FIFO is empty

WAIT_UNTIL_NO_MASTER_ACTIVITY(); // wait until no master activity
}

void i2c_wait_until_eeprom_ready(void)
{
uint16_t abort_SR_Status; // TX Abort Source Register
// Polling until EEPROM ACK to detect busy period
do {
SEND_I2C_COMMAND(0x08); // Make a dummy access
WAIT_UNTIL_I2C_FIFO_IS_EMPTY(); // Wait until Tx FIFO is empty
WAIT_UNTIL_NO_MASTER_ACTIVITY(); // Wait until no master activity
abort_SR_Status = GetWord16(I2C_TX_ABRT_SOURCE_REG); // Read the Tx abort source register
GetWord16(I2C_CLR_TX_ABRT_REG); // Clear the Tx abort flag
} while( (abort_SR_Status & ABRT_7B_ADDR_NOACK) != 0 ); // Repeat if not ACK
}

Keywords:
Device:
kenneth.er
Offline
Last seen:4 years 9 months ago
加入:2015-09-03 15:31
Hi,

Hi,

The SEND_I2C_COMMAND() simply writes into the DA14580 register, so it should not halt on that line for no reason. Maybe you want to double check your hardware connections?

也在SEND_I2C_COMMAND()。如果它执行utes properly, it will send the slave address together with the data (0x08). The code is correct, so my recommendation remains the same as before. Check the hardware connection of your DA14580 chip and the connection to your EEPROM. If possible, observe the I2C bus on an oscilloscope.
Good luck.