-
Notifications
You must be signed in to change notification settings - Fork 0
/
I2c_TB.vhd
71 lines (56 loc) · 1.58 KB
/
I2c_TB.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
library IEEE;
use IEEE.NUMERIC_STD.ALL;
use IEEE.STD_LOGIC_1164.ALL;
ENTITY I2C_top_TB IS
END ENTITY;
ARCHITECTURE ITOPTB OF I2C_top_TB IS
COMPONENT I2C_MASTER IS
GENERIC(bus_clk : INTEGER := 1_000_000;
sys_clk : INTEGER := 1000000000 );
PORT(
CLK : IN STD_LOGIC;
RESET : IN STD_LOGIC;
P : IN STD_LOGIC_VECTOR( 15 DOWNTO 0 );
SDA : INOUT STD_LOGIC;
SCL : INOUT STD_LOGIC
);
END COMPONENT;
COMPONENT I2C_SLAVE IS
GENERIC(bus_clk : INTEGER := 1_000_000;
sys_clk : INTEGER := 1000000000 ;
slave_addr : std_logic_vector( 6 DOWNTO 0) := "0101010");
PORT(
CLK : IN STD_LOGIC;
RESET : IN STD_LOGIC;
-- RAM : inout ram_type;
SDA : INOUT STD_LOGIC;
SCL : IN STD_LOGIC;
P : OUT STD_LOGIC_VECTOR( 15 DOWNTO 0 )
);
END COMPONENT;
SIGNAL clk, reset : std_logic :='0';
SIGNAL scl, sda : std_logic;
SIGNAL p_num : STD_LOGIC_VECTOR( 15 DOWNTO 0 ) := X"0000";
BEGIN
PULLUP_SDA: sda <= 'H';
PULLUP_SCL: scl <= 'H';
CLOCK: process begin
clk <= '0';
wait for 0.5 ns;
clk <= '1';
wait for 0.5 ns;
end process;
i : I2C_MASTER GENERIC MAP( bus_clk => 1_000_000, sys_clk => 1000000000 ) PORT MAP( CLK => clk , RESET=> reset, P=> X"00FF", SDA => sda, SCL=> scl);
s : I2C_SLAVE GENERIC MAP( bus_clk => 1_000_000, sys_clk => 1000000000 , slave_addr=>"0101010") PORT MAP( CLK => clk , RESET=> reset , SDA => sda, SCL=> scl, P => p_num);
r : process begin
reset <= '1';
scl <= 'H';
sda <= 'H';
wait for 10 ns;
reset <= '0';
wait for 10000 ns;
sda <= 'H';
wait for 100000000 ns;
wait;
end process;
END ITOPTB;