Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' CoreBASIC script to configure a nrf905 and transmit a few packets
- '
- '
- '---Start of Constants-----
- CLS
- '
- TX_EN = 7 ' TX_EN=1TX mode, TX_EN=0RX mode
- CS = 10 ' SPI chip select
- UPLCK = 1 ' output clock
- AM = 2 ' address match
- DR = 3 ' receive and and transmit data ready
- TRX_CE = 0 'enables chip for recieve and transmit
- PWR = 5 ' Power up chip
- '
- '
- ' 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, 0, 0x44, 0x20, 0x20, 0xB1, 0xB1, 0xB1, 0xA5, 0xD8]
- 'DIM REG(9)
- '
- '--- End of constants---
- '
- DIM ADRS(4)
- TXDATA = ZER(32)
- '
- ' 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
- '
- '
- 'Power donwn the device
- PIN PWR = 0
- '
- 'Configre device as transmitter
- PIN TXEN = 1
- '
- 'Disable the RF
- PIN TRX_CE = 0
- '
- PIN PWR = 1
- PAUSE 0.1
- '
- CALL WRITE_REGISTERS(DEFAULTREG)
- '
- PRINT "Config Data: ";
- CALL READ_REGISTERS
- CALL WRITE_TX_PAYLOAD(TXDATA)
- '
- ADDRESS = [0xB1, 0xB1, 0xB1, 0xA5]
- '
- TXDATA = 1
- '
- '
- PRINT "Transmitting..."
- ' Do this 500 times.
- FOR I = 0 TO 500
- ' Clear the tx packet
- TXDATA = ZER(32)
- CALL WRITE_TX_PAYLOAD(TXDATA)
- TXDATA = 0
- TIMER = 0
- '
- '
- WHILE TIMER < 1000 'mS
- PRINT ".";
- CORE.LED = 1
- CALL TX_DATA(ADDRESS, STR(TXDATA))
- TXDATA = TXDATA + 1
- WAIT PIN DR = 1
- CORE.LED = 0
- WEND
- '
- PAUSE 1
- '
- NEXT I
- '
- 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
- ' PAUSE 0.01
- PIN TRX_CE = 0
- ENDPROC
- '
- ' write the data to be transmitted
- DEFPROC WRITE_TX_PAYLOAD(TXDATA)
- CMD = WTP
- SPI NRF905 WRITE [CMD, TXDATA]
- ' CMD = RTP
- ' SPI NRF905 WRITE CMD READ 32 TO TXDATA
- ' PRINT 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]
- ' CMD = RTA
- ' SPI NRF905 WRITE CMD READ 4 TO ADDRESS
- ' PRINT HEX(EXPAND(ADDRESS))
- ENDPROC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement