有关逻辑电路和串行通信的建议 [英] Advice on logic circuits and serial communications

查看:192
本文介绍了有关逻辑电路和串行通信的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据目前为止我了解的串行端口,数据传输是通过引脚3完成的.如下所示:

As far as I understand the serial port so far, transferring data is done over pin 3. As shown here:

有两件事让我对此感到不舒服.第一个是似乎暗示两个连接的设备在信号速度上达成共识,第二个是即使将它们配置为以相同的速度运行,也会遇到可能的同步问题...对吗?我想这类事情可以处理,但似乎必须有一个更简单的方法.

There are two things that make me uncomfortable about this. The first is that it seems to imply that the two connected devices agree on a signal speed and the second is that even if they are configured to run at the same speed you run into possible synchronization issues... right? Such things can be handled I suppose but it seems like there must be a simpler method.

对我来说,似乎更好的方法是让其中一个串行端口引脚发送一个脉冲,该脉冲指示可以存储下一位.因此,如果我们将这些引脚连接到移位寄存器,则基本上可以得到:(某些脉冲引脚)-> clk,tx-> d

What seems like a better approach to me would be to have one of the serial port pins send a pulse that indicates that the next bit is ready to be stored. So if we're hooking these pins up to a shift register we basically have: (some pulse pin)->clk, tx->d

这是常见的做法吗?有什么理由不这样做吗?

Is this a common practice? Is there some reason not to do this?

编辑

Mike不应该删除他的答案.这种 I 2 C(2针串行)的方法似乎相当接近我的所作所为.串行端口没有时钟,您是正确的nobugz,但这基本上就是我所做的.看到这里:

Mike shouldn't have deleted his answer. This I2C (2 pin serial) approach seems fairly close to what I did. The serial port doesn't have a clock you're right nobugz but that's basically what I've done. See here:

private void SendBytes(byte[] data)
{
    int baudRate = 0;
    int byteToSend = 0;
    int bitToSend = 0;
    byte bitmask = 0;

    byte[] trigger = new byte[1];
    trigger[0] = 0;

    SerialPort p;
    try
    {
        p = new SerialPort(cmbPorts.Text);
    }
    catch
    {
        return;
    }

    if (!int.TryParse(txtBaudRate.Text, out baudRate)) return;
    if (baudRate < 100) return;
    p.BaudRate = baudRate;

    for (int index = 0; index < data.Length * 8; index++)
    {
        byteToSend = (int)(index / 8);
        bitToSend = index - (byteToSend * 8);
        bitmask = (byte)System.Math.Pow(2, bitToSend);

        p.Open();
        p.Parity = Parity.Space;
        p.RtsEnable = (byte)(data[byteToSend] & bitmask) > 0;

        s = p.BaseStream;
        s.WriteByte(trigger[0]);

        p.Close();
    }
}

在任何人告诉我这是多么丑陋或我如何破坏传输速度之前,我的快速回答是我不在乎.我的观点是,这似乎比您在nobugz答案中描述的方法简单得多.如果.Net SerialPort类为我提供了对接脚信号的更多控制,那将不会那么难看.还有其他串口API吗?

Before anyone tells me how ugly this is or how I'm destroying my transfer speeds my quick answer is I don't care about that. My point is this seems much much simpler than the method you described in your answer nobugz. And it wouldn't be as ugly if the .Net SerialPort class gave me more control over the pin signals. Are there other serial port APIs that do?

推荐答案

据我所知,该方法与 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆