This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to change from BLE central to peripheral mode by buttons

Hi, I was wondering how to change from central mode of the NRF52 board to peripheral mode and from peripheral mode to central mode by pressing the input buttons on the board. For example, button 1 would enable the central mode which is when the NRF52 board is acting as the client and wants to send data and then button 2 would enable the peripheral mode when the NRF52 board is advertising to be connected to another BLE device, but then disable the central mode which is button 1.

Are there any examples related to this? Any help would be appreciated.

Parents
  • If you are not planning to connect any devices that is running the heart rate service, it would just be waste of space and resources to have code that handles this on the device, but if you are planning to connect such devices in the future, this should be OK. You can call uart_init(), just not if you have NRF_LOG with UART backend enabled. If you disable the logging module (set NRF_LOG_ENABLED 0 in sdk_config.h) and adds #define RETARGET_ENABLED 1 in the same file, you can call uart_init() and use printf() in place of NRF_LOG_INFO() for UART logging.

  • Yes, I tried the instruction that you gave me with the NRF_LOG_ENABLED 0 and the RETARGET_ENABLED 1, but then when I run the code and observe the terminal, there were no words and it is blank meaning that it is not printing correctly. Also, put printf() on the main.c code instead of NRF_LOG_INFO Is there anything else that I need to do? Do you think if I don't use the heart rate service in the future, which example from the ones that you provided in the SDK is suitable? As I said before, I need something that is able to have UART communication as well have a user application that can have both central and peripheral. Thanks.

Reply
  • Yes, I tried the instruction that you gave me with the NRF_LOG_ENABLED 0 and the RETARGET_ENABLED 1, but then when I run the code and observe the terminal, there were no words and it is blank meaning that it is not printing correctly. Also, put printf() on the main.c code instead of NRF_LOG_INFO Is there anything else that I need to do? Do you think if I don't use the heart rate service in the future, which example from the ones that you provided in the SDK is suitable? As I said before, I need something that is able to have UART communication as well have a user application that can have both central and peripheral. Thanks.

Children
No Data
Related