• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Arduino Nano z CH340 ciekawy problem
#17
Raczej chodzi tylko o konkretne model konwerterów UART, bo na Atmega i CP2102 działa OK.
Serial event nie jest wywoływany na port COM USB w Leonardo, dla UART1 działa OK.
Przykład użycia dwóch serial event w Leonardo:
Kod:
String inputString = "";         // a String to hold incoming data
bool stringComplete = false;  // whether the string is complete
String inputString1 = "";         // a String to hold incoming data
bool stringComplete1 = false;  // whether the string is complete

void setup() {
  // initialize serial:
  Serial.begin(115200);
  Serial1.begin(115200);
  // reserve 200 bytes for the inputString:
  inputString.reserve(200);
  inputString1.reserve(200);
}

void loop() {
   serialEvent();
  // print the string when a newline arrives:
  if (stringComplete) {
    Serial1.println(inputString);
    // clear the string:
    inputString = "";
    stringComplete = false;
  }

    if (stringComplete1) {
    Serial.println(inputString1);
    // clear the string:
    inputString1 = "";
    stringComplete1 = false;
  }
}

/*
  SerialEvent occurs whenever a new data comes in the hardware serial RX. This
  routine is run between each time loop() runs, so using delay inside loop can
  delay response. Multiple bytes of data may be available.
*/
void serialEvent1() {
  while (Serial1.available()) {
    // get the new byte:
    char inChar = (char)Serial1.read();
    // add it to the inputString:
    inputString1 += inChar;
    // if the incoming character is a newline, set a flag so the main loop can
    // do something about it:
    if (inChar == '\n') {
      stringComplete1 = true;
    }
  }
}

void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag so the main loop can
    // do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}
serialEvent(); nie zostanie wywołany przez funkcje Arduino i musi być po prostu wstawiony do loop. 
Tak samo jest z ESP, trzeba wstawić do loop by działało, natomiast testowałem z ESP8266 i ESP32 ten program Moonlight i działa OK. Wniosek - serialEvent nie ma związku.
No i jeszcze ten obrazek:
   
Jedno co jeszcze mogę doradzić to temat na elektrodzie, może jest tam ktoś kto specjalizuje się w portach COM. Ja tylko mam odczucie, że to jest kwestia sprzętu/sterowników i konstrukcji tego programu od strony PC, od strony Arduino grzebanie nic nie da.
Miło być decenianym https://buycoffee.to/kaczakat
 
Odpowiedź
  


Wiadomości w tym wątku
RE: Arduino Nano z CH340 ciekawy problem - przez kaczakat - 22-09-2019, 20:17

Skocz do:


Przeglądający: 1 gości