07-29-2015 11:56 PM
Hi,
I want write I2c code for 24 bit register address and 32 bit data width in verilog ,can any one help me?
Thanks
Sunitha
07-30-2015 06:19 AM
What are you trying to do with this code? Do you need master code to connect with an external slave device? Or do you have an external master and want the FPGA to be the slave device?
I2C is a byte-oriented protocol. There are different ways to handle wider register address, but it is unusual to have wider data. Do you have a specification for the external device you will be communicating with?
08-04-2015 04:18 AM
Thanks for reply,
Yes i am connecting SRIO switch with FPGA.Switch has internal registers with 24 bit register address and 32 bit data.
And FPGA will acts as Master and Switch will act as slave mode.
So to write those registers i want I2c master code for 24 bit register address and 32 bit data,Can please help me?
Regards
Sunitha
08-04-2015 05:20 AM
It would help to have the data sheet for the SRIO switch you're using. The I2C bus defines a byte-based transfer mechanism with either 7 or 10 bit slave addressing. Most IC's use a 7-bit slave address for the device. Internal addressing ("register address") is handled as a simple write, where the first byte after the device address starts the internal address. For more than 8-bit internal addressing, you would send more address bytes, followed by data to write. In order to read, you would only send the internal address bytes, then start a read operation, either by issuing a stop followed by a start or using a "repeated start." Most I2C slaves respond to either mechanism, but I have seen some, notably chips from Analog Devices, which require the repeated start for reads.
As a starting point I have attached a simple I2C master for accessing registers in slaves using a 7-bit device address, 8-bit internal register address, and 8-bit register data. You could extend this to 24-bit addressing and 32-bit data by adding additional bytes. Note that you can't just make the "bytes" 24 or 32 bits. Each byte is followed by an acknowledge cycle and needs to be transmitted independently. You'll need to look at the data sheet for your device to determine the correct byte order for data or address larger than 8 bits (i.e. LSB first or MSB first).
08-10-2015 12:02 AM
HI
Thanks for your reply,
Did u work in this code?
Actually i have written Test bench with
sys_clock=100Mhz
active low Reset
wr_ctrl=1
But even state is also not changing,It is running only one iteration of timer(330 to 0).did i miss anything in testbench?
Thanks
Sunitha
08-10-2015 02:02 PM
Since you didn't post your test bench it's hard to say what you might have missed. Here's a simple one with no slave attached that shows what happens when you start up, and then attempts a write. The status at the end will show 6000 hex indicating that there was no acknowledge pulse from the slave on either the address or data cycles.
08-11-2015 12:15 AM
Hi,
Thanks for your reply,
If i want change ctrl_data with
7 bit slave address
24 bit register address
32 bit data width
whare i have to modify in this code?can you please tell me,its urgent require for me
Regards
sunitha
08-11-2015 10:38 PM
Hi,
Thanks for your reply,
If i want change ctrl_data with
7 bit slave address
24 bit register address
32 bit data width
whare i have to modify in this code?can you please tell me,its urgent require for me
Regards
sunitha
07-06-2018 01:14 AM
Hi,
I want write I2c code in verilog ,can any one help me?
Thanks,
Arun .
10-31-2018 02:00 AM
01-11-2019 12:01 AM
can you please share the specification document.
01-11-2019 06:22 AM
The I2C specification is available here
01-16-2019 10:51 PM
can you please share the i2c slave code.
01-17-2019 06:43 PM
I shared the code some time ago in this thread. It's attached to the post.
01-21-2019 01:53 AM
can you please share the testbench in which both slave and master should be attached. I was trying second data transfer format as per below mentioned it is not working.
Possible data transfer formats are:
• Master-transmitter transmits to slave-receiver. The transfer direction is not changed
(see Figure 11). The slave receiver acknowledges each byte.
• Master reads slave immediately after first byte (see Figure 12). At the moment of the
first acknowledge, the master-transmitter becomes a master-receiver and the
slave-receiver becomes a slave-transmitter. This first acknowledge is still generated
by the slave. The master generates subsequent acknowledges. The STOP condition
is generated by the master, which sends a not-acknowledge (A) just before the STOP
condition.
• Combined format (see Figure 13). During a change of direction within a transfer, the
START condition and the slave address are both repeated, but with the R/W bit
reversed. If a master-receiver sends a repeated START condition, it sends a
not-acknowledge (A) just before the repeated START condition
01-22-2019 04:33 AM
can anyone explain me why the below lines are used in i2c_master code?
if (ctrl_reg[31]) // reading requires subaddr write then data read
if (wr_cyc)
shift_reg <= {ctrl_reg[23:17],1'b0,1'b1,ctrl_reg[15:8],1'b1,ctrl_reg[30],7'b0,1'b0};
else
shift_reg <= {ctrl_reg[23:17],1'b1,1'b1,8'hff,1'b1,8'b0,1'b0};
06-03-2020 03:28 PM
For some reason, when I run the i2c_master and i2c_master_tb you attached, my waveform stop changing number after status[31:0] hits 80000000 and SDA remains zero after falling at the end of status[31:0] = 0. Are there any other steps that is required to run the waveform you showed?
Also, how do I test "read" with the testbench?
Thank you!
10-24-2020 12:03 AM
can you please share i2c master and slave verilog codes
10-24-2020 12:05 AM
can you please share i2c master and slave codes
10-24-2020 02:40 AM
10-24-2020 11:59 PM
can anyone explain me how prescale values are select for scl generation.
and also explain me below two lines and why 10'b11 value taken
modulus <= i_clk_div_factor[10:1] - 10'b11;
count_eq_modby2 <= (count == modulus[8:0]);
10-25-2020 12:20 PM
10-26-2020 12:42 AM
Thanks for your reply