​ ​ ​ nrf24 Receiver (ter) - Blogs - PICAXE Forum
View RSS Feed

kfjl

nrf24 Receiver (ter)

Rate this Entry
Code:
'RECEIVER          (nrf24_Receiver.bas)

'Power supply: 3.3V from computer USB or phone charger via FTDI =
'no 5V, phantom or otherwise, to fry nrf
'Inverter levels RX /  TX : 74HCT04

'1 GND    Black     GND
'2 VCC    Red        VCC     THREE point THREE volts !!!.!!!
'3 CE      Brown     B.1
'4 CSN    White     B.6
'5 SCK    Yellow    B.7
'6 MOSI   Green    SDO C.1
'7 MISO   Orange  SDI B.5
'8 INT      Grey      C.5  10k PullUP

#picaxe 20x2
#no_table
#no_data
       
symbol CE =   B.1      'Chip Enable 
symbol CSN =  B.6    'Chip Select Active low
symbol IRQ = pinC.5    'IRQ 
                       
init:
input  c.5          
output b.1
output b.6          
setfreq m16
hspisetup spimode00,spifast

high CSN     'active low
low CE
pause 100

'CONFIG_RX_MODE:

low csn
hspiout (%00100000,%00001011)   'REG0 CONFIG EN PRX + Power ON + EN CRC 1 byte
high csn

'REG1 EN_AA                              default: auto ack on all data pipes enabled
'REG2 EN_RXADDR                    default: data pipes 0 and 1 enabled
'REG3 SETUP_AW                       default: 5 byte addresses
'REG4                                           default                                                                             
'REG5 RF_CH                              default %00000010

low csn
hspiout (%00100110,%00001000) 'REG6 RF_SETUP 2Mbps -18dBm
high csn

'REGs 8+9                                               default
'REGs 10 to 15 pipe addresses           default
'REG  16 TX_ADDR                                default

low csn
hspiout (%00110001,1)    ' reg 17 (hex 11) RX payload width = 1 byte for data pipe 0
high csn

gosub clear_interrupts

MAIN:

pause 5000     ' Time to open the terminal ready to "readregs", if  needed
gosub readregs

setint %00000000,%00100000,c  '(20x2 Pin5 LOW)
sertxd("Waiting for data.1..",CR,LF)
high CE               ' Start listening
pause 10
do
   pause 100  'waiting for interrupt on data received
loop

interrupt:

pause 3
low ce  ' Stop listening 
low csn
hspiout (%01100001) ' Read Data in RX FIFO
hspiin (b10)
high csn

SERTXD ("Received ",#B10,CR,LF)

low csn
hspiout (%11100010)  'FLUSH RX FIFO
high csn

gosub clear_interrupts

setint %00000000,%00100000,c  'reset Picaxe interrupt
sertxd("Waiting for data...",CR,LF)
high CE       ' Start listening
return

Clear_interrupts:

low csn
hspiout (%00100111,%01110000)  
high csn
return

readregs: 

for b1 = 0 to 09  'registers 0 - 9 (decimal)    
low CSN
hspiout (b1)
hspiin (b0)
high CSN
sertxd(#b0,CR,LF) 
next b1

for b1 = 10 to 16    'Addresses with 5 byte registers
low csn
hspiout(b1)
hspiin (b4,b5,b6,b7,b8)
high csn
sertxd (#b4,#b5,#b6,#b7,#b8,CR,LF) 
next b1

for b1 = 17 to 23
low CSN
hspiout (b1)
hspiin (b0)
high CSN
sertxd (#b0,CR,LF)
next b1 
return
Maintenant, on Úcoute.

A suivre...

Submit "nrf24 Receiver (ter)" to Digg Submit "nrf24 Receiver (ter)" to del.icio.us Submit "nrf24 Receiver (ter)" to StumbleUpon Submit "nrf24 Receiver (ter)" to Google

Updated 12-11-2017 at 08:19 by kfjl

Tags: None Add / Edit Tags
Categories
Uncategorized

Comments