嗨,对话框,
I don't find a sample to use the Restart signal in demo project.
By referencing the Html help file, I found there is a function called 'hw_i2c_set_restart_enabled '. Is this the only one key step for generate Restart signal?
当用户按照“写入 - 读取”操作序列操作I2C时,硬件会生成重启信号吗?像这样:
Start device_addr(w) A reg_addr Restart device_addr(r) A data A data ...Stop
Another question is the hw i2c driver, in the file hw_i2c.c:
in functiong hw_i2c_read_buffer_sync, there is a while loop to repeat hw_i2c_read_byte_trigger(id):
while (rr < len && hw_i2c_is_tx_fifo_not_full(id)) {
hw_i2c_read_byte_trigger(ID);
rr ++;
}
what's the usage of these lines of code?
谢谢
James
Device:
Can Dialog help me?
I want to operate I2C like this :
--------------------------------
Start
发送device_addr(w)
Send Reg_addr
Restart
Send Device_addr(R)
Read data
....
Stop
-------------------------------
How to init the HW I2C bus and generate the 'Restart' signal?
谢谢
Hi jamesleo-konka,
The hw_i2c_set_restart_enable() just enables the ability for the I2C module to issue a restart signal (just sets the I2C_RESTART_EN bit), you dont control the restart from the application, the I2C module will send the restart signal without doing anything explicitly, also there is no application using that function since the I2C_RESTART_EN is enabled by default (the reset value is 0x1) and yes the sequence that you mention should occur since the restart enabled is active by default. So have you tried an I2C transaction and you dont see this happening on your analyser ? Since i am able to do this without having to set something explicitly, since like i ve mentioned above its a default functionallity.
Regarding the code that you mention, the code sets the read bit in the I2C_DATA_CMD_REG in order for the I2C module to provide clock to the slave device and the slave device to spit out its data, so for every time the hw_i2c_read_byte_trigger() gets executes the I2C module produces the clock cycles in order to read one byte at the timer from the slave.
谢谢MT_dialog
Hi, MT_Dialog,
对不起,我没有逻辑分析仪。
I'm studying the sample code of demo_i2c.c and trying to migrating my I2C code to Smartsnippets.
demo_i2c使用hw_i2c_write_byte,hw_i2c_write_buffer_sync / hw_i2c_read_buffer_sync读取fm75的reg。
Reading FM75's reg like this:
START (automatically) // --> how to start a new I2C operation?
Divece address will be transmited automatically (you need to set it before begin I2C )
hw_i2c_write_byte (Register address)
hw_i2c_read_buffer_sync/hw_i2c_write_buffer_sync (read/write a number of data)
STOP(automatically)
I think this procedure will not generate RESTART signal.
How to implement my I2C procedure include a RESTART signal? --- write reg_address attempt to read and then switch to read mode (Slave read address), read data...
-------------------------------
Start
发送device_addr(w)
Send Reg_addr
Restart
Send Device_addr(R)
Read data
....
Stop
-------------------------------
谢谢
Continue:
Refering to the manual of 24LC256, we can see the Random Read sequence of I2C is:
Start
Send Slave address(control byte,Write)
Send Memory address (2 bytes)
Start(Restart)
Send Slave address(control byte,Read)
Read data
the operation code in demo_i2c.c is like this:
set_target_address(EEPROM_ADDRESS);
resource_acquire(RES_MASK(RES_ID_I2C1), RES_WAIT_FOREVER);
hw_i2c_write_buffer_sync(HW_I2C1, addr, sizeof(addr), &abrt_src, HW_I2C_F_NONE); //-> does this generate START ,and send Slave address ?
hw_i2c_read_buffer_sync(hw_i2c1,read_buffer,sizeof(read_buffer) - 1,&abrt_src,hw_i2c_f_none);// - >方向已更改(写入 - >读取),此问题是否发出RESTART命令并发送从属地址(读取)?然后从EEPROM读取数据?
Many steps seems be hided by I2C controller... if the actions above is true.
Hi Jamesleo-konka,
As mentioned, the prefered usage of the peripherals is through the adapters, so in order to start an I2C transaction set the peripheral and the I2C adapter and start the transaction through the adapter and not by using the low level drivers. Regarding the restart signal, as mentioned its something the the I2C module will do, since the I2C_RESTART_EN is active, so it is something that the module will do and you will not be able to force it.
Regarding the functions that you have posted,
hw_i2c_write_buffer_sync() function, that will force the module to write the address of the slave on the bus with a write byte and then the address of the register that you would like to read, and in the case of the driver is 0x00 0x00.
hw_i2c_read_buffer_sync() function, this will start the reading procedure and since the direction is changed (from a read to write) the I2C module will issue a restart condition send the slave's address with the read bit and start reading data from the slave.
谢谢MT_dialog