极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 26236|回复: 5

arduino用modbus与rs485通讯出现的问题

[复制链接]
发表于 2016-2-26 13:40:47 | 显示全部楼层 |阅读模式

  1. #include <SimpleModbusMaster.h>

  2. /*
  3.    The example will use packet1 to read a register from address 0 (the adc ch0 value)
  4.    from the arduino slave (id=1). It will then use this value to adjust the brightness
  5.    of an led on pin 9 using PWM.
  6.    It will then use packet2 to write a register (its own adc ch0 value) to address 1
  7.    on the arduino slave (id=1) adjusting the brightness of an led on pin 9 using PWM.
  8. */

  9. //////////////////// Port information ///////////////////
  10. #define baud 9600
  11. #define timeout 2000
  12. #define polling 200
  13. #define retry_count 20
  14. #define TxEnablePin 2
  15. #define TOTAL_NO_OF_REGISTERS 2
  16. enum
  17. {
  18.   PACKET1,
  19.   TOTAL_NO_OF_PACKETS
  20. };
  21. Packet packets[TOTAL_NO_OF_PACKETS];
  22. unsigned int regs[TOTAL_NO_OF_REGISTERS];
  23. void setup()
  24. {Serial.begin(9600);

  25.   modbus_construct(&packets[PACKET1], 02, READ_INPUT_REGISTERS, 257, 02, 0);
  26.     modbus_configure(&Serial, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);
  27. }
  28. void loop()
  29. {
  30.   modbus_update();

  31. }
复制代码

这是程序  arduino与rs485之间用max485转接  载入程序之后arduino的tx闪 max485的tx也闪 但是rs485没反应  请问我是发送的数据包不对吗??

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

 楼主| 发表于 2016-2-26 13:48:49 | 显示全部楼层
有人 跟我说是 max流控制的原因  应该换一个自动流的ttl转接卡   可是对流控制不了解 求各位大神解答是不是流控制的问题呢  
回复 支持 反对

使用道具 举报

发表于 2016-2-27 01:00:05 | 显示全部楼层
也正在研究
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-3-1 09:38:38 | 显示全部楼层
acdc0616 发表于 2016-2-27 01:00
也正在研究

我弄出来了 是流控制的问题 换了一个自动流的就好了
回复 支持 反对

使用道具 举报

发表于 2016-3-9 00:51:54 | 显示全部楼层
weige 发表于 2016-3-1 09:38
我弄出来了 是流控制的问题 换了一个自动流的就好了

用modbus测试软件  发送什么样的命令,能分享一下吗。
回复 支持 反对

使用道具 举报

发表于 2016-3-9 13:17:02 | 显示全部楼层
看到 enum命令, 感觉好高大上
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-15 23:46 , Processed in 0.039085 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表