Is it possible to change the protocol on the fly (i.e. based on a flag status or GPIO) from BLE4 to Long range BLE5?
Is it possible to change the protocol on the fly (i.e. based on a flag status or GPIO) from BLE4 to Long range BLE5?
What you're looking for is the sd_ble_gap_phy_update function, it works on a specific link and asks the peer device to change to the requested PHY. Use BLE_GAP_PHY_CODED for long range.
I would like to change the PHY according to a UART command
For example, my 52840 device communicates with another device via BLE4 as a peripheral and once a command via UART arrives, it will change to BLE5 acting as central and connect to another BLE5 device
Can you elaborate how can I use this function?
If I understand you correctly the nRF52840 will be connected to a peripheral over 1/2mbps PHY, and you want it to connect to another device that is advertising using Coded PHY(128kbps) upon reception of a certain UART message.
In order to do that, you need to start a scan in CODED_PHY with a call to sd_ble_gap_scan_start() with a ble_gap_scan_params_t that has the .scan_phys set to BLE_GAP_PHY_CODED, and the .extended set to 1.
If the radio receives an advertisement on CODED_PHY it will send an advertisement report event to the application, where you will have to decide whether to connect to this particular device or not. To connect you call sd_ble_gap_connect with the peer address as provided in the advertising report, along with the scan parameters you used, a set of connection parameters that you would like, and an optional connection configuration.
The UART communication can be achieved through the UARTE driver.
Thank you!