Transmit a word with nRF24l01

mushroom

New Member
Hi. I'm struggling to transmit via 2x nRF24L01 radio modules, each connected to picaxe 40x2's. I can send a byte, no problem, but trying to send a word fails. I only recieve the first byte of the word.
I know the first reply will be "where's your code, where's your schematic". That will come if need be, but I hope someone of knowledge of these tranceivers will direct me to a setup change that should be obvious to me.
 

BESQUEUT

Senior Member
I only recieve the first byte of the word.
I know the first reply will be "where's your code...
Supposing you are using serout...
- Data are variables/constants (0-255) which provide the data to be output.

serout 7,N2400,(wo)
will only write b0

So, try :
serout 7,N2400,(b1,b0)
 

mushroom

New Member
Supposing you are using serout...
- Data are variables/constants (0-255) which provide the data to be output.

serout 7,N2400,(wo)
will only write b0

So, try :
serout 7,N2400,(b1,b0)
thanks for the reply. No, not serout. I'm confident using serout with basic radio modules. I'm using hspi. This tranceiver has many programable parameters and I suspect a '1' or '0' in it's configeration has limited it to transmitting only one and not multible bytes per transmission. I'll clean my program of rem-ed out bits of unrelated programs, and post code in a couple of hours. Maybe others will gain insight into these tranceivers from my code.
Spent so much time pawing over data sheets with no success. I'm sure the solution is so simple.
 

mushroom

New Member
Transmission Code
Code:
*********************************
' nRF24L01+ Test Code for 40x2  TRANSMIT 
'***********************************


'GO TO "OPTIONS" > "EDITOR" AND check  SERIAL TERMINAL
' TO "OPEN AFTER DOWNLOAD"  and check "Use Colapsing Blocks" 
'===================================================
 
 'THIS IS CODE FOR THE TRANSMITTER  
 
 
#picaxe 40x2
#no_data
#no_table

Symbols:
{          
                       

symbol status     = 7
symbol data1 = W0
symbol nRF_Address = b2

#rem
	CE	C.0
	CSN	C.1
	IRQ	C.2			PICAXE 40x2
	SCK	C.3
	SDI	C.4 (MI)
	SDO	C.5 (MO)
#endrem


symbol CE =   C.0      'Chip Enable 
symbol CSN =  C.1      'Chip Select Active low)
symbol IRQ = pinC.2    'hardware IRQ1 

symbol Red1   = B.7
symbol Amber1 = B.6
symbol Green1 = B.5
symbol Red2   = B.4
symbol Amber2 = B.3
symbol Green2 = B.2
symbol Red3   = B.1
symbol Amber3 = B.0
symbol Green3 = D.7
symbol Red4   = D.6
symbol Amber4 = D.5
symbol Green4 = D.4

symbol GreenTimeA = 1000
symbol GreenTimeB = 1000
symbol GreenTimeC = 1000
symbol GreenTimeD = 1000

symbol AmberTime = 500
symbol ClearTime = 500



}
'=================== INIT ==============================
init:
{
	input  c.2 		'interupt          
	output c.0 		'CE
	output c.1		'CSN

	output B.7		'Red Lantern 1
	output B.6		'Amber Lantern 1
	output B.5		'Green Lantern 1 

	output B.4		'Red Lantern 2 
	output B.3		'Amber Lantern 2
	output B.2		'Green Lantern 2

	output B.1		'Red Lantern 3
	output B.0		'Amber Lantern 3
	output D.7		'Green Lantern 3 

	output D.6		'Red Lantern 4 
	output D.5		'Amber Lantern 4
	output D.4		'Green Lantern 4

	setfreq m16
	hspisetup spimode00,spislow 
	high CSN    'active low
	low CE
	gosub clear_interrupts
}

'NOTE:  Shockburst is not used.  NO ACK
  
 

'Adddress 00 
'enable PtX, power on, en_crc/2bytes,  all interrputs on 
	low csn                        
	hspiout (%00100000,%00001110) 
	high csn

	low csn
	hspiout (%00100110,%00000110)  'REG 6  Data Rate  1 mbps
	high csn
	setint %00000000,%00000100,c  '(Pic40X2 PinC.2 LOW)
	W0 = 0

	let pinsB = %10010010	'All reds on, others off
	let pinsD = %01001001	'All reds on, others off

MAIN:
'========================================================
do
	setint %00000000,%00000100,c  '(Pic40X2 PinC.2 LOW - IRQ)

		Gosub Go1
		Gosub Go2
		Gosub Go3
		Gosub Go4
		
loop


	
'=============== END MAIN =================================		
		
		
Transmit:


	low csn              'FLUSH TX FIFO  redundant
	hspiout (%11100001)
	high csn

	low CSN
	hspiout (%10100000,w0)    'write 2 byte to tx fifo
	high csn
  

	low csn                        
	hspiout (%00100000,%00001110)  'POWER UP 
	high csn
	PAUSE 5
	
	pulsout CE,220    'TRANSMIT DATA    
	pause 5
	
	   
	low csn              'FLUSH TX FIFO  Redundant
	hspiout (%11100001)
	high csn
'debug
return


interrupt:
{
'the nRF has generated an interupt
;pause 500

;LOW CSN
;hspiin (b0)
;HSPIOUT (%11111111)
;HIGH CSN
'status data is now in b0 (data1) bits 4,5, & 6
 'Bit 4 is Max_RT
 'Bit 5 is  TX_DS  (Data Sent
 ;bit 6 is RX_DR  (data received) 

;if bit4 = 1 then 
;sertxd ("Interrupt on MAX_RT",cr,lf) 
;else 
;if bit5 = 1 then
;sertxd ("Interrupt on TX_DS",cr,lf) 
;else 
;if bit6 = 1 then  
;sertxd ("Interrupt on RX_DR",cr,lf)
;endif endif endif
gosub clear_interrupts
setint %00000000,%00000100,c  '(Pic40X2 PinC.2 LOW)
return
}

Clear_interrupts:
{
nRF_address = status + 32
low csn
hspiout (nRF_address,%01110000)  
high csn
return
}

Go1:

	let b0 = %00110010	'set Memory B0 ready to transmit
	let b1 = %01001001	'set Memory B1 ready to transmit
		
gosub Transmit
	
	let pinsB = %00110010	'Green1 'on', red 'on' lanterns 2,3 on 'B' Bank
	let pinsD = %01001001	'All reds 'on', others 'off' on 'D' Bank.
	
	Pause GreenTimeA
	
	let b0 = %01010010	'set Memory B0 ready to transmit
	let b1 = %01001001	'set Memory B1 ready to transmit
	
Gosub Transmit
	
	let pinsB = %01010010	'Green1 'off', Amber1 'on'on Bank B
	let PinsD = %01001001	'All reds 'on', rest 'off' on 'D' Bank.
	
	Pause AmberTime
	
	let b0 = %10010010	'set Memory B0 ready to transmit
	let b1 = %01001001	'set Memory B1 ready to transmit
	
Gosub Transmit
	
	let PinsB = %10010010	'Amber1 'off', Red 'on' lanterns 1,2,3 on 'B'Bank
	let PinsD = %01001001	'All reds 'on', rest 'off' on 'D' Bank.

	pause ClearTime

Return
	
Go2:
	let b0 = %10000110	'set Memory B0 ready to transmit
	let b1 = %01001001	'set Memory B1 ready to transmit
gosub Transmit
	let pinsB = %10000110	'Green2 'on', red2 'on' other lanterns Red
	let pinsD = %01001001	'All reds 'on', rest 'off' on 'D' Bank.
Pause GreenTimeB
	
	let b0 = %10001010	'set Memory B0 ready to transmit
	let b1 = %01001001	'set Memory B1 ready to transmit
Gosub Transmit
	let pinsB = %10001010	'Green2 'off', Amber2 'on' on Bank 'B'
	let PinsD = %01001001	'All reds 'on', rest 'off' on 'D' Bank.
Pause AmberTime
	
	let b0 = %10010010	'set Memory B0 ready to transmit
	let b1 = %01001001	'set Memory B1 ready to transmit
Gosub Transmit
	let PinsB = %10010010	'Amber2 'off', Red 'on' on Bank 'B'
	let PinsD = %01001001	'All reds 'on', rest 'off' on 'D' Bank.
pause ClearTime

Return
	
'#rem
Go3:
	let b0 = %10010000	'set Memory B0 ready to transmit
	let b1 = %11001001	'set Memory B1 ready to transmit
gosub Transmit
	let pinsB = %10010000	'Red3 'off' other lanterns Red
	let pinsD = %11001001	'Green3 'on', other lanterns Red.
Pause GreenTimeA
	
	let b0 = %10010001	'set Memory B0 ready to transmit
	let b1 = %01001001	'set Memory B1 ready to transmit
Gosub Transmit
	let pinsB = %10010001	'Green3 'off', Amber3 'on'. Other lanterns Red
	let PinsD = %01001001	'All reds 'on', rest 'off' on 'D' Bank.
Pause AmberTime
	
	let b0 = %10010010	'set Memory B0 ready to transmit
	let b1 = %01001001	'set Memory B1 ready to transmit
Gosub Transmit
	let PinsB = %10010010	'Amber2 'off', All reds 'on' on Bank 'B'
	let PinsD = %01001001	'All reds 'on', rest 'off' on 'D' Bank.
pause ClearTime

Return

Go4:
	let b0 = %10010010	'set Memory B0 ready to transmit
	let b1 = %00011001	'set Memory B1 ready to transmit
gosub Transmit
	let pinsB = %10010000	'Red3 'off' other lanterns Red
	let pinsD = %00011001	'Green3 'on', other lanterns Red.
Pause GreenTimeA
	
	let b0 = %10010010	'set Memory B0 ready to transmit
	let b1 = %00101001	'set Memory B1 ready to transmit
Gosub Transmit
	let pinsB = %10010010	'Green3 'off', Amber3 'on'. Other lanterns Red
	let PinsD = %00101001	'All reds 'on', rest 'off' on 'D' Bank.
Pause AmberTime
	
	let b0 = %10010010	'set Memory B0 ready to transmit
	let b1 = %01001001	'set Memory B1 ready to transmit
Gosub Transmit
	let PinsB = %10010010	'Amber3 'off', All reds 'on' on Bank 'B'
	let PinsD = %01001001	'All reds 'on', rest 'off' on 'D' Bank.
pause ClearTime

Return
Receiver Code
Code:
'*******************************
' nRF24L01+ Test Code  RECEIVE
'*******************************


'GO TO "OPTIONS" > "EDITOR" AND check  SERIAL TERMINAL
' TO "OPEN AFTER DOWNLOAD"  and check "use colapsing blocks" 
'===================================================
 
 'THIS IS CODE FOR THE RECEIVER  
 
 
#picaxe 40x2
#no_table
#no_data

Symbols:
{          

                       

symbol status     = 7
symbol data1 = W0
symbol nRF_Address = b2
#rem
	CE	C.0
	CSN	C.1
	IRQ	C.2
	SCK	C.3
	SDI	C.4 (MI)
	SDO	C.5 (MO)
#endrem

symbol CE =   C.0      'Chip Enable 
symbol CSN =  C.1      'Chip Select Active low)
symbol IRQ = pinc.2    'hardware IRQ1

symbol Red1   = B.7	
symbol Amber1 = B.6	
symbol Green1 = B.5	
symbol Red2   = B.4	
symbol Amber2 = B.3	
symbol Green2 = B.2	
symbol Red3   = B.1
symbol Amber3 = B.0
symbol Green3 = D.7
symbol Red4   = D.6
symbol Amber4 = D.5
symbol Green4 = D.4

}
'=================== INIT ==============================
init:
{
	input  C.2	'IRQ
	output C.0	'CE  Trans
	output C.1	'CSN Trans
	
	output B.7		'Red Lantern 1
	output B.6		'Amber Lantern 1
	output B.5		'Green Lantern 1 

	output B.4		'Red Lantern 2 
	output B.3		'Amber Lantern 2
	output B.2		'Green Lantern 2

	output B.1		'Red Lantern 3
	output B.0		'Amber Lantern 3
	output D.7		'Green Lantern 3 

	output D.6		'Red Lantern 4 
	output D.5		'Amber Lantern 4
	output D.4		'Green Lantern 4

	setfreq m16
	hspisetup spimode00,spislow 
	high CSN    'active low
	low CE
	gosub clear_interrupts
	w8 = 0

}

CONFIG_RX_MODE:
{
'Reg 0 "Config"
	'enable PRX, power on, en_crc/2bytes,  Max Tries interrput on 
	low csn
	hspiout (%00100000,%00001111)   'Write setup to config register
	high csn
	
'REG 6 "RF setup"  
	'Data Rate  1 mbps *(2 mbps Maybe better or not)	
	low csn
	hspiout (%00100110,%00000110)   ' REG 6  (Data Rate = 1 mbps)
	high csn

'REG 11 "RF setup"  
	low csn
	hspiout (%00110010,1)    ' reg 11 - payload = 2 bytes for data pipe 0
	'hspiout (%00110001,1)    ' reg 17 (hex 11) payload = 1 bytes for data pipe 0
	high csn
}

	let pinsB = %10010010	'All reds on, others off
	let pinsD = %01001001	'All reds on, others off
	pause 500
	
'=================== MAIN ==============================
MAIN:
	setint %00000000,%00000100,c  '(Pic40X2 PinC.2 LOW)
'	w8 = 0
#rem
  	low Amber1		'Amber 1 Off
  	low Green1		'Green 1 Off
 	low Amber2		'Amber 2 Off
 	low Green2		'Green 2 Off
	low Amber3		'Amber 1 Off
  	low Green3		'Green 1 Off
 	low Amber4		'Amber 2 Off
	low Green4		'Green 2 Off
	
	 #endrem
	'w8 = 0
do
	




  	high CE
  	pause 10
	low CE
	
loop


interrupt:

'The nRF has received data and has generated an interupt on RX_DR
	pause 3
	low ce  'Receiver in standby
	
	low csn
	hspiout (%01100001,%01100001) ' Read Data in RX FIFO    ADDED EXTRA BYTE
	hspiin (W0)
	high csn


'SERTXD (#B0,CR,LF)

	low csn
	hspiout (%11100001)  'FLUSH RX FIFO
	high csn
debug

let pinsB = b0

'let pinsD = %11100001
let pinsD = B1
pause 10

gosub clear_interrupts

	setint %00000000,%00000100,c  '(Pic40X2 PinC.2 LOW)
return


Clear_interrupts:
{
	nRF_address = status + 32
	
	low csn
	hspiout (%00100111,%01110000)  
	high csn
	return
}
 

mushroom

New Member
Think of this project as 4 sets of model traffic lights on a slot car track, hence the 4 sets of Red, Amber and Green defined in 'symbols'.
I'm trying to transmit variable W0, then on receipt, intend to put B0 onto 'b' bank of output pins, and B1 onto 'D' bank of output pins.
 

inglewoodpete

Senior Member
As BESQUEUT has said previously, you need to send bytes. Practically all microcontrollers only have 8-bit serial send and receive buffers. That is for synchronous and asynchronous serial transmission.

BESQUEUT may have confused your chip with Rev-Ed's NKM2401 wireless packet chip. If you have searched the forum and found very little discussion on your chip, it is courtesy to post a link to it. That will help others to help you.

So, even if you are using SPI or hSPI, you need to send bytes. Fortunately, the 16-bit w0 register breaks down into two byte registers, b0 and b1.
 

mushroom

New Member
As BESQUEUT has said previously, you need to send bytes. Practically all microcontrollers only have 8-bit serial send and receive buffers. That is for synchronous and asynchronous serial transmission.

BESQUEUT may have confused your chip with Rev-Ed's NKM2401 wireless packet chip. If you have searched the forum and found very little discussion on your chip, it is courtesy to post a link to it. That will help others to help you.

So, even if you are using SPI or hSPI, you need to send bytes. Fortunately, the 16-bit w0 register breaks down into two byte registers, b0 and b1.
Just realised I could send one byte and save in B0, then another byte and save in B1. Then I saw your post, Besqueut. I think you are right. Data sheet suggests to me that up to 32 bytes can be sent in a tranmission, but that may need to be provided as individual bytes. My mind works like a Vic20 computer. Slow processing speed, but gets results eventually. I'll post the, hopefully, positive results after trying it. That might help others.
 

mushroom

New Member
Hi,

I realized a study of nRF24L01 +, with TX and RX codes.
Can this help you?
Look at ---> http://www.alpmn.byethost32.com/nrf24l01p.htm

cordially
-----------------------------
Zorgloub, Yes looks useful. I cannot read the first half, the French half, as I only understand English. Will view the data section (in English), when time permits and post progress when possible. Thanks for the link. Progress has been delayed by the death of a friend.
 

zorgloub

Member
Hi Mushroom,
In fact, the hspiout command (and not Serout) must be used with this transceiver!
At the beginning of my (long!) study of this component, I had found tutorials but it was not suitable for the nRF24L01_PLUS!
The configuration of the registers is very important.
I have taken them in detail at the bottom of my web page web.
The code of my programs also contains some comments in English.
I hope that all this can help you ...
For my tests (see programs at the bottom of my web page), I only send Bytes.
But you can always restore a Word from two bytes sent one behind the other!
Looking forward to reading the progress of your work.
 
Top