- #include <SimpleModbusMaster.h>
- /*
- The example will use packet1 to read a register from address 0 (the adc ch0 value)
- from the arduino slave (id=1). It will then use this value to adjust the brightness
- of an led on pin 9 using PWM.
- It will then use packet2 to write a register (its own adc ch0 value) to address 1
- on the arduino slave (id=1) adjusting the brightness of an led on pin 9 using PWM.
- */
- //////////////////// Port information ///////////////////
- #define baud 9600
- #define timeout 2000
- #define polling 200
- #define retry_count 20
- #define TxEnablePin 2
- #define TOTAL_NO_OF_REGISTERS 2
- enum
- {
- PACKET1,
- TOTAL_NO_OF_PACKETS
- };
- Packet packets[TOTAL_NO_OF_PACKETS];
- unsigned int regs[TOTAL_NO_OF_REGISTERS];
- void setup()
- {Serial.begin(9600);
- modbus_construct(&packets[PACKET1], 02, READ_INPUT_REGISTERS, 257, 02, 0);
- modbus_configure(&Serial, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);
- }
- void loop()
- {
- modbus_update();
- }
复制代码
这是程序 arduino与rs485之间用max485转接 载入程序之后arduino的tx闪 max485的tx也闪 但是rs485没反应 请问我是发送的数据包不对吗?? |