Hardware Reference
In-Depth Information
76
i2c_clk <= not i2c_clk;
77
count := 0;
78
end if;
79
end if;
80
end process;
81
82
--FSM state register + Auxiliary register:
83
process (i2c_clk, rst)
84
begin
85
if rst='1' then
86
pr_state <= idle;
87
i_reg <= 0;
88
j_reg <= 0;
89
elsif falling_edge(i2c_clk) then
90
pr_state <= nx_state;
91
i_reg <= i;
92
j_reg <= j;
93
end if;
94
end process;
95
96
--FSM combinational logic:
97
process (all)
98
begin
99
--Default values:
100
SCL <= i2c_clk;
101
i <= 0;
102
j <= 0;
103
case pr_state IS
104
--Common states:
105
when idle =>
106
SCL <= '1';
107
SDA <= '1';
108
if wr='1' or rd='1' then
109
nx_state <= start;
110
else
111
nx_state <= idle;
112
end if;
113
when start =>
114
SCL <= '1';
115
SDA <= '0';
116
nx_state <= slave_addr_wr;
117
when slave_addr_wr =>
118
SDA <= slave_addr_for_wr(8-i);
119
i <= i_reg + 1;
120
if i=8 then
121
nx_state <= ack1;
122
else
123
nx_state <= slave_addr_wr;
124
end if;
125
when ack1 =>
126
SDA <= 'Z';
127
if wr='1' then
128
nx_state <= initial_addr_wr;
129
else
130
nx_state <= initial_addr_rd;
131
end if;
132
when stop =>
Search WWH ::




Custom Search