Advertisement
SolderCore

SolderCore nRF905 Rx Script

Jul 14th, 2014
474
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' CoreBASIC script to configure a nrf905 to receive transmitted packets
  2. '
  3. CLS
  4. '
  5. '---Start of Constants-----
  6. '
  7. TX_EN = 6 ' TX_EN=1TX mode, TX_EN=0RX mode
  8. CS = 10 '   SPI chip select
  9. 'UPLCK = 1 ' output clock
  10. AM = 2 '    address match
  11. DR = 4 '    receive and and transmit data ready
  12. TRX_CE = 0 'enables chip for recieve and transmit
  13. PWR = 5 '   Power up chip
  14. CDT = 1
  15. '
  16. ' NRF905 cmds
  17. WC = 0
  18. RC = 0x10
  19. WTP = 0x20
  20. RTP = 0x21
  21. WTA = 0x22
  22. RTA = 0x23
  23. RRP = 0x24
  24. CC = 0x80
  25. '
  26. '
  27. ' Keep it simple write the config in one hit
  28. DEFAULTREG = [0x6C, 0x0C, 0x44, 0x20, 0x20, 0xB1, 0xB1, 0xB1, 0xA5, 0xD8]
  29. DIM REG(9)
  30. '
  31. '--- End of constants---
  32. '
  33. DIM ADRS(4)
  34. '
  35. ' Start of hardware setup
  36. '
  37. PIN CDT AS DIGITAL INPUT
  38. PIN AM AS DIGITAL INPUT
  39. PIN UPCLK AS DIGITAL INPUT
  40. PIN DR AS DIGITAL INPUT
  41. '
  42. PIN PWR AS DIGITAL OUTPUT
  43. PIN TXEN AS DIGITAL OUTPUT
  44. PIN TRX_CE AS DIGITAL OUTPUT
  45. '
  46. '
  47. INSTALL "SPI-DEVICE" USING CORE.D10 AS NRF905
  48. '
  49. '
  50. 'Configre device as receiver
  51. PIN TXEN = 0
  52. 'Power up the device
  53. PIN PWR = 1
  54. 'Enable the RF front end
  55. PIN TRX_CE = 1
  56. '
  57. PAUSE 0.1
  58. '
  59. '
  60. CALL WRITE_REGISTERS(DEFAULTREG)
  61. CALL READ_REGISTERS
  62. '
  63. PRINT "Ready to recieve"
  64. '
  65. '
  66. WHILE 1
  67.   WAIT PIN CDT = 1
  68.   TIMER = 0
  69.   REPEAT
  70.     IF PIN DR = 1 THEN
  71.       '
  72.       CALL READ_RX()
  73.       CORE.LED = 1
  74.       PAUSE 0.001
  75.       CORE.LED = 0
  76.     ENDIF
  77.   UNTIL TIMER > 50
  78. WEND
  79. '
  80. END
  81. '
  82. '
  83. ' read all configuration registers
  84. DEFPROC READ_REGISTERS()
  85.   CMD = RC
  86.   SPI NRF905 WRITE CMD READ 10 TO REG
  87.   '  PRINT HEX(EXPAND(REG))
  88. ENDPROC
  89. '
  90. ' writes to the config registers
  91. DEFPROC WRITE_REGISTERS(MYDATA)
  92.   CMD = WC
  93.   SPI NRF905 WRITE [CMD, MYDATA]
  94. ENDPROC
  95. '
  96. ' transmits a packet
  97. DEFPROC TX_DATA(ADDRESS, TXDATA)
  98.   CALL WRITE_TX_ADDRESS(ADDRESS)
  99.   CALL WRITE_TX_PAYLOAD(TXDATA)
  100.   '
  101.   PIN TRX_CE = 1
  102.   PIN TRX_CE = 0
  103. ENDPROC
  104. '
  105. '  write the data to be transmitted
  106. DEFPROC WRITE_TX_PAYLOAD(TXDATA)
  107.   CMD = WTP
  108.   SPI NRF905 WRITE [CMD, TXDATA]
  109. ENDPROC
  110. '
  111. ' write the address to which the tx payload should be transmitted to
  112. DEFPROC WRITE_TX_ADDRESS(ADDRESS)
  113.   CMD = WTA
  114.   SPI NRF905 WRITE [CMD, ADDRESS]
  115. ENDPROC
  116. '
  117. DEFPROC READ_RX()
  118.   CMD = RRP
  119.   SPI NRF905 WRITE CMD READ 32 TO RXPAYLOAD
  120.   PRINT RXPAYLOAD; " ";
  121. ENDPROC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement