Professional Documents
Culture Documents
ADT7420 Codigo Libro
ADT7420 Codigo Libro
ADT7420 Codigo Libro
-- Company:
-- Engineer:
--
-- Create Date: 08/19/2022 01:48:45 PM
-- Design Name:
-- Module Name: adt7420_intento1 - Behavioral
-- Project Name:
-- Target Devices:
-- Tool Versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
library ieee;
use ieee.std_logic_1164.all;
entity adt7420_intento1 is
port(clk_100MHz, rst: in std_logic;
scl: out std_logic;
sda: inout std_logic;
led: out std_logic_vector(10 downto 0)
);
end entity;
architecture Behavioral of adt7420_intento1 is
type state is (st_idle, st0_start, st1_txSlaveAddress, st2_ack1,
st3_txAddress, st4_ack2, st5_restart, st6_txSlaveAddress, st7_ack3, st8_rd_data,
st9_nack, st10_stop);
signal DataOut: std_logic_vector(7 downto 0);
constant Address_tobe_Read: std_logic_vector(7 downto 0):=x"0b";
constant slave_address_with_rd_flg: std_logic_vector(7 downto 0):=x"97";
constant slave_address_with_wrt_flg: std_logic_vector(7 downto 0):=x"96";
signal scl_buss: std_logic:='0';
signal dcl_buss: std_logic:='0';
constant max_length: integer:=8;
signal present_state,next_state :state ;
shared variable data_index: integer range 0 to max_length -1;
signal timer: integer range 0 to max_length; signal clk_400KHz:
std_logic:='0';
signal ack_bits: std_logic_vector(2 downto 0);
signal count: integer range 0 to 250:=0;
signal sda_signal, scl_signal: std_logic;
signal rd_flag: std_logic:='0';
begin
clk400KHz: process(clk_100MHz)
begin
if(rst='1') then
clk_400KHz<='0';
count<=0;
elsif(rising_edge(clk_100MHz)) then
if(count=124) then
clk_400KHz <= not clk_400KHz;
count <= 0;
else
count<=count + 1;
end if;
end if;
end process;
scl<=scl_signal;
sda<=sda_signal;
when st2_ack1=>
sda_signal<='Z';
scl_signal<=scl_buss;
timer<=1;
next_state<=st3_txAddress;
when st4_ack2=>
sda_signal<='Z';
scl_signal<=scl_buss;
timer<=1;
next_state<=st5_restart;
when st9_nack=>
sda_signal<='1';
scl_signal<=scl_buss;
timer<=1;
next_state<=st10_stop;
end case;
end process;
end Behavioral;