BLE under the microscope (24-52 link)
NORDIC has been producing new crystals of the nRF52 series for several years. However, many still use the older nRF24 family. Today I will show you how to organize two-way communication between them on advertising channels. In addition, using the ability of the nRF52 crystal to measure the RSSI level, we will plot it on a graph.
Connection options
Reading the Nordic forum about the wireless capabilities between the old and new families, I saw that there are two possibilities. This is the ESB (Enhanced Shock Burst) protocol and an add-on over it - the Gazell protocol. This is certainly good, but there are a number of difficulties. On the nRF24 side, this is what the sources are in nRFgo_SDK_2.3.0 only for the nrf24le1 and nrf24lu1 modules (nRF24L01 bundle + microcontroller). However, among radio amateurs, such a module without a controller is more widespread.
Fig.1
From the side of nRF52 not everything is smooth either. In the SDK, ESB and Gazell protocols are given in the form of ready-made, compiled modules, which is not ice. We will link them at the lowest level, working with registers directly. In his third articleI have already described how to make a beacon using nRF51822. It will also be interesting to read this publication .
First, a few words about the system that we will build. We will receive and transmit on advertising channels in BLE packets format. This will allow using a cell phone and the NRF Connect program ( android and iOS) see our packages on the air. This will greatly help us and will allow us to break the original task into stages. We will have a Host with a radio channel on nRF24L01 and a Device on m / c nRF52832. Moreover, since nRF24L01 is just a radio channel, it will need a controller. We will create two projects at once on different m / c from the ST company. Host will broadcast a radio packet several times per second. The Device will receive it, measure the RSSI level and send a response packet back, which will contain its value. After receiving a reply message, Host will output one byte with the RSSI level to the COM port. In order to visually track the change in the reception level, I wrote a small graphical program .
Host Nrf24L01 + Stm8L152
So, let's start with the Host on the Nrf24L01 + Stm8L152 link. For this task, I took the Nrf24L01 module, the photo of which was given above, and STM8L-DISCOVERY, a debug board based on STM8L152C6T6. Below is the pinout of the nRF24L01 module.
Fig. 2
Pinout from STM8L-DISCOVERY
#define LED_PORT GPIOC
#define LED_PIN GPIO_Pin_7
#define IRQ_PORT GPIOE
#define IRQ_PIN GPIO_Pin_0
#define CE_PORT GPIOD
#define CE_PIN GPIO_Pin_1
#define SPI_CLK_PORT GPIOE
#define SPI_CLK_PIN GPIO_Pin_4
#define SPI_MISO_PORT GPIOE
#define SPI_MISO_PIN GPIO_Pin_2
#define SPI_MOSI_PORT GPIOE
#define SPI_MOSI_PIN GPIO_Pin_5
#define SPI_CSN_PORT GPIOD
#define SPI_CSN_PIN GPIO_Pin_0
#define LED_PIN GPIO_Pin_7
#define IRQ_PORT GPIOE
#define IRQ_PIN GPIO_Pin_0
#define CE_PORT GPIOD
#define CE_PIN GPIO_Pin_1
#define SPI_CLK_PORT GPIOE
#define SPI_CLK_PIN GPIO_Pin_4
#define SPI_MISO_PORT GPIOE
#define SPI_MISO_PIN GPIO_Pin_2
#define SPI_MOSI_PORT GPIOE
#define SPI_MOSI_PIN GPIO_Pin_5
#define SPI_CSN_PORT GPIOD
#define SPI_CSN_PIN GPIO_Pin_0
Fig. 3
To output data to the COM port, a USB adapter to m / s cp2102 was used connected to the PC2 and PC3 legs. You can get its driver here. In the end, this is what happened.
Fig.4
On the nRF24L01 module you can see a soldered electrolytic capacitor between the power pins. It is recommended to set it for stable operation of the module. The complete project and firmware can be found here and here... You can open it using the IAR for Stm8 development environment. We flash the m / c and launch it. The blue LED on the STM8L-DISCOVERY board will blink 2 times per second, indicating the sending of packages. Now is the time to start the NRF Connect program and see something like the picture shown in Fig.5a. If you succeed, congratulations, the first half of the tasks is completed.
Fig.5a ________________________________ Fig.5b _______________________________ Fig.5c ______________________________
Host Nrf24L01 + stm32F103
In order not to go far from the Host's work, we will repeat the same for the stm32F103 m / c. To do this, I took a "blue pill" with a USB connector installed on it. This made it possible not to use an adapter, but to output data directly to the USB port using these drivers . I put together a project for stm32F103 in STM32CubeMx.
Pinout from the blue pill side
#define SPI_CE_PORT GPIOB
#define SPI_CE_PIN GPIO_PIN_4
#define SPI_IRQ_PORT GPIOB
#define SPI_IRQ_PIN GPIO_PIN_5
#define SPI_MISO_PORT GPIOB
#define SPI_MISO_PIN GPIO_PIN_6
#define SPI_CLK_PORT GPIOB
#define SPI_CLK_PIN GPIO_PIN_7
#define SPI_MOSI_PORT GPIOB
#define SPI_MOSI_PIN GPIO_PIN_8
#define SPI_CSN_PORT GPIOB
#define SPI_CSN_PIN GPIO_PIN_9
#define SPI_CE_PIN GPIO_PIN_4
#define SPI_IRQ_PORT GPIOB
#define SPI_IRQ_PIN GPIO_PIN_5
#define SPI_MISO_PORT GPIOB
#define SPI_MISO_PIN GPIO_PIN_6
#define SPI_CLK_PORT GPIOB
#define SPI_CLK_PIN GPIO_PIN_7
#define SPI_MOSI_PORT GPIOB
#define SPI_MOSI_PIN GPIO_PIN_8
#define SPI_CSN_PORT GPIOB
#define SPI_CSN_PIN GPIO_PIN_9
Fig.6
The project itself and the firmware can be taken here and here . You can open it using the IAR for Stm32 development environment. Any programmer can be used to program the STM32F103. I used this one.
Fig. 7 We
connect the power supply and try to see the packages on advertising channels. The picture will be the same as in Fig5a. Nothing blinks on this board, both LEDs are on continuously. I was unable to revive the green LED on the PC13 leg. The sending frequency is higher than on the board with stm8L152 and is 10 Hz. All these parameters can be easily changed within projects.
Device Nrf52832
So, we will assume that the first part of the system with the Host is working for us. Now we will launch Device. This can be done on a suitable KIT from NORDIC PCA10040
Fig.8
You can also use any board with m / k nRF52832. I will use a board from an old design. But on the PCA10040 kit, I checked, it also starts. The project and firmware are here and here . It is built in Keil uVision4 environment using the old SDK12.3.0, which can be taken here... In order for the project to build without problems, its folder must be placed in the nrf52832_workspace_SDK12 \ examples \ peripheral \ directory. The fact is that any project from NORDIC contains a huge number of related links, so it will not be collected in an arbitrary place. To flash nRF52832, you can use the nRFgoStudio or nRF Connect for Desktop program .
When launching a Device project, I would recommend doing this first. Because Device works in the broadcast listening mode, it does not send radio packets on the air. This will happen only as a response, after receiving a packet from the Host. Therefore, you must first check that the device is alive. To do this, you need to comment out the BleListen () function in the project and, on the contrary, uncomment the BleRadioTransaction (). As shown below.
In this case, Device itself will start broadcasting radio packets. They can be seen on the phone. An example picture is shown in Fig.5b. If everything is fine, we turn everything back and turn on both the Host and Device devices. On the phone, we should see both of them, as in Figure 5c. This means that the Device saw the Host's message and sent its own in response. If the Host, in turn, has received a response message with the RSSI level, then it sets this value to the COM port. Now if we run the LevelRssi program on Windows and select the correct port, we will see how the RSSI level changes with a different relative position of devices.
Conclusion
I had almost finished preparing the article when I got another thought. I decided to use a more common device as a Device, namely the pca10059 dongle , based on the nRF52840 m / c. Here is his photo.
Fig. 9
Fortunately, I had two such boards. Having rebuilt the project, I ran into the problem of uploading the firmware into it. I knew I needed to do this using nRF Connect for Desktop, but did not immediately figure out how to enter the dongle into DFU (firmware update) mode. Here's how to do it. We get into DFU mode immediately after reset. You must first plug the dongle into the USB connector, and then press the reset button (farthest from the processor), with a horizontal pusher. The red LED on the dongle starts blinking. Open the nRF Connect program and press the "Install" button in the Programmer section. When the required software is downloaded, click the "Open" button.
Fig. 10 The
programmer window will open in front of you.
Fig. 11
At the top left, select the desired COM port. You will see something like the following picture.
Fig. 12
On the left side we will see what is in the controller's memory. By clicking on the "Add HEX file" button, you can add a file for filling to the right side. There were also some problems here. The "Erase all" and "Erase & write" buttons are not available to us. The fact is that the dongle does not have a programmer, so the program is loaded using the bootloader. And we get into it through the MBR section. If we erase these sections, then the firmware via DFU mode will be impossible. In theory, you just need to add firmware to the right half of the screen and press the "Write" button. Everything seems to be correct, but will not work. Our program starts at address zero in FLASH memory, and this address is already occupied by the MBR partition. How to deal with this can be read in this tutorial.... If you read for a long time or not, I will explain in pictures using Keil's example. Here is a picture of a project with microcontroller memory allocation for non-stack projects.
Fig. 13
It is necessary to move the FLASH-a pointer to 0x1000, and RAM to 0x20000008 and recompile the project.
Fig.14
After that, you can already use the nRF Connect for Desktop program. That's probably all. You can see what I did in the video below.
yadi.sk/i/BGQQnga1HeN50A
yadi.sk/i/d8A9pU82kBcTMw
yadi.sk/i/XGac8xwpksVX7g
Employee of Caesar Satellite Group of Companies
Vladimir Pecherskikh