Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' CoreBASIC script to configure a nrf905 to receive transmitted packets
- '
- CLS
- '
- '---Start of Constants-----
- '
- TX_EN = 6 ' TX_EN=1TX mode, TX_EN=0RX mode
- CS = 10 ' SPI chip select
- 'UPLCK = 1 ' output clock
- AM = 2 ' address match
- DR = 4 ' receive and and transmit data ready
- TRX_CE = 0 'enables chip for recieve and transmit
- PWR = 5 ' Power up chip
- CDT = 1
- '
- ' NRF905 cmds
- WC = 0
- RC = 0x10
- WTP = 0x20
- RTP = 0x21
- WTA = 0x22
- RTA = 0x23
- RRP = 0x24
- CC = 0x80
- '
- '
- ' Keep it simple write the config in one hit
- DEFAULTREG = [0x6C, 0x0C, 0x44, 0x20, 0x20, 0xB1, 0xB1, 0xB1, 0xA5, 0xD8]
- DIM REG(9)
- '
- '--- End of constants---
- '
- DIM ADRS(4)
- '
- ' Start of hardware setup
- '
- PIN CDT AS DIGITAL INPUT
- PIN AM AS DIGITAL INPUT
- PIN UPCLK AS DIGITAL INPUT
- PIN DR AS DIGITAL INPUT
- '
- PIN PWR AS DIGITAL OUTPUT
- PIN TXEN AS DIGITAL OUTPUT
- PIN TRX_CE AS DIGITAL OUTPUT
- '
- '
- INSTALL "SPI-DEVICE" USING CORE.D10 AS NRF905
- '
- '
- 'Configre device as receiver
- PIN TXEN = 0
- 'Power up the device
- PIN PWR = 1
- 'Enable the RF front end
- PIN TRX_CE = 1
- '
- PAUSE 0.1
- '
- '
- CALL WRITE_REGISTERS(DEFAULTREG)
- CALL READ_REGISTERS
- '
- PRINT "Ready to recieve"
- '
- '
- WHILE 1
- WAIT PIN CDT = 1
- TIMER = 0
- REPEAT
- IF PIN DR = 1 THEN
- '
- CALL READ_RX()
- CORE.LED = 1
- PAUSE 0.001
- CORE.LED = 0
- ENDIF
- UNTIL TIMER > 50
- WEND
- '
- END
- '
- '
- ' read all configuration registers
- DEFPROC READ_REGISTERS()
- CMD = RC
- SPI NRF905 WRITE CMD READ 10 TO REG
- ' PRINT HEX(EXPAND(REG))
- ENDPROC
- '
- ' writes to the config registers
- DEFPROC WRITE_REGISTERS(MYDATA)
- CMD = WC
- SPI NRF905 WRITE [CMD, MYDATA]
- ENDPROC
- '
- ' transmits a packet
- DEFPROC TX_DATA(ADDRESS, TXDATA)
- CALL WRITE_TX_ADDRESS(ADDRESS)
- CALL WRITE_TX_PAYLOAD(TXDATA)
- '
- PIN TRX_CE = 1
- PIN TRX_CE = 0
- ENDPROC
- '
- ' write the data to be transmitted
- DEFPROC WRITE_TX_PAYLOAD(TXDATA)
- CMD = WTP
- SPI NRF905 WRITE [CMD, TXDATA]
- ENDPROC
- '
- ' write the address to which the tx payload should be transmitted to
- DEFPROC WRITE_TX_ADDRESS(ADDRESS)
- CMD = WTA
- SPI NRF905 WRITE [CMD, ADDRESS]
- ENDPROC
- '
- DEFPROC READ_RX()
- CMD = RRP
- SPI NRF905 WRITE CMD READ 32 TO RXPAYLOAD
- PRINT RXPAYLOAD; " ";
- ENDPROC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement