PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HardwareSerial.ino 1.5KB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /********************************************************************
  2. - Snooze REDUCED_CPU_BLOCK Hardware Serial Example -
  3. HardwareSerial1_LP Driver Class reconfigures Serial1 to work at
  4. a CPU speed of 2 MHz while in the REDUCED_CPU_BLOCK.
  5. Use second Teensy to read from this serial port.
  6. Supported Micros: T-LC/3.x
  7. ********************************************************************/
  8. #include <Snooze.h>
  9. #include "HardwareSerial1_LP.h"
  10. #include "delay.h"
  11. // User Driver Class to make Serial1 work at 2 MHz in the REDUCED_CPU_BLOCK
  12. HardwareSerial1_LP serial1(115200);
  13. // install low power hardware serial driver to a SnoozeBlock
  14. SnoozeBlock serialConfig(serial1);
  15. elapsedMillis time;
  16. void setup() {
  17. pinMode(LED_BUILTIN, OUTPUT);
  18. // start Serial1 normally at F_CPU
  19. Serial1.begin(115200);
  20. time = 0;
  21. }
  22. void loop() {
  23. // print serial1 running at F_CPU
  24. Serial1.printf("F_CPU:\t%i\n", F_CPU);
  25. Serial1.flush();
  26. digitalWriteFast(LED_BUILTIN, LOW);
  27. // REDUCED_CPU_BLOCK will run the HardwareSerial1_LP Driver before
  28. // and after the code inside the brackets
  29. REDUCED_CPU_BLOCK(serialConfig) {
  30. // print serial1 with cpu running at 2 MHz
  31. Serial1.print("2_MHZ:\t2000000\n");
  32. Serial1.flush();
  33. time = 0;
  34. // see delay.c
  35. delay_lp(1000);
  36. uint32_t t = time;
  37. Serial1.printf("DELAY:\t%i\n", t);
  38. Serial1.println("----------------------------------------");
  39. Serial1.flush();
  40. }
  41. digitalWriteFast(LED_BUILTIN, HIGH);
  42. delay(500);
  43. }