7762| 5
|
[已解决] 一个485通信的问题,能发送不能接收,求大神指点 |
本帖最后由 maxfeel 于 2015-7-17 11:53 编辑 通过串口助手调试能正确收到485发送来的数据,但是返回数据收不到求大神指点,digitalWrite(EN, HIGH);//为发送状态 digitalWrite(EN, LOW);//为接收状态 代码如下: int EN = 7; //定义RS485扩展板的使能端(2号数字IO口),高电平为发送状态,低电平为接收状态 unsigned char RX = 0; void setup() { Serial.begin(1200, SERIAL_8E1); Serial.flush(); delay(1000); pinMode(EN, OUTPUT); pinMode(8,OUTPUT); digitalWrite(EN, HIGH); } void loop() { digitalWrite(EN, HIGH); char hexdata[14] = {0x68, 0x73, 0x26, 0x12, 0x00, 0x80, 0x013, 0x68, 0x01, 0x02, 0x43, 0xc3, 0x17, 0x16}; Serial.write(&hexdata[0], 14); delay(300); digitalWrite(EN, LOW); if (Serial.available() > 0) { unsigned char RX = 0; RX = char(Serial.read()); //Serial.read(); Serial.println(RX); digitalWrite(8, HIGH); delay(1000); digitalWrite(EN, HIGH); } delay(3000); } |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed