Radical Computer Technologies
Interfaces / entity

radif_reg_to_i2c_master

Documentation version: 0.2.1 / Subpackage: radif_i2c / Source package: radif

Register-controlled I2C master. Launches one-byte I2C read or write transactions from a RADIF register interface with programmable SCL timing.

Use Cases

Block Diagram

radif_reg_to_i2c_master radhdl entity clk rstn reg_wr_addr reg_rd_addr reg_wr_en reg_rd_en reg_data_in i2c_scl_i i2c_sda_i reg_data_out reg_wr_rdy reg_rd_rdy reg_wr_valid reg_rd_valid reg_error i2c_scl_oen i2c_sda_oen
VHDL Include And Instantiation Template

File Header

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

library radhdl;
-- Direct entity instantiation below does not require importing the entity name.
use radhdl.interfaces.all;
-- Narrower alternative: use radhdl.interfaces_i2c.all;

Component Declaration

component radif_reg_to_i2c_master is
  generic (
    DATA_WIDTH : positive := 32;
    REG_ADDR_WIDTH : positive := 16;
    DEFAULT_SCL_DIV : natural := 124;
    VENDOR_TAG : string := "GENERIC";
    PRODUCT_SERIES_TAG : string := "GENERIC"
  );
  port (
    clk : in std_logic;
    rstn : in std_logic;
    reg_wr_addr : in std_logic_vector(REG_ADDR_WIDTH - 1 downto 0);
    reg_rd_addr : in std_logic_vector(REG_ADDR_WIDTH - 1 downto 0);
    reg_wr_en : in std_logic;
    reg_rd_en : in std_logic;
    reg_data_in : in std_logic_vector(DATA_WIDTH - 1 downto 0);
    reg_data_out : out std_logic_vector(DATA_WIDTH - 1 downto 0);
    reg_wr_rdy : out std_logic;
    reg_rd_rdy : out std_logic;
    reg_wr_valid : out std_logic;
    reg_rd_valid : out std_logic;
    reg_error : out std_logic;
    i2c_scl_i : in std_logic;
    i2c_sda_i : in std_logic;
    i2c_scl_oen : out std_logic;
    i2c_sda_oen : out std_logic
  );
end component;

Direct Entity Instantiation

u_radif_reg_to_i2c_master : entity radhdl.radif_reg_to_i2c_master
  generic map (
    DATA_WIDTH         => 32,
    REG_ADDR_WIDTH     => 16,
    DEFAULT_SCL_DIV    => 124,
    VENDOR_TAG         => "GENERIC",
    PRODUCT_SERIES_TAG => "GENERIC"
  )
  port map (
    clk          => <clk_signal>,
    rstn         => <rstn_signal>,
    reg_wr_addr  => <reg_wr_addr_signal>,
    reg_rd_addr  => <reg_rd_addr_signal>,
    reg_wr_en    => <reg_wr_en_signal>,
    reg_rd_en    => <reg_rd_en_signal>,
    reg_data_in  => <reg_data_in_signal>,
    reg_data_out => <reg_data_out_signal>,
    reg_wr_rdy   => <reg_wr_rdy_signal>,
    reg_rd_rdy   => <reg_rd_rdy_signal>,
    reg_wr_valid => <reg_wr_valid_signal>,
    reg_rd_valid => <reg_rd_valid_signal>,
    reg_error    => <reg_error_signal>,
    i2c_scl_i    => <i2c_scl_i_signal>,
    i2c_sda_i    => <i2c_sda_i_signal>,
    i2c_scl_oen  => <i2c_scl_oen_signal>,
    i2c_sda_oen  => <i2c_sda_oen_signal>
  );

Generics

NameTypeDefaultDescription
DATA_WIDTHpositive32Width of the RADIF register data bus.
REG_ADDR_WIDTHpositive16Width of the RADIF register address bus.
DEFAULT_SCL_DIVnatural124Default SCL half-period divider. The active half-period is divider + 1 FPGA clock cycles.
VENDOR_TAGstring"GENERIC"Selects the vendor-specific implementation path. This core is portable RTL for all values.
PRODUCT_SERIES_TAGstring"GENERIC"Identifies the target FPGA family for generated project metadata.

Ports

NameDirectionTypeDescription
clkinstd_logicFPGA/register clock domain.
rstninstd_logicActive-low reset for the FPGA/register clock domain.
reg_wr_addrinstd_logic_vector(REG_ADDR_WIDTH - 1 downto 0)Register write address.
reg_rd_addrinstd_logic_vector(REG_ADDR_WIDTH - 1 downto 0)Register read address.
reg_wr_eninstd_logicOne-cycle register write request.
reg_rd_eninstd_logicOne-cycle register read request.
reg_data_ininstd_logic_vector(DATA_WIDTH - 1 downto 0)Register write data.
reg_data_outoutstd_logic_vector(DATA_WIDTH - 1 downto 0)Register read data.
reg_wr_rdyoutstd_logicRegister write ready.
reg_rd_rdyoutstd_logicRegister read ready.
reg_wr_validoutstd_logicRegister write response valid.
reg_rd_validoutstd_logicRegister read response valid.
reg_erroroutstd_logicRegister address or transaction error.
i2c_scl_iinstd_logicOpen-drain SCL input as observed at the pin.
i2c_sda_iinstd_logicOpen-drain SDA input as observed at the pin.
i2c_scl_oenoutstd_logicSCL output-enable. A value of 0 drives SCL low; a value of 1 releases SCL.
i2c_sda_oenoutstd_logicSDA output-enable. A value of 0 drives SDA low; a value of 1 releases SDA.

Register Interfaces

Static register maps are rendered below for this module.

InterfaceDirectionsSignalsRepresentative ports
Register control/statusin, out11reg_wr_addr, reg_rd_addr, reg_wr_en, reg_rd_en, reg_data_in, reg_data_out, reg_wr_rdy, reg_rd_rdy, +3 more

Register Maps

radif_reg_to_i2c_master

Source: interfaces/hdl/radif/register_maps/radif_reg_to_i2c_master.map.json

Controls one-byte I2C read/write transactions and SCL timing.

RegisterOffsetAccessResetDescription
control0x00rw0x00000000Launches one-byte I2C transactions and clears sticky completion/error status.
status0x04ro0x00000000Reports current I2C transaction state and sticky completion/error status.
clk_div0x08rwDEFAULT_SCL_DIVConfigures the I2C SCL phase timing derived from the FPGA/register clock.
slave_addr0x0Crw0x00000000Stores the 7-bit I2C target address used by the next transaction.
tx_data0x10rw0x00000000Stores the data byte used by the next I2C write transaction.
rx_data0x14ro0x00000000Returns the data byte captured by the most recent I2C read transaction.

control

Offset 0x00 / Access rw / Reset 0x00000000

Launches one-byte I2C transactions and clears sticky completion/error status.

Control[15:0]
1514131211109876543210
RSVD [15:3]
READ
CLEAR
START
Control[31:16]
31302928272625242322212019181716
RSVD [31:16]
NameRegister bit(s)Description
READControl[2]Selects transaction direction. 1 performs an I2C byte read from SLAVE_ADDR, 0 performs an I2C byte write using TX_DATA.
CLEARControl[1]Writing 1 clears STATUS.DONE and STATUS.ACK_ERR. Software should write this as a pulse before launching another transaction when it wants fresh status.
STARTControl[0]Writing 1 starts a one-byte I2C transaction when the master is idle. START is ignored as a stored level by transaction logic after the launch cycle.

status

Offset 0x04 / Access ro / Reset 0x00000000

Reports current I2C transaction state and sticky completion/error status.

Status[15:0]
1514131211109876543210
RSVD [15:3]
ACK ERR
DONE
BUSY
Status[31:16]
31302928272625242322212019181716
RSVD [31:16]
NameRegister bit(s)Description
ACK ERRStatus[2]Sticky error bit set when the target does not acknowledge the address byte or write data byte, or when START is requested while BUSY.
DONEStatus[1]Sticky completion bit set when the most recent transaction reaches STOP. Cleared by CONTROL.CLEAR, a new START, or reset.
BUSYStatus[0]Set while the I2C state machine is actively generating START, address, data, acknowledge, or STOP phases.

clk_div

Offset 0x08 / Access rw / Reset DEFAULT_SCL_DIV

Configures the I2C SCL phase timing derived from the FPGA/register clock.

ClkDiv[15:0]
1514131211109876543210
SCL DIV [15:0]
ClkDiv[31:16]
31302928272625242322212019181716
RSVD [31:16]
NameRegister bit(s)Description
SCL DIVClkDiv[15:0]SCL half-period divider. The I2C state machine advances each SCL phase every SCL_DIV + 1 FPGA clock cycles.

slave_addr

Offset 0x0C / Access rw / Reset 0x00000000

Stores the 7-bit I2C target address used by the next transaction.

SlaveAddr[15:0]
1514131211109876543210
RSVD [15:7]
SLAVE ADDR [6:0]
SlaveAddr[31:16]
31302928272625242322212019181716
RSVD [31:16]
NameRegister bit(s)Description
SLAVE ADDRSlaveAddr[6:0]Unshifted 7-bit I2C slave address. The core appends CONTROL.READ as the R/W bit during the address phase.

tx_data

Offset 0x10 / Access rw / Reset 0x00000000

Stores the data byte used by the next I2C write transaction.

TxData[15:0]
1514131211109876543210
RSVD [15:8]
TX BYTE [7:0]
TxData[31:16]
31302928272625242322212019181716
RSVD [31:16]
NameRegister bit(s)Description
TX BYTETxData[7:0]One byte transmitted after the slave address when CONTROL.READ is 0.

rx_data

Offset 0x14 / Access ro / Reset 0x00000000

Returns the data byte captured by the most recent I2C read transaction.

RxData[15:0]
1514131211109876543210
RSVD [15:8]
RX BYTE [7:0]
RxData[31:16]
31302928272625242322212019181716
RSVD [31:16]
NameRegister bit(s)Description
RX BYTERxData[7:0]One byte sampled from SDA during the data phase when CONTROL.READ is 1.

Testbenches

tb_radif_reg_to_i2c_master captured waveform

Source: interfaces/hdl/radif/testbenches/tb_radif_reg_to_i2c_master.vhd

Exercises the register-controlled I2C master with always-acknowledging open-drain bus behavior. The waveform shows register launch, START, address byte, write data byte, ACK sampling, STOP, and completion status.

Artifacts: status, vcd

Captured GHDL Waveform

Source: interfaces/hdl/radif/testbenches/tb_radif_reg_to_i2c_master.vhd

clk
rstn
reg_wr_addr[15:0]
reg_rd_addr[15:0]
reg_wr_en
reg_rd_en
reg_data_in[31:0]
reg_data_out[31:0]
reg_wr_rdy
reg_rd_rdy
reg_wr_valid
reg_rd_valid
reg_error
scl_i
sda_i
scl_oen
sda_oen
control_r[31:0]
status_r[31:0]
clk_div_r[15:0]
slave_addr_r[6:0]
tx_data_r[7:0]
rx_data_r[7:0]
shift_r[7:0]
div_count[15:0]
bit_count
read_mode_r
scl_oen_r
sda_oen_r
wr_valid_r
rd_valid_r
error_r
rd_data_r[31:0]
I2C
I2C interface signals

I2C Interface Waveform

Source: interfaces/hdl/radif/testbenches/tb_radif_reg_to_i2c_master.vhd

i2c_scl_i
i2c_sda_i
i2c_scl_oen
i2c_sda_oen

Sources