由于项目中需要实现多个无线设备部署在集装箱内部采集温湿度、光强度、角度等信息,并将采集的数据通过BLE发送到集装箱外部的接收设备中,但是由于集装箱是一个几乎密闭(箱门由胶条密闭)的金属箱子,实际测试发现很难去搜索到箱子内部的Ble设备信号,因而采用加PA的方式。
调试是在15.0SDK的ble_app_blinky_pca10040_s132基础上修改的,PA的启用的代码部分比较简单,网上都可以搜索到,但是由于我的nRF52832- YJ-17029没有接外部晶振,所以还需要修改RTC的时钟源,下图是模块的原理图:

代码分成两步:1、启用PA 2、修改协议栈时钟源
static void pa_assist(uint32_t gpio_pa_pin,uint32_t gpio_lna_pin)
{
ret_code_t err_code;
static const uint32_t gpio_toggle_ch = 0;
static const uint32_t ppi_set_ch = 0;
static const uint32_t ppi_clr_ch = 1;
// Configure SoftDevice PA assist
ble_opt_t opt;
memset(&opt, 0, sizeof(ble_opt_t));
// Common PA config
opt.common_opt.pa_lna.gpiote_ch_id = gpio_toggle_ch; // GPIOTE channel
opt.common_opt.pa_lna.ppi_ch_id_clr = ppi_set_ch; // PPI channel for pin clearing
opt.common_opt.pa_lna.ppi_ch_id_set = ppi_clr_ch; // PPI channel for pin setting
// PA config
opt.common_opt.pa_lna.pa_cfg.active_high = 1; // Set the pin to be active high
opt.common_opt.pa_lna.pa_cfg.enable = 1; // Enable toggling
opt.common_opt.pa_lna.pa_cfg.gpio_pin = gpio_pa_pin; // The GPIO pin to toggle
opt.common_opt.pa_lna.lna_cfg.active_high = 1;
opt.common_opt.pa_lna.lna_cfg.enable = 1;
opt.common_opt.pa_lna.lna_cfg.gpio_pin = gpio_lna_pin;
err_code = sd_ble_opt_set(BLE_COMMON_OPT_PA_LNA, &opt);
APP_ERROR_CHECK(err_code);
}
1)、gpio_pa_pin:PA(TX)的控制IO
2)、gpio_lna_pin:LNA(RX)的控制IO
从上面的原理图可以知道,PA(24),LNA(20)
nRF52832有三中时钟源:
// <0=> NRF_CLOCK_LF_SRC_RC :内部RC时钟
// <1=> NRF_CLOCK_LF_SRC_XTAL :外部晶振时钟
// <2=> NRF_CLOCK_LF_SRC_SYNTH :从高速合成的低速时钟

1)、打开sdk_config

修改协议栈时钟配置为:
#ifndef NRF_SDH_CLOCK_LF_SRC
*#define NRF_SDH_CLOCK_LF_SRC 0*
#endif
// NRF_SDH_CLOCK_LF_RC_CTIV - SoftDevice calibration timer interval.
#ifndef NRF_SDH_CLOCK_LF_RC_CTIV
*#define NRF_SDH_CLOCK_LF_RC_CTIV 16*
#endif
// NRF_SDH_CLOCK_LF_RC_TEMP_CTIV - SoftDevice calibration timer interval under constant temperature.
// How often (in number of calibration intervals) the RC oscillator shall be calibrated
// if the temperature has not changed.
#ifndef NRF_SDH_CLOCK_LF_RC_TEMP_CTIV
*#define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV 2*
#endif
启用PA和未启用PA信号强度对比如下图:


由上面2张图我们可以发现信号从-65db变成了-20db,nRF52832+PA实验调试成功。