NRF51822 BLE4 2.4GHz Bluetooth 4.0 Module Documentation
The NRF51822 BLE4 2.4GHz Bluetooth 4.0 Module is a compact, low-power Bluetooth 4.0 module based on the nRF51822 System-on-Chip (SoC) from Nordic Semiconductor. This module provides a reliable and efficient way to add Bluetooth Low Energy (BLE) capabilities to various devices and applications.
Bluetooth 4.0 compliant
2.4 GHz frequency band
nRF51822 SoC with 256 KB of flash memory and 16 KB of RAM
Supports multiple roles (central, peripheral, broadcaster, observer)
Range: up to 100 meters (line of sight)
Power consumption: 10.5 mA (transmit) and 11.5 mA (receive)
### Example 1: Basic BLE Advertising ( Peripheral Role)
This example demonstrates how to configure the NRF51822 module as a BLE peripheral device and advertise a custom service.
NRF51822 BLE4 2.4GHz Bluetooth 4.0 Module
Microcontroller (e.g., Arduino Uno)
Breadboard and jumper wires
Nordic Semiconductor's nRF5 SDK (Software Development Kit)
Keil Vision IDE (or alternative C compiler)
Code
```c
#include <stdbool.h>
#include <string.h>
#include "nrf_drv_ble.h"
#include "nrf_gpio.h"
#include "app_util.h"
#define ADVERTISEMENT_INTERVAL 100 // 100 ms advertisement interval
#define DEVICE_NAME "MyPeripheral"
int main(void) {
// Initialize the NRF51822 module
nrf_drv_ble_init();
// Configure the device name
ble_gap_conn_params_t conn_params;
conn_params.p_device_name = DEVICE_NAME;
conn_params.device_name_type = BLE_ADVTYP_FLAGS_GENERAL;
// Start advertising
nrf_drv_ble_adv_start(ADVERTISEMENT_INTERVAL, NULL);
while (true) {
// Wait for incoming connections
sd_app_evt_wait();
}
}
```
Description
In this example, we initialize the NRF51822 module and configure the device name using the `ble_gap_conn_params_t` structure. We then start advertising using the `nrf_drv_ble_adv_start()` function, specifying the advertisement interval and a NULL pointer for the advertisement data.
### Example 2: BLE Central Role - Scanning for Devices (Central Role)
This example demonstrates how to configure the NRF51822 module as a BLE central device and scan for available BLE peripherals.
NRF51822 BLE4 2.4GHz Bluetooth 4.0 Module
Microcontroller (e.g., Arduino Uno)
Breadboard and jumper wires
Nordic Semiconductor's nRF5 SDK (Software Development Kit)
Keil Vision IDE (or alternative C compiler)
Code
```c
#include <stdbool.h>
#include <string.h>
#include "nrf_drv_ble.h"
#include "nrf_gpio.h"
#include "app_util.h"
#define SCAN_INTERVAL 100 // 100 ms scan interval
#define SCAN_WINDOW 50 // 50 ms scan window
int main(void) {
// Initialize the NRF51822 module
nrf_drv_ble_init();
// Configure the scanner
ble_gap_scan_params_t scan_params;
scan_params.active = 0; // Passive scanning
scan_params.interval = SCAN_INTERVAL;
scan_params.window = SCAN_WINDOW;
scan_params.timeout = 0; // No timeout
// Start scanning
nrf_drv_ble_scan_start(&scan_params);
while (true) {
// Wait for scan results
sd_app_evt_wait();
}
}
```
Description
In this example, we initialize the NRF51822 module and configure the scanner using the `ble_gap_scan_params_t` structure. We set the scan interval, window, and timeout parameters, and then start scanning using the `nrf_drv_ble_scan_start()` function.
Note: These examples are simplified and intended to demonstrate basic BLE functionality. In a real-world application, you would need to add error handling, implement callback functions for BLE events, and ensure compliance with BLE specifications.
Nordic Semiconductor's nRF5 SDK documentation
BLE specifications (Bluetooth SIG website)
NRF51822 datasheet (Nordic Semiconductor website)
By following these examples and consulting the provided resources, you can develop more complex BLE applications using the NRF51822 BLE4 2.4GHz Bluetooth 4.0 Module.