Forum: FPGA, VHDL & Verilog Writing Testbench for Bidirectional/Inout Port

von Ahmed A. (Company: None) (newbiespartan)

Rate this post
0 useful
not useful
Hello! I have to write a testbench for I2C. I have an inout SDA port, 
which I drive to either zero or high impedance state in the module.I 
want to make sure that on the 9th clock cycle, when the SDA port is 
driven to a high impedance state for the slave to issue an acknowledge, 
the test bench drives the port low, indicating successful 
acknowledgement by the slave. Currently, I know when I want to drive the 
port low, this cycle is marked by an IO signal in simulation which goes 
high on the 9th clock cycle.

The function should be something like this :

//reg IO; //IO is controlled in the testbench, not exported from module.
 if (IO)  SDA = 1'b0;
 else     SDA = SDA;

The following approach did not work.

 assign SDA = IO? 1'b0 : SDA;

: Edited by User
von Vancouver (Guest)

Rate this post
1 useful
not useful
The problem may be that you never set SDA = 1'bZ when IO===0. So your 
SDA signal is always driven by the test bench. ( I am not sure if 1'bZ 
is the correct notation for high impedance in Verilog, you have to look 

von Lothar M. (lkmiller) (Moderator)

Rate this post
0 useful
not useful
Ahmed A. wrote:
> which I drive to either zero or high impedance
You don't. Instead you built a latch...

: Edited by Moderator
von Ahmed A. (Company: None) (newbiespartan)

Rate this post
0 useful
not useful
assign SDA = IO? 1'b0 : 1'bz;

This works.
Thank you!

: Edited by User


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.