Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

any example code for bidirectional port (inout)???

Status
Not open for further replies.

childs

Member level 5
Joined
Apr 28, 2008
Messages
87
Helped
15
Reputation
30
Reaction score
12
Trophy points
1,288
Activity points
1,945
verilog bidirectional port

Is there any example of code to utilize a bidirectional port (inout)??? Maybe take for example, how to use it for a RAM with bidirectional data bus. Any other examples are welcomed as well. Thx :D
 

bidirectional port

hi,
below code may help you to understand bidirectional pins.

module top
(
input SysClk ,
input Sys_Rst,
inout I2c_Sda,
inout I2c_Scl
);

wire i2c_scl_out;
assign I2c_Scl = (i2c_scl_out == 1'b0) ? 1'b0 : 1'bz;
wire i2c_scl_in = I2c_Scl ;
wire i2c_sda_out;
assign I2c_Sda = (i2c_sda_out == 1'b0) ? 1'b0 : 1'bz;
wire i2c_sda_in = I2c_Sda ;

Instance Componant
(//==============================
// Globle Signals
.NSYSRESET ( sys_reset_n ), // input
.SYSCLK ( sys_clk ), // input
//-------------------------------------------
//==============================
// I2C Signals
.SDAI ( i2c_sda_in ), // input
.SCLI ( i2c_scl_in ), // input
.SDAO ( i2c_sda_out ), // output
.SCLO ( i2c_scl_out ) // output
//-------------------------------------------
);

endmodule

Hth
 

interface example +inout

can u explain what is performed by this statement?

assign I2c_Scl = (i2c_scl_out == 1'b0) ? 1'b0 : 1'bz;

Sorry because I only came across VHDL so far, I guess this is Verilog? Because this statement looks like something in C.
 

bidirectional port verilog

I know neither VHDL (am very slowly learning!) nor Verilog, but I know C/C++. In C/C++ the ? operator (called a ternary operator) works as follows:

Code:
a = (condition) ? true : false;

So, using the line you showed, I2c_Scl will be assigned 1'b0 if the condition (i2c_scl_out == 1'b0) is true, otherwise it will be assigned 1'bz.

Hope this helps you.
TM
 

example bidirectional vhdl

Yes, Verilog syntax is near to C-language in many parts, here's the VHDL equivalent:
Code:
I2c_Sda <= '0' WHEN i2c_sda_out = '0' ELSE 'Z';
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top