PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

53 linhas
1.4KB

  1. // AltSoftSerial Receive Test
  2. //
  3. // Transmit data with Serial1 and try to receive
  4. // it with AltSoftSerial. You must connect a wire
  5. // from Serial1 TX to AltSoftSerial RX.
  6. #include <AltSoftSerial.h>
  7. AltSoftSerial altser;
  8. const int mybaud = 9600;
  9. // Board Serial1 TX AltSoftSerial RX
  10. // ----- ---------- ----------------
  11. // Teensy 3.x 1 20
  12. // Teensy 2.0 8 (D3) 10 (C7)
  13. // Teensy++ 2.0 3 (D3) 4 (D4)
  14. // Arduino Leonardo 1 13
  15. // Arduino Mega 18 48
  16. // Serial1 on AVR @ 16 MHz minimum baud is 245
  17. // Serial1 on Teensy 3.2 @ 96 MHz minimum baud is 733
  18. // This example code is in the public domain.
  19. byte sentbyte;
  20. unsigned long prevmillis;
  21. byte testbyte=0xF0;
  22. void setup() {
  23. delay(200);
  24. Serial.begin(9600);
  25. while (!Serial) ; // wait for Arduino Serial Monitor
  26. Serial1.begin(mybaud); // connect a wire from TX1
  27. altser.begin(mybaud); // to AltSoftSerial RX
  28. Serial.println("AltSoftSerial Receive Test");
  29. prevmillis = millis();
  30. }
  31. void loop() {
  32. // transmit a test byte on Serial 1
  33. if (millis() - prevmillis > 250) {
  34. sentbyte = testbyte++;
  35. Serial1.write(sentbyte);
  36. prevmillis = millis();
  37. }
  38. // attempt to receive it by AltSoftSerial
  39. if (altser.available() > 0) {
  40. byte b = altser.read();
  41. Serial.println(b);
  42. if (b != sentbyte) Serial.println("***** ERROR *****");
  43. }
  44. }