Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. #include <cc1101.h>
  2. #include "EEPROM.h"
  3. #include <SPI.h>
  4. #include <SD.h>
  5.  
  6. CC1101 cc1101;
  7. byte syncWord = 199;
  8.  
  9. File file;
  10. const String fStart = "DATA_";
  11. const String fEnd = ".TXT";
  12. int fInt = 0;
  13. String Ffile = "DATA_0.TXT";
  14.  
  15. String data = "";
  16. byte in;
  17. byte inA[61];
  18. int inputA = 0;
  19. int inputB = 0;
  20.  
  21. void setup() {
  22. // SD Start
  23. if (!SD.begin(10)) {
  24. return;
  25. }
  26. Serial.begin(250000);
  27.  
  28. while (SD.exists(fStart + (String) fInt + fEnd)) {
  29. fInt++;
  30. }
  31.  
  32. Ffile = fStart + (String) fInt + fEnd;
  33. Serial.println("Ready: " + Ffile);
  34.  
  35. // Funk Start
  36. cc1101.init();
  37.  
  38. cc1101.setSyncWord(&syncWord, false);
  39. cc1101.setCarrierFreq(CFREQ_433);
  40. cc1101.disableAddressCheck();
  41.  
  42. delay(1000);
  43.  
  44. Serial.print("CC1101_PARTNUM ");
  45. Serial.println(cc1101.readReg(CC1101_PARTNUM, CC1101_STATUS_REGISTER));
  46. Serial.print("CC1101_VERSION ");
  47. Serial.println(cc1101.readReg(CC1101_VERSION, CC1101_STATUS_REGISTER));
  48. Serial.print("CC1101_MARCSTATE ");
  49. Serial.println(cc1101.readReg(CC1101_MARCSTATE, CC1101_STATUS_REGISTER));
  50.  
  51. Serial.println("device initialized");
  52. }
  53.  
  54. void loop() {
  55. while (Serial.available()) {
  56. in = Serial.read();
  57. data += char(in);
  58. }
  59.  
  60. }
  61.  
  62. void send_data(byte data[]) {
  63. CCPACKET packet;
  64. packet.length = sizeof(data);
  65. int c = 0;
  66. for (c = 0; c < sizeof(data); c++)
  67. {
  68. packet.data[c] = data[c];
  69. }
  70.  
  71. Serial.print("CC1101_MARCSTATE ");
  72. Serial.println(cc1101.readReg(CC1101_MARCSTATE, CC1101_STATUS_REGISTER));
  73. if (cc1101.sendData(packet)) {
  74. Serial.println(" sent ok :)");
  75. } else {
  76. Serial.println(" sent failed :(");
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement