STM32F4 Discovery board - Keil 5 IDE with CubeMX: Tutorial 24 - NRF24L01 Radio Transceiver
HTML-код
- Опубликовано: 14 окт 2024
- This video tutorial shows how to use the NRF24L01 radio transceiver, by sharing a library that I've written for the NRF24. Here is a link for the library files and source code:
github.com/MYa...
Wonderful tutorial, also helped me, building a bidirectional RF transmission with the NRF24L01+.
There's one thing which could be interesting for some of you here, where I was struggeling for a longer time: I tried to use the automatic acknowledge functionality and always after the first transmission it stopped working. Well, the reason was not too abvious for me in the beginning but does make sense now: In order to save battery, I'm always taking away the battery completely from the transmitter after sending my data. This again always resets the internal counter, which is managed by the NRF24L01+ chip internally. When sending a second time, means, by pressing my transmission button again, this counter was then on the same value as before - and the receiver thinks that this was just a repetition of the first signal, and ignors it.
So in other words: If you plan to remove the power of the transmitting chip, then you should:
a) Use the non-acknowledged single way transmission mode or
b) Build your own acknowledge system in Software and use a counter to distinguish between a "retransmission" packet or a new packet.
Hope this helps someone? ;-)
Greetz and thanks again for the great and well explained tutorial!
I struggled with these problems for a long time, and this video is my day. My research work was stuck at a dead end because of a lack of knowledge about STM and nRF24. Great work!!
At first i want to thank you for this great library you have provided, which actually does my job easily. But initially this library did not work on my STM32F446 and STM32F767 and i ended up learning about the NRF24 (which is good :) ). Last night i was trying to do some project and i needed a function for delay us. I remembered that you library consist of a delay us function and i tried to implement it and Boom!! I found that your delay us function don't work. And i implemented your libraries again with HAL_Delay(1) for everywhere you used delay us function and everything works just as expected. So if anyone is having problem with this library after all the circuitry part is OK then try to change the delay us function.
Regards
Nice spot!
You are right, this part of MicroDelay might fail to work with other boards.
Thank you, I will correct it.
@@mutexembedded2206 you should make a tutorial on microdelay and why it is different for different boards and how things work inside the mcu... It will help many people... Including me.
Regards
Thank you so much for this comment !
I spent few hours checking every function, and everything that was written in every register just to realize everything was correct. I would have never found where the error came from if it wasn't for your comment.
It seems kind of weird that I have this bug since I am using exactly the same board as the Transmitter one (STM32f401RE), but it still did not work because of the Delay.
Thanks again !
Also, thank you Mohammed for your work and all your tutorials (even if on this one it did not work). I am learning a lot from all your videos.
Damn it, I put away my project for 2 months, not knowing this was the problem. Thanks for sharing the info!
Hi, could you please, or somebody else, share code ? I did try to replace every "delay us" function with HAL_Delay(1) , but no luck. I also properly implemented delay_us function, in which i used timer, but i still cant communicate with another board. I have no problem to read registers of NRF24, or write to them, so ISP configuration must be OK. When i use two arduinos (2x mini pro, one as Rx, one as Tx) they works fine. But when i try to replace one arduino with STM32F103, i am not able to receive or send data to arduino.
Thanks for the library. Just read the previous comments and changed the "Micro Second" code and it worked.
For stm32fo use internal timer to generate almost 1us delay. I've used timer3
void NRF24_DelayMicroSeconds(uint32_t uSec)
{
__HAL_TIM_SET_COUNTER(&htim3,0);
__HAL_TIM_ENABLE(&htim3);
while(__HAL_TIM_GET_COUNTER(&htim3)
Peace be upon you brother, hope your company always a success.
Great tutorial!
Only one problem: in function" NRF24_DelayMicroSeconds(uint32_t uSec)" I had to add volatile qualifier for uSecVar, otherwise timing was too short and functions using this timing didn't work. Compiler optimization issue in "while(uSecVar--);" loop. I'm on STM32cubeIDE.
Thanks once again!
Good spot
My code wasn't working because of this... how in the world did you narrow it down to this? I am so confused how you figured this out
Probing CS and CSN lines with oscilloscope. Timing was way to short, after that it was easy find. Did that mistake in my code in the past many times.
Thank you sooooooooooooo much dear MYaqoobEmbedded... its working proper for me on my stm32f103c8 board, there was a problem on receiver but with the help of @Devjeet Mandal comment about delay, i used HAL_Delay(1); at every where instead of uDelay its working well on my board, THANK YOU sooo much dear
MYaqoobEmbedded bro, thanks lot. Thank you @Devjeet Mandal for your kind note, thank you
Yeah, good spot. I should have mentioned about the internal timer I was using, I could have done a better implementation to MicroDelay. Thanks
I am trying the same board ı hope ı can succes
Keep up the good work. Hope your company will succeed!
I appreciate your work Mohammad
As a hobbyist, I started exploring embedded systems on and off. Lately I have been very impressed with ChibiOS
I wonder if you considered it? and if so what you think?
It has a a solid RTOS and HAL layers, and nicely coupled with STM32 boards.
Frankly I feel you need an RTOS layer, else the resources of the MCUs won't be taken advantage of
Thx Again
Salah
absolute great explanation. Everything worked without problems. Can now build a radio link for my project. Thank Mohamed
Great!
Mustafa hangi stmi kullandın?
@@furkanklc5220 ben stm32f103 kullandım bazı hatalar aldım sen yapabildin mi
Amazing, just keep on Making tutorials on STM32. I am always wating for your video.
Gr8 Job 👍.
Thanks :)
Great video, well explained and good examples. Thank You.
Thanks so much for your tutorials! Is this library able to handle multi RX and TX pipes?
Thank you for the great tutorial.
I have a question. Does this library also work for nRF24LE1?
Nice job! I have tried it on a Nucleo-L432KC and it works. Have you any tutorial about how to use the library with interruptions? Thanks
Thank you so much!!! It works :)) Great tutorial:)
I would love to see tutorial on more complicated RF chip - like SPIRIT1 from STM. Great tutorials. You have a gift for teaching
Nice tutorial. I also watched your tutorial on the Virtual Serial Port. Is there a way to use the nrf24_DebugUART_Init(huart2); function but send printRadioSettings(); data to the VSP instead of uart2?
thanks for the tutorial, where does the uart pins connect to ?
Hi, You choose that and tell the library which UART.
hello, i have a question about sending data from multiple devices and receiving in only one (multiple Tx, one Rx). Should i use different channels on every Tx or should i use different pipe addresses? As I understood from datasheet, I can use different pipe addresses for every Tx and all of those addresses should be in Rx device, then just scan through them? Thank you for this very easy to use library.
Works like a charm. Thank you very much!
Thanks for the tutorial! Please tell how you set the colours on your IDE! Thanks!
Sure, Will do very soon.
hi, i downloaded your library for stm32 cube ide. But I want to change the RF_PWR setting. I saw that it is possible to choose between 0 dB and 18 dB. How do I change main.c? Also, which dB setting should I choose for the maximum distance? Can you help me.
Hi! Great video and very useful library. I’m trying to develop a simple TX RX application between two STM32s. I see that the .c library file has a SPI typedef called nrf24_hspi. However CubeMx declares it as hspi1. The code compiles (I haven’t tested functionality) but I don’t see any linkage between hspi1 and nrf24_hspi. How are the two connected?
Hi.. Linked at begin function 11:00
@@mutexembedded2206 Thank you! I am following the video and I've entered the code for no ack transmit. However, it does not seem to be transmitting. Here is the UART data: pastebin.com/xbdXvhaZ. Here is the code so far: pastebin.com/9EWEpQbD. What am I missing?
Hi,
I don't have enough information, like what STM board you're using for instance and more about your hardware set up if any different.
@@mutexembedded2206 Oh sorry! It's a STM32F103C8T6 Bluepill board running at 72MHz. Using SPI1 which is on APB2 which is also running at 72MHz. I set the SPI baud prescaler divider to 64 giving me a data rate of 1.125Mbps. I have changed the define in MY_NRF24.h to stm32f1xxx_hal.h. Using UART1. Using the TrueStudio IDE.
Hi,
I will try the library later today with the Bluepill. Will get back to you later.
I have one more question. I will apply to my system but I wanted to ask you that can I use NRF24 module as transmitter and receiver at the same time by using your codes?
Can we use the following libraries if we are working with stm32f103c8t6?
Thank you for your good work, that was very helpful especially i'm passing from Arduino to STM32 and i found it difficult. I tried to send struct data but the write function doesn't accept it as argument, how can I send more than one data? thank you in advance
Hi,
you can send struct data as long as it does not exceed max bytes of 32 bytes.
If I have:
struct assetTracker_TAG{
uint8_t id;
uint16_t addrs;
uint32_t latitude;
uint32_t longitude;
bool status;
}assetTracker_t;
assetTracker_t myAssetDef;
nrf_write(uint8_t *bytes, uint8_t size);
nrf_write((uint8_t *) &myAssetDef, sizeof(myAssetDef));
@@mutexembedded2206 thank you very much for your help
I tried to use what you said, I guess this don't work assetTracker_t myAssetDef; we shoud declare the variable using assetTracker_TAG myAssetDef.
still I have this error when i use nrf_write((uint8_t *) &myAssetDef,sizeof(myAssetDef)) that says "operand of type 'struct assetTracker_TAG' where arithmetic or pointer type is required" I used nrf_write(&myAssetDef,sizeof(myAssetDef)) which doesn't give error.
In the end, I don't receive the data on the receiver.
sorry to bother you.
@@aitelhajreda7867
Don't forget typedef
typedef struct AssetTracker_TAG
{
...
}AssetTracker_t
AssetTracker_t myAsset;
Hello! I am trying to find a library that works with a simple 433Mhz RF transmitter and this is the closest I can find. Do you think that the write function in this library works with a much simpler 433Mhz transmitter? If not, can you point me to where I can learn more about rf transmitters so I can make my own library? Thank you!
GOD BLESS YOU BROTHER
First, thank you very much for your tutorials. During following your teaching, I can't see the "Hello world!" in serial terminal window.
It seems communication works. Could you check my code (actually yours)?. I am using two Nucleo F446REs.
Hi,
I checked my code, nothing seems to be wrong
It works after changing to SPI2. Thanks
Can I use this code for STM32103CT86 blue pill board ?
welldone ... i hav e a question about this ce and csn pins ,, how i can change these pins and choose different ports for these pins .. i have ce on port B and csn is on port A
Easy, modify library GPIO part
@@bestofbest8213 i think so yes, you just need to overwrtie pin the port of CSE and CE in init() function. Try it, you will get there easy task
@@mutexembedded2206 will you please update your library for different ports and share the link with me.
@@mutexembedded2206 i forgot to mentioned i am using stm32L0 , i did overwrite pins but it didnot work and also i wrote separately void NRF24_begin( function for ce and csn pins but did not help .
tx ds remains zero all the time.
@@mutexembedded2206 NO LUCK . WILL YOU PLEASE UPDATE YOUR LIBARAY ,, IA WAITING for your response....
thank u a lot, muchas gracias bro.
Hello, I have some issues with receiving message. I have a question, if it is possible to implement your library on stm32L053 microcontroler? If so, what would be the main changes for the library?
Thanks :)
I want to try this after I build another F405 board. Can someone give me a link for some NRF24L01 modules that will definitely work with this library please
Hi, congratulations for the video. I followed the transmission and reception procedures without ack. and it did not work. However I noticed that when the settings by the printradiosettings in the transmitter show the address 0x1122334455, but in the receiver when the tx result in the printradiosettings in tx shows 0xe7e7e7e7e7 does not assign the address, but the channel was assigned normally.
If you can help then and for a course completion job.
thank you
Hey,
Send me a link to your entire project. Works fine for me just like I show in the video. I will double check the library again too.
@@mutexembedded2206 www.dropbox.com/sh/sic8mkoeni9uj2a/AAAWhHNiKtpyV5-tPGMo5LE_a?dl=0
I did in the main.h file the possibility to use as transmit and or receiver
stm32f103c8 blue pill
sorry to click the link again for updated project above 20 minutes
Hello, do you have any video interfacing STM32 and the bluetooth module HC-05 /06?
Hi..thank you very much for the video... I tried it with my customised board having part stm32f072rb.... The transmitter works fine...I found transmitted successful msg on terminal... But as per video I didn't get data on receiver side...that is hello world...
I didn't get where is the problem...
Can you help me to get solve the issue
Many pple seem to suffer from this issue.. I will try updating this tutorial sometimr soon to fix all reported issues and make it compatible with all targets
@@mutexembedded2206
Ok sir.
Hello sir,
When can we expect the updated video?
Egerly waiting for the same...
Hello sir,
When can we expect the updated video?
Egerly waiting for the same...
Hey Mohammad, can u please add and extension of the video where a single nrf24 changes btwn transmit and receive mode. I was trying this using ur library. But failed to do so. There are 2 nrf A-Nrf and B-Nrf. First A-Nrf is in transmit mode and B-Nrf is in receive mode. Now A-should tranamit something and change in receive mode... Simultaneously B receives the data and changes in transmit mode. I am doing this by using NRF24_stoplistning() and NRF24_startlistening() to switch btwn transmit and receive mode.. But after few transaction both the devices turns in transmit mode. Can you help pls?
Hi,
I don't use NRF much, made a quick educational library. I would recommend trying to read datasheet and modify to this basic library.
Hello sir, Do you have any video which explains what clock speed to use on different applications like you changes Spi prescalar and leave frq to 84 MhZ How to get that?
Hi, I use CubeMX clock tree most often.
For specific peripheral clock speed, you look into Clock Diagram for your specific MCU to find out which clock it's using. For instance ADC might be using APB1. Thus, you can look APB1 peripheral clock frequency in CubeMX clock tree and accordingly set your ADC prescalar.
No i wanted to learn more about clock settings what clock to set.
Also I want to ask For using ESP8266 With STM 32 F4 do u have any source to refer?
@@zuhaibchoudhary4635 For Clock, it is recommended that you learn STM32 programming without CubeMX first. To get a better insight about what's going on. I am in fact preparing for a getting started series for fundamentals of STM32 programming, that's without CubeMX. That's in fact where most of us who do work with companies start with.
That will be great Sir
Like We want to learn
1 . Without using HAL libraries.
2. how to make our own .c and .h file.
3. Writing from scratch and using our own libraries.
I am using NRF24L01+ module with STM32F446RE Nucleo board. I changed delay us functions to HAL_Delay(1). After that, I am able to transmit in TX mode, but I am not able to receive the data at the receiver side. I am following all steps showed in this video. Can anyone please help me?
thanks a lot that was very helpful
The function NRF24_write, has 2 arguments. The length argument, can be greater than 32 bytes?
I see now. The parameter Length is a byte variable. Only can have 256 values.
Hello ı want to transmit data which taken from ADC. But NRF24_write funcion is not allow int type data. How can ı transmit adc data.
can you please help me about code for Arduino as receiver. I compile your code for transmitting but I want to use an Arduino as receiver and I just configured address and channel parameters but it didn't worked. Do you thing that ı should change library or set else? please help
Hi, not sure how I may help,, If you did exactly same set-up as mine,, should work the same.
@@mutexembedded2206 Thank you for your reply. I configured my stm as same as like you but my receiver nrf24l01 connected to an arduino. Do you think an arduino and a stm board can communicate with this way if we configure both of them correctly?
@@fehimkus5658 Have you solve your problem? I used an arduino for transmit and stm for receiver but it still didn't work.
@@heuehwbebjd2100 unfortunately i couldnt solve the problem, i tried almost every library on internet and configuration but they didnt communicate each other. if you will be successful please inform me too :)
@@fehimkus5658 I have exactly same problem as you two have. I also tried different configurations for STM32 (change rf channel, CRC length, ack enabled/disabled) no luck. I also fixed MicroDelay function with using timer, still no luck :/
thank you so much to start again :)
Hi Emre, hope you're having a good time.
@@mutexembedded2206 As always :) would it possible to make more RTOS videos? and CAN bus would be so cool
Great. Yes definitely there are more RTOS videos to cover, CAN bus is coming on the list, I will try to make it sooner.
Am not getting my receiver to reply to the transmitted message. I literally just copied the same project for transmitter and made sure that am loading the right elf file to the receiver. Still its NRF_available() always returns false. anyone that's experienced the same problem and how did they solve it?
thanks for the info :)
HI MYaqoob,
I am using your library for NRF24L01+, STM32-Tutorials\Tutorial 24 - NRF24L01 Radio Transceiver
I have the following issue, Would you please help me understanding what is wrong.PFA
Previously it was receiving correct strings, but now I am just receiving as "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"
My transmission strings look like this
---------- Configured as Transmitter ------------
Tx Count= 6566, Tx Failed= 0, Rx Count= 0, Rx Failed= 0
'T' is first letter which is transmitted, but it doesn't receives strings after that, I checked with SPI analyser.
image
Sometime it goes to Power down mode abruptly and all value of status/config register becomes zero.
I added NRF24_powerUp(); while changing mode Tx to Rx, but nothing helps.
image
Radio_RF_Control.zip
I will check for any software related issues with the NRF24L01+. I suggest you check for power consumption, perhaps use external power supply for the NRF as STM cannot supply lots of current.
@@mutexembedded2206 Thanks for the response.
I have tested with external power as well as with ext voltage regulator and added a 10 uF capacitor and reduced RF Power but still no improvement, I also raised this issue on your github page.
can I use this library as a receiver end can transmit data to the transmitter side as a receiver
there is a video or library for esp8266 wifi module?.thanks
nope, nrf24l01 is not a esp8266
HI MYaqoob,
I am using your library "NRF24L01+, STM32-Tutorials\Tutorial 24 - NRF24L01 Radio Transceiver"
I created an issue on the git hub page with above title , did you get chance to look at it?
Sure
May I use these codes with STM32F407 or STM32F103?
Yes should work
My STM32F103 is not working with this libary. Can you tell me why ??
Thanks you !
I have a same problem can u help that situation?
same :C
Doesn't show "Transmit Successful" on my STM32F446 Nucleo. After reading the status registers i found it doesn't set the TX_DS Bit. Any Help???
Hi,
I am not entirely sure,, but could be something related to using different boards, think of anything that may have changed, UART peripheral, pins and port and so on.
I will be able to give you a bit more constructive feedback if you can send me a link to your project setup.
Thanks
@@mutexembedded2206 I have changed the UART. I am using USART3. I have also changed the SPI Pins but kept it on same port
SCK - PE12
MISO - PE13
MOSI - PE14
CS - PE15
CE - PE10
IRQ - NC
I have not changed a bit of your library. Here is the link of my main file and SPI initialization.
pastebin.com/CVFTdKca
Hello, I have exactly the same problem. Did you resolve this problem? Maybe someone know what is wrong?
Hello again, I resolved my problem. In my case problem was in NRF24_startWrite(). Before set BIT_PWR_UP and clear BIT_PRIM_RX set CE line as LOW and after set CE in HIGH.
@@MrVentran where exactly in the code? I have the same problem and it's really frustrating.
Thanks.
Thanks very much~!!
can you do tutorials for modbus rs485 rtu and modbus tcp with cubemx and stm32 ?
Thank you soo much
Thanks man!
Thanks man..!!
Hey! Do you have RF audio library? Can you teach that?
thanks so much
I'm using stm32f103c8t6. How can I use the library nrf24c if I don't have st link in the board?
Hi,
Need to generate Hex files from Keil, then flash it to your board using the Hex file.
@@mutexembedded2206 yes I always do that, but the library gets a lot of code where use UART statements, so I have to erase them?
Wow, great video! Can you help me create a network from NRF24?
stm and arduino can not communicate with the data rate synchronize. NRF24_setDataRate(RF24_1MBPS);
Thank you for pointing this out. Finally got my code running.
Hi sir,
I have a problem. Could u help me related source code.
can you help me please i need nrf24l01 library for protues if you have please
Hi ,my Realterm is nothing can you help me?
I can't download the library :((
Hi,
I just checked the link, it works
Bro am face a one error am not get a acknowledgement why?
People reported that few times, I would have to update this library to fix all those issues
@@mutexembedded2206 thanks for your reply ..pls solve this error soon as possible
السلام عليكم اذا يمكنك ان تشرح عن القطعة بالعربي
@ yaqoob Sir
please help me
Hi how can I help
@@mutexembedded2206 Thank you for the reply
I am using two stm32f103c8 for TX and RX but not able to get the data on the receiver side
could you please correct it, I think the minor mistake I am doing over here, Below is the link
drive.google.com/file/d/1sTJKCOvcNkzY1lzRyMtCjxnakKnmdpfN/view?usp=sharing
and please mail me @ iamnotarobot9643@gmail.com
Thank you
@@mutexembedded2206 Sir please reply
@@newtonkhan7883 hi no worries
Can you explain to me briefly what's your setup is like, are you communicating with PC or a UART module? And what sort of tests have you carried out already.
@@mutexembedded2206 Thank you so much for the reply
I am using two stm32f103c8 for transmitter and receiver, I am using terminal software 1.9b.
Thank you