nRF24L01 does not receive multiple bytes

Discussion about wireless devices

nRF24L01 does not receive multiple bytes

Postby x-programer » Fri Oct 02, 2015 9:53 pm

Hello guys,

I'm new member in the forum and noob in electronics and embedded systems.

So, recently I have created a simple nRF24L01's library to send and receive data with arduino and pic 16f84. When I use the two pieces of nRF24l01 witharduino, everything works fine and the data is correctly transmitted. However, when I use the receiver with arduino and the sender with the 16F84, the receiver can receive only one byte. I would to mention that all the registers are well configured on both devices (sender/receiver), and both devices are power with 3v3.

for example:
#sender transmitts: 0x24 0x25 0x26 0x27 0x28 0x29
#receiver receives: 0x24 0x00 0x00 0x00 0x00 0x00, and sometimes it receives: 0x24 0x00 0x26 0x00 0x00 0x00

Hope you can help me to overcome this problem (it made me crazy) !!

PS: I attach the sender's code below.

Code: Select all
RF24_write_reg macro reg,val
   bcf RF24_CSN
   movlw reg
   call RF24_SPI_send ; REG
   movlw val
   call RF24_SPI_send ; VAL
   bsf RF24_CSN
   call delay_ms_10
   endm

RF24_write_reg_buffer macro reg,c1,c2,c3,c4,c5
   bcf RF24_CSN
   movlw reg
   call RF24_SPI_send ; REG
   movlw c1
   call RF24_SPI_send ; VAL
   movlw c2
   call RF24_SPI_send ; VAL
   movlw c3
   call RF24_SPI_send ; VAL
   movlw c4
   call RF24_SPI_send ; VAL
   movlw c5
   call RF24_SPI_send ; VAL
   bsf RF24_CSN
   call delay_ms_10
   endm


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; FUNCTION TO TRANSMIT DATA
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
RF24_Transmit
   ;;;;;;;;;;;;
   bcf RF24_CSN
   movlw 0xE1 ; flush TX
   call RF24_SPI_send
   bsf RF24_CSN
   RF24_write_reg 0x07,0x7E ; clear STATUS flags

   ;;;;;;;;;;;;
   bcf RF24_CSN
   movlw 0xA0 ; Write in the payload
   call RF24_SPI_send
   movlw 0x24
   call RF24_SPI_send
   movfw 0x25
   call RF24_SPI_send
   movlw 0x26
   call RF24_SPI_send
   movfw 0x27
   call RF24_SPI_send
   movfw 0x28
   call RF24_SPI_send
   movfw 0x29
   call RF24_SPI_send
   bsf RF24_CSN

   ;;;;;;;;;;;;;;;;;;;;;;;;
   call delay_ms_10
   bsf RF24_CE
   call delay_ms_10
   bcf RF24_CE
   
   call delay_ms_10
   return

   
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; FUNCTION TO CONFIGURE THE DEVICE AS TRANSMITTER
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
RF24_Config_TX
   bcf RF24_CE
   bsf RF24_CSN
   ;;;;;;;;;;;;
   call delay_ms_10
   ; Clear STATUS flags
   RF24_write_reg 0x27,0x7E

   ; Configure the device as transmitter
   RF24_write_reg 0x20,0x1C

   ; Write RX address (Pipe 0) 9A:FE:BF:ED:0C
   RF24_write_reg_buffer 0x2A,0x9A,0xFE,0xBF,0xED,0x0C

   ; Write TX address 9A:FE:BF:ED:0C
   RF24_write_reg_buffer 0x30,0x9A,0xFE,0xBF,0xED,0x0C

   ; Set the address width to 5
   RF24_write_reg 0x23,0x03

   ; Set the radio channel to CHANNEL
   RF24_write_reg 0x25,CHANNEL

   ; Set the retries to 4000us and 15
   RF24_write_reg 0x24,0xFF

   ; Set the device debit as 0dBm and 250 kbps
   RF24_write_reg 0x26,0x26

   ; Set the PAYLOAD size to 6
   RF24_write_reg 0x31,0x06

   ;;;;;;;;;;;;;;;;;;;;;;;;
   RF24_write_reg 0x1C,0x00

   ; Power up the device as transmitter
   RF24_write_reg 0x20,0x1E

   ; Flush RX and TX buffers
   RF24_write_reg 0xE2,0xE1

   bcf RF24_CE
   return
   

   
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; FUNCTION TO SEND AND READ DATA VIA SPI BUS (MSBFirst)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
RF24_SPI_send
   movwf outByte
   movlw 0x08
   movwf bits_counter
   clrf inByte
RF24_SPI_loop
   ; send data bits
   btfss outByte,7
   bcf RF24_MOSI
   btfsc outByte,7
   bsf RF24_MOSI
   bsf RF24_SCK
   ; read data bits
   btfsc RF24_MISO
   bsf inByte,0
   btfss RF24_MISO
   bcf inByte,0
   bcf RF24_SCK
   decfsz bits_counter,f
   goto RF24_next_bit
   goto RF24_end_sending
RF24_next_bit
   ; move to next bit
   rlf outByte,f
   rlf inByte,f
   goto RF24_SPI_loop
RF24_end_sending
   movfw inByte
   return
x-programer
 
Posts: 1
Joined: Fri Oct 02, 2015 9:07 pm

Re: nRF24L01 does not receive multiple bytes

Postby brennen » Mon Oct 05, 2015 1:04 pm

The first thing I would check would be to make absolutely sure you have really good power and ground connections to the L01 unit. The other would to be that you need to make sure you're using the correct SPI mode. If the SPI timing is off because you have an incorrect CPOL or CPHA setting in hardware, you could easily see problems like this. There's always the possibility of a wiring problem on your SPI bus or CE pin.
brennen
Site Admin
 
Posts: 395
Joined: Sun Aug 17, 2008 2:15 pm


Return to Wireless

Who is online

Users browsing this forum: No registered users and 2 guests

cron