PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

70 Zeilen
2.1KB

  1. // cc110_server.pde
  2. // -*- mode: C++ -*-
  3. // Example sketch showing how to create a simple messageing server
  4. // with the RH_CC110 class. RH_CC110 class does not provide for addressing or
  5. // reliability, so you should only use RH_CC110 if you do not need the higher
  6. // level messaging abilities.
  7. // It is designed to work with the other example cc110_client
  8. // Tested with Teensy 3.1 and Anaren 430BOOST-CC110L
  9. #include <SPI.h>
  10. #include <RH_CC110.h>
  11. // Singleton instance of the radio driver
  12. RH_CC110 cc110;
  13. void setup()
  14. {
  15. Serial.begin(9600);
  16. while (!Serial)
  17. ; // wait for serial port to connect. Needed for native USB
  18. // CC110L may be equipped with either 26 or 27MHz crystals. You MUST
  19. // tell the driver if a 27MHz crystal is installed for the correct configuration to
  20. // occur. Failure to correctly set this flag will cause incorrect frequency and modulation
  21. // characteristics to be used. You can call this function, or pass it to the constructor
  22. cc110.setIs27MHz(true); // Anaren 430BOOST-CC110L Air BoosterPack test boards have 27MHz
  23. if (!cc110.init())
  24. Serial.println("init failed");
  25. // After init(), the following default values apply:
  26. // TxPower: TransmitPower5dBm
  27. // Frequency: 915.0
  28. // Modulation: GFSK_Rb1_2Fd5_2 (GFSK, Data Rate: 1.2kBaud, Dev: 5.2kHz, RX BW 58kHz, optimised for sensitivity)
  29. // Sync Words: 0xd3, 0x91
  30. // But you can change them:
  31. // cc110.setTxPower(RH_CC110::TransmitPowerM30dBm);
  32. // cc110.setModemConfig(RH_CC110::GFSK_Rb250Fd127);
  33. //cc110.setFrequency(928.0);
  34. }
  35. void loop()
  36. {
  37. if (cc110.available())
  38. {
  39. // Should be a message for us now
  40. uint8_t buf[RH_CC110_MAX_MESSAGE_LEN];
  41. uint8_t len = sizeof(buf);
  42. if (cc110.recv(buf, &len))
  43. {
  44. // RH_CC110::printBuffer("request: ", buf, len);
  45. Serial.print("got request: ");
  46. Serial.println((char*)buf);
  47. // Serial.print("RSSI: ");
  48. // Serial.println(cc110.lastRssi(), DEC);
  49. // Send a reply
  50. uint8_t data[] = "And hello back to you";
  51. cc110.send(data, sizeof(data));
  52. cc110.waitPacketSent();
  53. Serial.println("Sent a reply");
  54. }
  55. else
  56. {
  57. Serial.println("recv failed");
  58. }
  59. }
  60. }