Guest User

Untitled

a guest
Jul 23rd, 2014
65
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * Project: nRF905 AVR/Arduino Library/Driver
  3. * Author: Zak Kemble, contact@zakkemble.co.uk
  4. * Copyright: (C) 2013 by Zak Kemble
  5. * License: GNU GPL v3 (see License.txt)
  6. * Web: http://blog.zakkemble.co.uk/nrf905-avrarduino-librarydriver/
  7. */
  8.  
  9. /*
  10. * Wait for data and reply.
  11. * Output power is set to the lowest setting, receive sensitivity is lowered.
  12. *
  13. * 7 -> CE
  14. * 8 -> PWR
  15. * 9 -> TXE
  16. * 2 -> CD
  17. * 3 -> DR
  18. * 10 -> CSN
  19. * 12 -> SO
  20. * 11 -> SI
  21. * 13 -> SCK
  22. */
  23.  
  24. #include <nRF905.h>
  25. #include <SPI.h>
  26.  
  27. void setup()
  28. {
  29. // Start up
  30. nRF905_init();
  31.  
  32. // Put into receive mode
  33. nRF905_receive();
  34.  
  35. Serial.begin(9600);
  36.  
  37. Serial.println(F("Server started"));
  38. }
  39.  
  40. void loop()
  41. {
  42. Serial.println(F("Waiting for ping..."));
  43.  
  44. // Make buffer for data
  45. char buffer[NRF905_MAX_PAYLOAD];
  46.  
  47. // Wait for data
  48. while(!nRF905_getData(buffer, sizeof(buffer)));
  49.  
  50. Serial.println(F("Got ping"));
  51.  
  52. // Set payload data (reply with data received)
  53. nRF905_setData(buffer, sizeof(buffer));
  54.  
  55. Serial.println(F("Sending reply..."));
  56.  
  57. // Send payload (send fails if other transmissions are going on, keep trying until success)
  58. while(!nRF905_send());
  59.  
  60. // Put back into receive mode
  61. nRF905_receive();
  62.  
  63. Serial.println(F("Reply sent"));
  64.  
  65. // Show raw data
  66. Serial.print(F("Raw: "));
  67. Serial.write((byte*)buffer, sizeof(buffer));
  68. Serial.println();
  69.  
  70. // Printout ping contents
  71. Serial.print(F("Data: "));
  72.  
  73. if(strncmp(buffer, "test test", sizeof(buffer)) == 0)
  74. Serial.println("OK");
  75. else
  76. Serial.println("Fail");
  77. }
RAW Paste Data