Serial.Available不能使用Arduino nano

时间:2015-09-19 10:58:15

标签: arduino serial-port

我有一个从nano运行到当前循环驱动程序的串行应用程序。 现在,如果我将Tx直接连接到Rx,则LED设置为HIGH,但如果我将Tx / Rx链接到当前环路板,则LED根本不设置。我甚至在usb监视器上添加了一个序列,以确认当前的循环板返回与传递的相同的十六进制。有什么建议?



int timeout = 0;

void setup() {
  // put your setup code here, to run once:

  pinMode(13, OUTPUT);
Serial.begin(4800,SERIAL_8E1);
//Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  //delay(10000);
  byte inByte1 = 0xF1;
  byte inByte2 = 0x10;
  byte inByte3 = 0xB0;
  
  
//if(timeout == 0)
//{
  Serial.write(inByte1);
  Serial.write(inByte2);
  Serial.write(inByte3);
//}
//timeout = timeout+1;

//if(timeout == 50)
//{
//  timeout=0;
//}
  
//delay(80);

byte inByte4 = 0xE1;
//Serial.println(Serial.available());
 while (!Serial.available()) {
  //timeout =0;
    //byte inChar = Serial.read();
    //Serial.println(inChar);
//digitalWrite(13, HIGH);
    //if(inChar == inByte4)
    //{
    //   digitalWrite(13, HIGH);
    //}
     Serial.write(inByte1);
  Serial.write(inByte2);
  Serial.write(inByte3);
  delay(80);
  }

while (Serial.available()) {
  //timeout =0;
    //byte inChar = Serial.read();
    //Serial.println(inChar);
digitalWrite(13, HIGH);
    //if(inChar == inByte4)
    //{
    //   digitalWrite(13, HIGH);
    //}
    
  }
}



String ReadResult(Stream &serial)
{
  int serialState = 0;
  String content = "";
  char character;
  long interval = 10000; 
 //unsigned int timeout = 0;
 unsigned long currentMillis = millis();
 long previousMillis = millis();

 while ( !serial.available() && serialState != 1) {
  currentMillis = millis();
   if(currentMillis - previousMillis > interval){
        serialState = 1;
   }
 }
 
 //timeout = 0;

  //while (serial.available()) {
  //  character = serial.read();
  //  content += character;
  //}

  return content;
};




1 个答案:

答案 0 :(得分:0)

我喂的司机没有返回正确的电压