Advertisement
SolderCore

nRF905 SolderCore Tx Script

Jul 14th, 2014
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' CoreBASIC script to configure a nrf905 and transmit a few packets
  2. '
  3. '
  4. '---Start of Constants-----
  5. CLS
  6. '
  7. TX_EN = 7 ' 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 = 3 '    receive and and transmit data ready
  12. TRX_CE = 0 'enables chip for recieve and transmit
  13. PWR = 5 '   Power up chip
  14. '
  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, 0, 0x44, 0x20, 0x20, 0xB1, 0xB1, 0xB1, 0xA5, 0xD8]
  29. 'DIM REG(9)
  30. '
  31. '--- End of constants---
  32. '
  33. DIM ADRS(4)
  34. TXDATA = ZER(32)
  35. '
  36. ' Start of hardware setup
  37. '
  38. PIN CDT AS DIGITAL INPUT
  39. PIN AM AS DIGITAL INPUT
  40. PIN UPCLK AS DIGITAL INPUT
  41. PIN DR AS DIGITAL INPUT
  42. '
  43. PIN PWR AS DIGITAL OUTPUT
  44. PIN TXEN AS DIGITAL OUTPUT
  45. PIN TRX_CE AS DIGITAL OUTPUT
  46. '
  47. INSTALL "SPI-DEVICE" USING CORE.D10 AS NRF905
  48. '
  49. '
  50. 'Power donwn the device
  51. PIN PWR = 0
  52. '
  53. 'Configre device as transmitter
  54. PIN TXEN = 1
  55. '
  56. 'Disable the RF
  57. PIN TRX_CE = 0
  58. '
  59. PIN PWR = 1
  60. PAUSE 0.1
  61. '
  62. CALL WRITE_REGISTERS(DEFAULTREG)
  63. '
  64. PRINT "Config Data: ";
  65. CALL READ_REGISTERS
  66. CALL WRITE_TX_PAYLOAD(TXDATA)
  67. '
  68. ADDRESS = [0xB1, 0xB1, 0xB1, 0xA5]
  69. '
  70. TXDATA = 1
  71. '
  72. '
  73. PRINT "Transmitting..."
  74. ' Do this 500 times.
  75. FOR I = 0 TO 500
  76.   ' Clear the tx packet
  77.   TXDATA = ZER(32)
  78.   CALL WRITE_TX_PAYLOAD(TXDATA)
  79.   TXDATA = 0
  80.   TIMER = 0
  81.   '
  82.   '
  83.   WHILE TIMER < 1000 'mS
  84.     PRINT ".";
  85.     CORE.LED = 1
  86.     CALL TX_DATA(ADDRESS, STR(TXDATA))
  87.     TXDATA = TXDATA + 1
  88.     WAIT PIN DR = 1
  89.     CORE.LED = 0
  90.   WEND
  91.   '
  92.   PAUSE 1
  93.   '
  94. NEXT I
  95. '
  96. END
  97. '
  98. '
  99. ' read all configuration registers
  100. DEFPROC READ_REGISTERS()
  101.   CMD = RC
  102.   SPI NRF905 WRITE CMD READ 10 TO REG
  103.   PRINT HEX(EXPAND(REG))
  104. ENDPROC
  105. '
  106. ' writes to the config registers
  107. DEFPROC WRITE_REGISTERS(MYDATA)
  108.   CMD = WC
  109.   SPI NRF905 WRITE [CMD, MYDATA]
  110. ENDPROC
  111. '
  112. ' transmits a packet
  113. DEFPROC TX_DATA(ADDRESS, TXDATA)
  114.   CALL WRITE_TX_ADDRESS(ADDRESS)
  115.   CALL WRITE_TX_PAYLOAD(TXDATA)
  116.   '
  117.   PIN TRX_CE = 1
  118.   '  PAUSE 0.01
  119.   PIN TRX_CE = 0
  120. ENDPROC
  121. '
  122. '  write the data to be transmitted
  123. DEFPROC WRITE_TX_PAYLOAD(TXDATA)
  124.   CMD = WTP
  125.   SPI NRF905 WRITE [CMD, TXDATA]
  126.   ' CMD = RTP
  127.   ' SPI NRF905 WRITE CMD READ 32 TO TXDATA
  128.   ' PRINT TXDATA
  129.   '
  130. ENDPROC
  131. '
  132. ' write the address to which the tx payload should be transmitted to
  133. DEFPROC WRITE_TX_ADDRESS(ADDRESS)
  134.   CMD = WTA
  135.   SPI NRF905 WRITE [CMD, ADDRESS]
  136.   ' CMD = RTA
  137.   ' SPI NRF905 WRITE CMD READ 4 TO ADDRESS
  138.   ' PRINT HEX(EXPAND(ADDRESS))
  139. ENDPROC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement