Location>code7788 >text

nRF24L01 chip driver record

Popularity:603 ℃/2024-09-19 11:30:03

nRF24L01 chip driver record

After studying the usb, understand the function of some of the components as well as the use of the intention of the Dragon Boat Festival holiday with a day to complete a small goal, but in fact it took a day and a half to successfully achieve, now will drive the whole process of the nRF24L01 chip recorded.

small target

Driving nRF24L01 chips to realize communication between nRF24L01 chips

Ask customer service at taobao to find the driver code

This process is difficult to describe, at first because of the cheap, I bought the chip store is not an official store, belongs to the private store, sells a variety of things. Although a few dollars cheaper, but the information will be relatively incomplete, and older (are 10 years 11 years of code), in the description of the business inside, the information inside the OP, I turned the whole zip file over and over again, I looked for half a day can not be found, and then go to ask customer service, customer service said a moment of technology is not available, after half an hour and then asked, customer service said the technology has been off work, let me ask again tomorrow! I'll ask again tomorrow. At that time, I almost quarreled with the customer service.

I went to another taobao store later on my own and dabbled with the download link for the OP so that I could use my computer for one end of the nRF24L01 and make sure there were no errors. I just need to implement the nRF24L01 on the mcu for receive or transmit, and the other end on the OP for transmit and receive to communicate.

After sorting out the customer service driver code, none of which I can directly use, and the driver code of the chip are 10 years 11 years old chip, I personally feel that in order to learn a driver to learn an outdated chip in the cost of time and benefits are very unsatisfactory, so I did not go to look at the source code, but just roughly look at it.

Find the driver code on github

Finally I was on github to find me this chip driver code, but also a long time ago, but the code is also written better, although it is also more than a decade ago, but and Taobao customer service to give the information is not a grade, this code is like before the technical director gave me the driver library of ST7789, direct include in, configure some of their own GPIO can be used directly, and communication between the mcu and nRF24L01 completely do not need me to worry about and understand, until now the goal is completed, the source code inside the I just looked at 70%.

Configure GPIO, initial failure

Once the GPIOs were configured, I just powered it up and ran it, and not surprisingly, it failed the first time (and I didn't think it would work at the time).

Configure address, second failure

Then I started to look at the main function, from initialization to configuration to communication, I looked at all of them and then I found that the address code needs to be configured, so I started to configure the RX_address and TX_address, and after I configured the address of the upper computer, I configured the address inside the project. After configuring the addresses I started the second power up test, but it still failed.

Configuration parameters, third failure

That's when I realized how much of the Chinese manual was incomplete (just the26 pp.), and started opening up the English manuals (there are78 pp.I've read the English manual.) After reading the English manual, I realized that there are a lot of configurations that require one-to-one correspondence between the transmitter and the receiver, and it is not possible to use one nRF24L01 device to send out a signal that can be directly read by another nRF24L01 device.

Although they are all based on the 2.4Ghz band, there are a lot of sub-bands within the 2.4Ghz band and there are communication rates and stuff. So I was excited to finish the configuration, thinking that this time, finally can succeed it. But reality still gave me a blow, or communication failure. By this time the first day was drawing to a close, but I felt that I was getting closer to the truth.

Grabbing data from the host computer, failed for the fourth time

At this time I thought to use the logic analyzer to capture the initialization data of the moment the nRF24L01 is plugged into the computer, to see how he is configured, and then use the same configuration in my project. When I grabbed the data, I found that there are some parameters of the configuration, actually in the host computer has been written to death (such as RX payload host computer written to death is 32 bytes), while my project is 2 bytes. After the modification, I powered up and ran the program, and it still failed.

Grabbing mcu data, finally worked!

Later I grabbed the mcu data again and realized that my RX address and TX address seemed to be set the other way around, so I made the change and it finally worked.

lit. summarize the pitfalls (idiom); fig. to summarize what is wrong and what is not right

Here are some summaries of the two days of stepping in the pits:

  • It is best to choose the chip's official store, so that after-sales service and sample code can be guaranteed!
  • github / CSDN above also has good sample code, sometimes you can spend a little time to find it, if you find it will achieve twice the result with half the effort. If I write my own SPI driver nRF24L01, I need to configure the SPI, and I do not know what the specific process of their communication, so I may need to spend a lot of time to read the entire 78-page English manual to find the answer, and until the process of communication, the implementation of the communication process is not necessarily correct. And the time overhead would be huge.
  • The Chinese manual may be the easiest to understand, but most likely it is not the most accurate and detailed. If you have a Chinese manual, you can read the Chinese manual first, and after reading it, you can spend 2 minutes to go through the English manual, to know what is in the English manual that the Chinese manual doesn't have, and then when you need to use it, you can target to read the English manual, and in the case of having read the Chinese manual, it will be easier to read the part of the English manual that you've read (for those who don't have a good command of English, such as me).
  • When the self-perception is that the configuration is ready, use a logic analyzer to grab the configuration on the sender and receiver side and check that it is as expected