Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Code Verilog - [expand] 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 module i2c_master_top(clk, rst, i2c_rst,data_in,data_out, status,we_data,we_command,command,scl_pad_i, scl_pad_o, scl_padoen_o, sda_pad_i, sda_pad_o, sda_padoen_o ); input clk; // master clock input input rst; input i2c_rst; input [7:0] data_in; // databus input output [7:0] data_out; // databus output input we_data; // write enable input input we_command; // stobe/core select signal input [4:0] command; // valid bus cycle input output [3:0] status; reg [7:0] data_out; // I2C signals // i2c clock line input scl_pad_i; // SCL-line input output scl_pad_o; // SCL-line output (always 1'b0) output scl_padoen_o; // SCL-line output enable (active low) // i2c data line input sda_pad_i; // SDA-line input output sda_pad_o; // SDA-line output (always 1'b0) output sda_padoen_o; // SDA-line output enable (active low) // // variable declarations // // registers wire [15:0] prer; // clock prescale register reg [ 7:0] txr; // transmit register wire [ 7:0] rxr; // receive register reg [ 4:0] cr; // command register wire [ 3:0] sr; // status register // done signal: command completed, clear command register wire done; // core enable signal wire core_en; wire ien; // status register signals wire irxack; reg rxack; reg tip; wire i2c_busy; wire i2c_al; reg al; // generate data register always @(posedge clk or negedge rst) if (!rst) txr <= #1 8'h0; else if (i2c_rst) txr <= #1 8'h0; else if (we_data) begin txr <= #1 data_in; end // generate command register (special case) always @(posedge clk or negedge rst) if (!rst) cr <= #1 5'd0; else if (i2c_rst) cr <= #1 5'd0; else if (we_command) begin cr <= #1 command; end else begin if (done | i2c_al) cr <= #1 5'd0; end // decode command register wire sta = cr[4]; wire sto = cr[3]; wire rd = cr[2]; wire wr = cr[1]; wire ack = cr[0]; wire nReset; assign nReset=rst; // decode control register assign core_en = 1; assign prer=16'h00c8; assign data_out=rxr; // hookup byte controller block i2c_master_byte_ctrl byte_controller ( .clk ( clk ), .rst ( i2c_rst ), .nReset ( nReset), .ena ( core_en ), .clk_cnt ( prer ), .start ( sta ), .stop ( sto ), .read ( rd ), .write ( wr ), .ack_in ( ack ), .din ( txr ), .cmd_ack ( done ), .ack_out ( irxack ), .dout ( rxr ), .i2c_busy ( i2c_busy ), .i2c_al ( i2c_al ), .scl_i ( scl_pad_i ), .scl_o ( scl_pad_o ), .scl_oen ( scl_padoen_o ), .sda_i ( sda_pad_i ), .sda_o ( sda_pad_o ), .sda_oen ( sda_padoen_o ) ); // status register block + interrupt request signal always @(posedge clk or negedge rst) if (!rst) begin al <= #1 1'b0; rxack <= #1 1'b0; tip <= #1 1'b0; end else if (i2c_rst) begin al <= #1 1'b0; rxack <= #1 1'b0; tip <= #1 1'b0; end else begin al <= #1 i2c_al | (al & ~sta); rxack <= #1 irxack; tip <= #1 (rd | wr); end // assign status register bits assign sr[3] = rxack; assign sr[2] = i2c_busy; assign sr[1] = al; assign sr[0] = tip; assign status=sr; endmodule
Code Verilog - [expand] 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 module test_i2c(sda,scl,clk,rst); inout sda; output scl; input clk,rst; wire i2c_rst; // asynchronous reset wire [7:0] din; // databus input wire [7:0] dout; // databus output wire we_data; // write enable input wire we_command; // stobe/core select signal wire [4:0] command; // valid bus cycle input wire ack; wire sda0_o, sda0_oen; wire sda, sda0_o, sda0_oen; wire [7:0] dout; fsm cmd_controller cr (clk,rst,we_command,we_data,din,command,status); i2c_master_top core(.clk(clk), .rst(rst), .i2c_rst(1'b0), .data_in(din), .data_out(dout) , .we_data(we_data), .we_command(we_command), .command(command), .scl_pad_i(scl), .scl_pad_o(scl0_o), .scl_padoen_o(scl0_oen), .sda_pad_i(sda), .sda_pad_o(sda0_o), .sda_padoen_o(sda0_oen) ); endmodule *************** module fsm_cmd_controller (clk,rst,we_command,we_data,din,command,status); input [3:0]status; output we_command; output we_data output [7:0]din output [4:0]command //fsm will be here //// endmodule
Ya i have used.
Any problem
I don't quite follow. You have 3 devices. A PIC microcontroller, an fpga and a DAC, yes?
What is connected to what?
You have the PIC connected to the fpga using what kind of bus? I2c?
You mentioned a DAC, how (as in bus, protocol) is that connected to what (fpga or pic)?