View previous topic :: View next topic |
Author |
Message |
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Wed Mar 28, 2018 2:59 pm Post subject: nRF24 simple to use, multilink library |
|
|
Hello. For some new project I need send more than 32 nRF24 FiFo bytes. So I made this library/routines.
Feel free to improve cause I need it same way too
'*[CREDIT]*
'
' 1.Based on #AN151 from Evert Dekker (Extended to variable/flexible payload lenght)
' LINK https://www.mcselec.com/index.php?option=com_content&task=view&id=212&Itemid=57
'
' 2.modified FIFO routines from forum MCS user "ollopa"
' LINK https://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=7941&highlight=ring+buffer
'
'*[DESCRIPTION]*
'
' nRF24 have FIFO buffer but only for 32bytes. With this library you can send larger buffers/strings.
' Library gives opportunity to easy and quick setup and transmission handling
'.
' Up to six different incomming adressess can be easy programmed in the receive device.Use "Set_rx_address" for that.
' In this sub you must choose pipe nr and show six byte array with address. For simple two device link adress can be
' same for both.
'
' Be careful, and set power to the minimum if you test devices near each other. Use "Set_radio(1 , 0)" for that.
' Which means "channel 1, minimum power"
'
' Sub "Call Rfm24_routines() " should be frequently called in the loop. It set "Got_msg" flag if message with Enter arrive.
'
' If you want to send something then call "Tx_mode", fill "data_out" string and call "Send_string"
' Software FIFO buffer will chunk message into 32bytes max and will be sending it till the end, and switch to Rx_mode.
'
' Attached DEMO code will send 53 bytes every 2sec if switch/jumper is short to the ground.
Code: |
$regfile = "m328pdef.dat"
$crystal = 16000000
$baud = 115200
$hwstack = 32
$swstack = 16
$framesize = 32
Config Submode = New
'-[switch for test purposes]-
Switch Alias Pinc.0 : Config Switch = Input : Set Portc.0 'enable pullup on PORT not PIN!
'-[Timer for 10ms time base]-
Config Timer2 = Timer , Prescale = 1024 , Compare_a = Disconnect , Compare_b = Disconnect , Clear_timer = 1
Compare2a = 155 '10ms @16MHz/1024
$include "nRF24L01routines.inc"
Call Set_tx_address(device_tx_addr(1))
Call Set_rx_address(device_tx_addr(1) , 0 ) 'for only two nodes address here can be same as tx
Call Set_radio(1 , 0) 'Ch1 to Ch125 ,power 0min 3max
Do
If Tifr2.ocf2a = 1 Then '10ms
Tifr2.ocf2a = 1
Call Rfm24_routines()
'---------------------[NEW MESSAGE]------
If Got_msg = 1 Then
Print Data_in
Got_msg = 0 : Data_idx = 0 : Data_in = ""
End If
'----------------------------------------
If Miliseconds < 100 Then '1s timer 100 x10ms
Incr Miliseconds
Else
Miliseconds = 0
If Rxtx_mode = 0 Then
If Switch = 0 Then 'switch for test purposes
Call Tx_mode() 'want to send something
Data_out = "12345678901234567890123456789012345678901234567890-53" 'fill string
Call Send_string() 'fill FIFO
End If
End If
End If
'end 10ms
End If
Loop |
|
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Wed Mar 28, 2018 8:11 pm Post subject: |
|
|
Thank you for sharing your project.
RF24 is still very popular.
Good that you included the data-sheet. _________________ Mark |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Wed Mar 28, 2018 9:15 pm Post subject: |
|
|
This days you can buy 2$ version with PowerAmplifier and then have link with range up to 1km and this range is the key of popularity because nothing compares to this in this price |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Thu Mar 29, 2018 9:27 am Post subject: |
|
|
you mean the module with PA and LNA ?
You actual get 1 km distance? _________________ Mark |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Thu Mar 29, 2018 5:49 pm Post subject: |
|
|
I find Bug(in my code) that will do the Compare fail. Picture show the problem. I update first post shortly but there I`m showing how one of the sub should be modified.
Code: | Sub Load_nrf24()
Local Idx As Byte
Tx_bytes(1) = Wr_tx_pload
Idx = 1
While Head <> Tail
Incr Idx
If Idx > 32 Then Exit While
Tx_bytes(idx) = Pop_fifo()
Debug Chr(tx_bytes(idx));
Wend
Jump_here:
Call W_register(idx)
Set Ce 'Set CE for a short moment to transmit the fifo buffer
Waitus 500 '
Reset Ce
Rxtx_mode = 20 'wait x10ms
End Sub |
|
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Mon Apr 02, 2018 2:47 pm Post subject: |
|
|
I found that all my devices are nRF24L01plus versions that have additional baudrate 250kbps. So I add possibility to choose baudrate simply because lower baudrate should give longer range.
Code: | Call Set_radio(20 , 3 , 2mega) 'channel 1-126, power 0-3, Baudrate "250kbps","1mega", "2mega" |
This is done by setting 5 bit of the RF_SETUP. I attach new datasheet.
I was do some tests but I`m living in the "national park" so it is a forest, and range in the very bad weather (rain/snow and trees) is about 200m (measured with google maps).
Changing baudrate from 2mega to 250kbps change nothing in my case. I also do shielding for modules (pics attached) and this also change nothing.
Link is down exactly in the same place.
In the free time I do some tests in the open area.
There is one thing which I have not done yet. A scanner for all channels. Device can check if channel is occupied by another device and then our channel should be changed to another to avoid collisions/jamming. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Tue Apr 03, 2018 11:53 am Post subject: |
|
|
thanks for the update.
i think shielding will not help when you live in the forest.
maybe a good old external amplifier will help. and of course the perfect antenna/connectors will.
national forest? sounds beautiful:D _________________ Mark |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Tue Apr 03, 2018 3:41 pm Post subject: |
|
|
albertsm wrote: | national forest? sounds beautiful:D |
Hahaha yest it is. I moved 3 years ago and learn about peace and quiet. I moved from Silesia where noise is very big but it was imperceptible for me that time.
Now whenI visit my young years friends I hear that noise..but I can live wit that again. I like it
People can adapt to any enviroment .. but after a fiew days ..I miss about this quiet
I attach two pics. How much snow we have (snow chain for the wheels is a first aid kit here) and second pics is the deer/ roe-deer roe that came for apples which we do not gather ... because they come for apples in the winter when they are hungry
But I must add that we have here LTE ~20MBps and I have only 10min to near town So not bad |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Tue Apr 03, 2018 7:15 pm Post subject: |
|
|
it looks indeed as it sounds : beautiful. I always like the snow. This year we had to drive 800 km to Germany to get some decent snow. But it looks you have loads of it. Especial the trees look great.
Nice that you have deers in your back yard . I hope it remains that beautiful.
(sorry for off topic posts) _________________ Mark |
|
Back to top |
|
|
lslabs2005
Joined: 28 Dec 2004 Posts: 57
|
Posted: Sun Apr 08, 2018 3:23 am Post subject: can I use one Nrf24l01 as master and another 110 as slaves? |
|
|
can I use one Nrf24l01 as master and another 110 as slaves?
to replace standard RS485 cable network! |
|
Back to top |
|
|
sielcon
Joined: 16 Mar 2006 Posts: 74 Location: Argentina
|
Posted: Fri Nov 30, 2018 1:41 pm Post subject: |
|
|
Hello EDC, first of all I admire and appreciate the excellent work you have done with this lib. I want to ask you about a problem I have, I'm doing a development where there are several devices that speak only with one, everything works perfect while the TX and RX addresses are the same, when I change addresses what the terminal images show.
I need to use two RX addresses, one in all the devices and a different one in each, according to what I have read in the data sheet, it seems possible.
I would thank you if you can help me see what I'm doing wrong.
Best regards.
Compiler version :2.0.8.1
Compiler build :2.0.8.1.000
IDE version :2.0.8.1.001
Code: |
'- Setea address
Call Set_tx_address(device_tx_addr(1))
Call Set_rx_address(device_rx_addr_1(1) , 0 ) 'for only two nodes address here can be same as tx
' Call Set_rx_address(device_tx_addr(1) , 1 ) 'for only two nodes address here can be same as tx
'Setea canal, potencia y data rate
Call Set_radio(20 , 0 , 250kbps) 'Ch1 to Ch125 ,power 0min 3max
|
[img]
https://www.dropbox.com/s/685kzvao1qmkpv6/Image2.jpg?dl=0
[/img]
[img]
https://www.dropbox.com/s/9rwuwybkq5tnv6p/Image3.jpg?dl=0
[/img] |
|
Back to top |
|
|
sielcon
Joined: 16 Mar 2006 Posts: 74 Location: Argentina
|
Posted: Fri Nov 30, 2018 1:45 pm Post subject: |
|
|
It is better to see it like this |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Sat May 25, 2019 9:25 am Post subject: |
|
|
I am having problems with the multilink library
I can get #AN151 working ok
It seems to be passing an array in a sub I did not think this possible?
regards Paul
Code: |
Sub Set_tx_address(byref Addr_array() As Byte)
Reset Ce 'to get access to the registers
Tx_bytes(1) = Write_reg + Tx_addr 'TX adress
M = Memcopy(addr_array(1) , Tx_bytes(2) , 5)
Call W_register(6)
End Sub
|
|
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5921 Location: Holland
|
Posted: Tue May 28, 2019 11:37 am Post subject: |
|
|
sure you can pass an array to a sub. that is no problem. _________________ Mark |
|
Back to top |
|
|
|