Goodmorning,
I'm studing i2c eeprom library of Dialog SDK to know if I can use it to control an I2C display module.
I have some questions...
1 - Slave address of I2C_TAR_REG register, is send automatically by the hardware only the first time that I write on I2C_DATA_CMD_REG register?
2 - Why i2c_wait_until_eeprom_ready function send 0x08 data (SEND_I2C_COMMAND(0x08))? Why just 0x08?
3 - Why i2c_eeprom_read_byte first send address (i2c_send_address(address)) and after set R/W bit to 1 (SEND_I2C_COMMAND(0x0100))? R/W should not be entered in the slave address byte? If the previous bits written inside I2C_DATA_CMD_REG by i2c_send_address have not yet been sent, 0x0100 don't overwrite those bits?
Thanks
Device:
Hi giuseppe,
1) Yes, you set the address of the i2c device with the i2c_init and this sends the address of the device when accessing the bus.
2) Its just a dummy byte in order to check if the eeprom is operational.
3) You have to write the address of the register of the module you that you want read, so you must perform a write, and then you must perform a read in order to get the data from the slave. If you check tha bytes that are sent you should see the [device_address + write] [register address] [device_address + read][read_byte_from_module]. The data are going through a FIFO and then to the as soon as you write the I2C_DATA_CMD_REG.
Thanks MT_dialog
if the device address is send automatically only the first time that I2C_DATA_CMD_REG was writed (SEND_I2C_COMMAND()), in the read procedure what instruction send the second device address byte in the sequential below?
[device_address + write] [register address][device_address + read](read_byte_from_module)
uint8_t i2c_eeprom_read_byte(uint32_t address)
{
i2c_wait_until_eeprom_ready();
i2c_send_address(address);
WAIT_WHILE_I2C_FIFO_IS_FULL(); // Wait if Tx FIFO is full
SEND_I2C_COMMAND(0x0100); // Set R/W bit to 1 (read access)
WAIT_UNTIL_I2C_FIFO_IS_EMPTY(); // Wait until I2C Tx FIFO empty
WAIT_FOR_RECEIVED_BYTE(); // Wait for received data
return (0xFF & GetWord16(I2C_DATA_CMD_REG)); // Get received byte
}
Thanks
Hi guiseppe,
The SEND_I2C_COMMAND(0x100); sends the read command with the device address. Since if you want to perform a read or write command you have to send the address of your device when writing a 1 (in the I2C_DATA_CMD_REG in order to perform a read) the module will send the address of your device again. To sum up since you are switching operations from read to write or the opposite the module will re-send the device address as the I2C protocol indicates.
Thanks MT_dialog
Ok, then hardware automatically sends device address byte only when I switching from read operations to write opertions and vice versa.
And in the previus example, if I change the SEND_I2C_COMMAND(0x0100) value with an other value but always with the R/W bit set to 1, for example 0x1FF, SEND_I2C_COMMAND(0x01FF), perform it a correct reading anyway?
Hi giuseppe,
Yes, even if you right 0x1FF it should perform ok.
Thanks MT_dialog
Sometimes the code goes in loop on WAIT_UNTIL_I2C_FIFO_IS_EMPTY();
Hi giuseppe,
I suppose that the 580 doesn't get anything from the slave, if there is no ACK from the slave the master will keep trying to communicate with the slave and get no response. Also check the status of your lines when that happens, to see if the da is sending any data and the slave doesn't reply or if the slave keeps the line occupied and the 580 cant sent anything so its keeping the Tx FIFO occupied.
Thanks MT_dialog
What triggers the sending of the stop bit ?
Hi taylorjw,
I dont get what you mean, the stop condition will be generated when the transmition is over, if there is no ack, from the slave side, for the transaction it means that either there are no data to send or that the I2C slave device isn't ready for the transfer.
Thanks MT_dialog