与图16F913通讯

发布于 2024-09-10 01:42:24 字数 716 浏览 7 评论 0原文

这是我的问题,似乎 PIC 16F913 的所有通信线路都位于同一组引脚上,这很方便,因为我不必牺牲 GPIO 引脚来进行通信,但是我遇到的问题现在如果我使用芯片上的SPI,我怎样才能向RS232发送信息?

出现这个问题的原因是,我刚刚买了一个通过SPI通信的CAN总线芯片,我真的很想看到RS232上的数据,这样我就可以看到消息。 (我真的对 CAN 还不太了解,所以谁知道这是否有意义)。

以下是我看到的选项,也许其他人有更好的想法,而我只是缺少。

  1. 以某种方式设置一个时间方案,每次获取数据时都会在 SPI 和 RS232 之间切换,

--这看起来并不难,应该可行,但假设我不想错过一条消息,如果我在写入消息时怎么办正在写信给 RS232,我会不会错过它?

2..我总是可以使用SPI,但然后通过8条GPIO线路构建自己的通信总线,连接到另一个PIC 16F913,仅使用GPIO线路,然后由于第二个PIC上的RS232线路是空闲的,我可以简单地读取数据并吐出来。

-- 这是可行的,但现在我们浪费了 2 个芯片,以及所有 GPIO 线,

必须有更好的方法。或者有吗?

非常感谢任何帮助。

更新:我想澄清一下,显然一种解决方案是使用完全不同的芯片(如果我可以对 18F 进行编程,这实际上可能就是我最终要做的),但是,我对最坏的情况感兴趣,在我的资源有限,只有一些913,上面描述的方法是使用该芯片实现此目的的唯一方法,还是有更好的方法?

Here is my issue, it appears that all the communication lines for the PIC 16F913 reside on the same set of pins, this is convenient in that I don't have to sacrifice GPIO pins just to do comms, however the problem I'm having now is if I'm using the SPI on the chip, how can I send information to the RS232?

The reason this issue came up, is that I just bought a CAN bus chip that communicates over SPI, and I would really like to see the data on RS232, so I can see messages. (I really don't know much about CAN yet, so who knows if this even makes sense yet).

Here are the options I see, and maybe someone else has better ideas that I'm just simply missing.

  1. Somehow setup a time scheme that will switch between SPI and RS232 every time I get data,

-- This doesn't seem hard and should work, but supposing I don't want to miss a message, what if a message is written while I'm writing to RS232, is it possible I'll miss it?

2.. I can always use SPI, but then build my own comm bus over 8 of the GPIO lines, to another PIC 16F913, using only the GPIO lines and then since the RS232 lines are free on the second PIC I can simply read the data and spit it out.

-- This one is doable but now we're wasting 2 chips, AND all the GPIO lines,

There has to be a better way. Or is there?

Any help is greatly appreciated.

Update: I would like to clarify, obviously one solution is using a completely different chip (which may in fact be what I end up doing, if I can get the 18F programmed), however, I'm interested in worst case scenario, in which I am limited in resources and only have some 913's, is the way described above the only way to do it with this chip, or is there a better way?

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

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

发布评论

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

评论(3

时光与爱终年不遇 2024-09-17 01:42:25

您可以对 SPI 总线进行软件实现 - 它比 UART 更容易实现,因为时序并不重要并且您可以控制它。

大多数 CAN 芯片都有一些接收缓冲区,因此如果您正忙于使用 UART 执行某些操作,那么消息将在 CAN 芯片内部进行缓冲。但是……您需要确保能够足够快/足够频繁地从 CAN 芯片中获取消息,这样您就不会丢失一些消息。

您可能必须对 UART Tx 过程使用中断 - 以便在 UART 上发送数据时可以接收 CAN 消息。

如果您只对某些消息感兴趣,大多数 CAN 芯片都有过滤器 - 这使得您很容易只接收您感兴趣的消息,通常会大幅降低每秒的数据包数量。

You could do a software implementation of the SPI bus - it's easier to do than the UART because the timing isn't critical and you are in control of it.

Most CAN chips have a few receive buffers so if you're busy doing something with the UART then the messages will be buffered inside the CAN chip. But... you will need to make sure that you can get the messages out of the CAN chip fast/often enough so you don't lose some.

You would probably have to either use an interrupt for the UART Tx process - so that you can be receiving CAN messages while you're sending data on the UART.

If you're only interested in certain messages most CAN chips have filters - this makes it easy to only receive the messages you're interested in, usually dropping the number of packets/second dramatically.

楠木可依 2024-09-17 01:42:25

您可以使用 RS232 端口的软件实现。例如,http://mikroe.com 的 c 编译器就带有这样的库。但将位转移到输出引脚应该不会太难,rs232 是一个相当简单的协议。

You can use a software implementation of a RS232 port. For example the c compiler from http://mikroe.com comes with such a library. But it shouldn't be too hard to shift bits to an output pin, rs232 is a fairly simple protocol.

メ斷腸人バ 2024-09-17 01:42:25

我强烈建议您将MCU更换为PIC16F1933。

  1. 它更新且更
  2. 便宜,
  3. 带有 EUART 和 MSSP 模块。
  4. MCU架构有所改进。

PIC16F913 MCU将在未来几年内被淘汰!

I strongly recommend that you change the MCU with PIC16F1933.

  1. It is newer
  2. It is cheaper
  3. With EUART and MSSP moduls.
  4. The MCU arhitecture is impruved.

The PIC16F913 MCU will become obsolete in next few years!

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