Redbear BLE experiment



Resources


# Link Category Reference Description
1 Mydaq material
2 2 x Redbear Nano material nRF51822_XXAA BLE devices
3 USB2UART dongle material
4 Arduino software programming firmware of Redbear Nano for data penetration
5 NI DAQExpress software virtual oscilloscope for digital signal recording
6 nRF Toolbox application OTA downloader
7 BLE Nano – Redbear Duo間通信でモータ制御 tutorial Redbear Nano Arduino template project
8 RedBearLab BLE Nano の設定方法とOTA tutorial Redbear Nano OTA
9 J-Link programmer download firmware
10 bootloader.hex firmware redbear github webpage function arduino OTA
11 RD-DPS3005 power supply link provide 3.3v power supply (optional)
12 nrfgo software nordic IDE
13 redbear_nano_BLE_serial sketch template codes official released
14 readbear_nano_peripheral sketch template codes
15 readbear_duo_central sketch template codes
16 Mbed OS BLE library library Instructions
mbed x Keil
mbed x STM32
17 AN043 - Small Size 2.4GHz PCB antenna.pdf tutorial a tutorial on PCB antenna
18 NRF SDK download center SDK
19 SDK for redbear NRF51822 SDK nrf51822 latest SDK
19 nrf52832 datasheet datasheet
20 nrf51822 datasheet datasheet
20 Flashing SoftDevice directly from ARM Keil uVision and Makefile tutorial keil flash softdevice
21 S130_SDS_v1.0.pdf usermanual softdevice S130 AIP notes
21 s130_nrf51_1.0.0_softdevice.hex firmware softdevice S130
22 nRF51822 AK II上手指南 manual PCA10001 compatible
23 nRF52832 Product Specification v1.4 datasheet
24 nordic bootload manual nrf5 bootloader explained by nordic
25 Adjustment of RAM and Flash memory tutorial * The default setting in Keil is correct, flashing softdevice first then application, if changing softdevice, using jflash erase full chip and repeating previous steps
26 Running examples that use a SoftDevice tutorial *
27 What is role of bootloader? tutorial
28 nrf.zip template nrf51822 code compilation
29 DeviceDownload.zip template SDK v17 for nrf52832, kickstart project in SDK/examples/ble_peripheral/ble_app_blinky/pca10040/s132/arm5_no_packs using nrf_dual board
30 nrf_clock_lf_cfg_t Struct Reference manual *** softdevice using LSI, ctiv Must be 0 if source is not NRF_CLOCK_LF_SRC_RC. For nRF52, the application must ensure calibration at least once every 8 seconds to ensure +/-500 ppm clock stability. The recommended configuration for NRF_CLOCK_LF_SRC_RC on nRF52 is rc_ctiv=16 and rc_temp_ctiv=2. This will ensure calibration at least once every 8 seconds and for temperature changes of 0.5 degrees Celsius every 4 seconds. See the Product Specification for the nRF52 device being used for more information.


Circuit Diagram


Figure 1 Redbear Nano pin def

Figure 2 BLE delay measurement diagram

Figure 3 Redbear wiring diagram

W: Should beware of polarity direction of breadboard.

Workflow


1. program bootloader.hex

N: connect device by J-link.exe before using nrfgo, otherwise fail connection.
N: erase all, uncheck softdevice protection, program bootloader.hex by bootloader program, because this bootloader provided by redbear includes softdevice bootloader and application.

2. OTA test

test project from Arduino in File->Example->BLE_Examples->BLE_Serial, Arduino setup see redbear github . Then File->save as..., export compiled binary.
N: connect device by J-link.exe before using nrfgo, otherwise fail connection.
N: OTA using program application
M: once connected, DFU OTA disabled.
BLE_serial template binary for OTA

3. codes

N: library used in the Redbear Nano Arduino examples is Mbed OS for BLE
3.1 BLE init

3.2 peripheral codes

3.3 central codes
back to OTA

Code Analysis ( mbed )


  • 1. initialise
    BLE ble;
    
    ...
    ble.init();
    
    Syntax: in BLE.h :
    137   class BLE {
    ...
    288     ble_error_t init(InitializationCompleteCallback_t completion_cb = NULL)
    289     {
    290         FunctionPointerWithContext callback(completion_cb);
    291         return initImplementation(callback);
    292     }
    ...
    1955    };
  • 2. event handler
    ble.onDisconnection(disconnectionCallBack);
    disconnectionCallBack: 断开连接后开始广播,_t即type
    void disconnectionCallBack(const Gap::DisconnectionCallbackParams_t *params) {
        ble.startAdvertising();
    }
    Syntax: in BLE.h
     1577     MBED_DEPRECATED("ble.gap().onDisconnectionComplete(callback)")
     1578     void onDisconnection(Gap::DisconnectionEventCallback_t disconnectionCallback);
    Syntax: in Gap.h
     718     typedef FunctionPointerWithContext<const DisconnectionCallbackParams_t *>
     719         DisconnectionEventCallback_t;
    Syntax: in FunctionPointerWithContext.h
       55 template <typename ContextType>
       56 class FunctionPointerWithContext : public SafeBool<FunctionPointerWithContext<ContextType> > {
       57 public:
       58     typedef FunctionPointerWithContext<ContextType> *pFunctionPointerWithContext_t;
       59     typedef const FunctionPointerWithContext<ContextType> *cpFunctionPointerWithContext_t;
       60     typedef void (*pvoidfcontext_t)(ContextType context);
    Q: what is FunctionPointerWithContext, how to use typedef in C++?


    ble.onDataWritten(gattServerWriteCallBack);
    gattServerWriteCallBack:
    void gattServerWriteCallBack(const GattWriteCallbackParams *Handler) {
    	  uint8_t buf[TXRX_BUF_LEN];
    	  uint16_t bytesRead, index;
    
    	  if (Handler->handle == characteristic1.getValueAttribute().getHandle()) {
    		ble.readCharacteristicValue(characteristic1.getValueAttribute().getHandle(), buf, &bytesRead);
    		for(index=0; index<bytesRead; index++) {
    		  Serial.write(buf[index]);
    		}
    	  }
    	}

Troubleshoot


# Troubles Solutions
1 例程只在连接上J-Link时有效,不接J-Link时蓝牙无法扫到设备 问题错误,引起该现象的本质是swclk和swdio连至jlink而jlink未通电,可能导致芯片进入到编程模式,只需将swclk和swdio悬空即可。
M: mcu works when swclk swdio ground connected to jlink, the disfunction may be caused by target voltage pin driven the jlink and mcu into program mode