在 Verilog 中驱动双向线路

发布于 2024-10-18 14:21:19 字数 1493 浏览 4 评论 0原文

这个问题可能不会得到很好的解释,那是因为我不太明白我的设计中发生了什么。

我需要使用 I2C 通信总线与相机 (Terasic D5M) 通信,因此我尝试使用 Verilog 编写一个。我只需要一个师傅。在我的逻辑分析仪上,除了我不断从相机收到 NACK 信号之外,一切看起来都很棒。起初我不知道出了什么问题,所以我就把它放在一边。

今晚我尝试使用 Altera University IP Core,它有一个用于 D5M 的模块。将其设置为自动初始化后,我观察了分析仪上发生的情况。该跟踪看起来与我的 I2C 模块的输出相同,只不过这是由设备注册 ACK。

我的问题是,我一生都无法弄清楚为什么我没有得到认可。可能是我不允许相机将 sda 线拉低(scl 工作正常),但我不明白为什么会这样。

有谁有类似的经历或知道我应该去哪里查看/发布/阅读?我会发布一些代码,但我不知道如果它不是完整的,它会有多大用处。抱歉这么含糊,但我真的很迷茫,甚至不知道我应该问什么;我想这是一个类似的效果请求。感谢您的帮助,这里有一些 i2c 模块输出行的代码。


`define HIGH  1'bZ
`define TRUE  1'b1
`define FALSE 1'b0

inout sda;
assign sda = (ena_sda)?sda_bit:`HIGH;

inout scl;
assign scl = (ena_scl)?pSCL:`HIGH;

pSCL 是以所需速率运行的时钟,sda_bit 是操作期间 sda 线的值。这是释放并等待确认的部分。这嵌入在我的转变状态中,因此是 else if 的开始。


// Data shifting complete, check for ACK
// Release the SDA line and set our bit to high Z
else if(shiftComplete == `TRUE) begin
    ena_sda = `FALSE;
    sda_bit = `HIGH;
    if(negedge_SCL) begin
        ena_sda = `TRUE;                        
        case(i2cState)
            `DATA_STATE:
                begin
                    shiftComplete = `FALSE;
                    nxState = `DATA_STATE;
                end
            `START_STATE: nxState = `REPEAT_START_STATE;
             default: nxState = `STOP_STATE;
        endcase
    end
end /* end ACK */

我认为释放 ena_sda 足以让相机驱动模块。我想我之前把 sda_bit = HIGH 作为测试(我一个月没看过这个)。

我很乐意分享更多代码或展示我的逻辑痕迹,但我不想再弄乱了。感谢您的阅读。

this question probably wont be explained very well and that's because I don't really understand what's happening in my design.

I need to use an I2C communication bus to talk to a camera (Terasic D5M) so I tried to write one using Verilog. I only need a master. On my logic analyzer everything looks great except I keep getting NACK signals from the camera. Initially I had no idea what was wrong so I just put it aside.

Tonight I tried to use the Altera University IP Core which has a module for the D5M. After setting this to automatically initialize I watched what was going on on my analyzer. The trace looks the same as the output from my I2C module except this is registering an ACK by the device.

My problem is, I cannot for the life of me figure out why I'm not getting an acknowledgement. It may be that I'm not allowing the camera to pull the sda line low (scl works fine) but I cannot figure out why this would be.

Has anyone has any similar experiences or have any idea where I should go look / post / read? I would post some code but I don't know how useful it's going to be if it's not in its entirety. Sorry about being so vague but I'm really lost and don't even know what I should be asking; I guess this is a similar effect request. Thanks for any help, here's a little bit of code for the output lines from the i2c module.


`define HIGH  1'bZ
`define TRUE  1'b1
`define FALSE 1'b0

inout sda;
assign sda = (ena_sda)?sda_bit:`HIGH;

inout scl;
assign scl = (ena_scl)?pSCL:`HIGH;

pSCL is a clock that runs at the desired rate and sda_bit is the value of the sda line during operation. Here is the section that releases and waits for the ack. This is embedded in my shifting state, hence the beginning else if.


// Data shifting complete, check for ACK
// Release the SDA line and set our bit to high Z
else if(shiftComplete == `TRUE) begin
    ena_sda = `FALSE;
    sda_bit = `HIGH;
    if(negedge_SCL) begin
        ena_sda = `TRUE;                        
        case(i2cState)
            `DATA_STATE:
                begin
                    shiftComplete = `FALSE;
                    nxState = `DATA_STATE;
                end
            `START_STATE: nxState = `REPEAT_START_STATE;
             default: nxState = `STOP_STATE;
        endcase
    end
end /* end ACK */

I would think that releasing ena_sda would be enough to let the camera drive the module. I think I put the sda_bit = HIGH before as a test (I haven't looked at this in a month).

I would be happy to share more code or show my logic traces but I don't want to clutter this anymore. Thanks for reading.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-10-25 14:21:19

我会将输入和输出分开,并添加一个输出启用,基本上不使用输入输出。您的 altera 设备的 I/O 板支持这样使用吗? (他们应该)如果是这样,让 I/O pad 完成输入输出工作。另外,您是否将 I/O 板定义为推挽式、线或式、弱上拉式或其中任何一种?在某些情况下,您可以选择在启用输出时将其设置为推挽式,并且在输入时将其设置为三态,从而允许另一侧控制数据线。

I would separate the input and output and add to that an output enable, basically not use an inout. Does your altera device's I/O pads support being used that way? (they should) If so let the I/O pad do the inout work. Also have you defined the I/O pad as a push-pull or wired-or, or weak pull up or any of those? In some cases you may choose to have it a push-pull when output is enabled and when an input it tri-states allowing the other side to control the data line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文