Analysis of PPI developed by nRF52832

1. Principle of PPI

1. Concept
PPI is the abbreviation of Programmable Peripheral Interconnect.
2. It
provides a hardware channel to "connect" events and tasks of different peripherals together. When an event occurs, the hardware automatically triggers the event "connection" "Task
3. Advantages " The
design of the PPI mechanism allows the task to be "connected" to be triggered automatically by the hardware, eliminating the need for the CPU to participate in the steps. This aspect reduces the load on the CPU, and on the other hand guarantees the real-time nature of generating events to executing tasks.

4. Implementation principle
1) nRF52832 has 32 channels (numbered 0 ~ 31), among which, 12 channels (channels 20 ~ 31) have been pre-programmed, and the remaining 20 channels (channels 0 ~ 19) are user programmable ; and
2) each channel consists of three endpoints PPI registers, an EEP (event End-Point: event endpoints) and two TEP (task End-Point: endpoint task, the task of the secondary endpoint) register;
3) task Endpoints and secondary task endpoints are triggered at the same time;
4) When using PPI to connect peripheral events and peripheral tasks, write the address of the peripheral event register to the EEP of the PPI channel, and write the address of the peripheral task register to TEP of the PPI channel, and finally enable the PPI channel to realize the connection between events and tasks;

5. The
PPI group nRF52832 shares 6 PPI groups CHG [0] ~ CHG [5]. The PPI channel can be added to the PPI group for centralized management to enable or disable the PPI channel at the same time.
Note: When a PPI channel belongs to two PPI groups at the same time, if one PPI group is enabled and the other PPI group is disabled, the enable function takes priority.

Two, PPI register

PPI only has task register and general register, it has no event register, so PPI cannot generate events
1. Task register
1) CHG [n] .EN (n = 0 ~ 5): enable PPI channel group n
2) CHG [n] .DIS (n = 0 ~ 5): Disable PPI channel group n

2. General register
1) CHEN: enable / disable PPI channel
2) CHENSET: enable PPI channel
3) CHENCLR: disable PPI channel
4) CH [n] .EEP (n = 0 ~ 19): PPI channel n event endpoint
5) CH [n] .TEP (n = 0 ~ 19): PPI channel n task endpoint
6) CHG [n] (n = 0 ~ 5): PPI channel group n
7) FORK [n] .TEP (n = 0 ~ 31): PPI channel n secondary task endpoint

Three, programming analysis

SDK version: nRF5_SDK_15.2.0_9412b96

1. Basic programming steps
1) Initialize the PPI module
2) Apply to the driver for the PPI channel
3) Configure the channel's EEP and TEP
4) Enable the PPI channel

2. Related library functions
1) ret_code_t nrf_drv_ppi_init (void);
Function: PPI Initialization Module
2) nrfx_err_t nrfx_ppi_channel_alloc (nrf_ppi_channel_t * p_channel
); Function: PPI application channel
3) nrfx_err_t nrfx_ppi_channel_assign (nrf_ppi_channel_t channel,
uint32_t eep, uint32_t tep); function : of EEP channel configuration and of TEP
. 4) nrfx_err_t nrfx_ppi_channel_fork_assign (nrf_ppi_channel_t channel, uint32_t fork_tep);
function: configuration channel sub tasks endpoint
5) nrfx_err_t nrfx_ppi_group_alloc (nrf_ppi_channel_group_t * p_group
); function: application PPI channel group
6) __ STATIC_INLINE nrfx_err_t nrfx_ppi_channel_include_in_group (nrf_ppi_channel_t channel, nrf_ppi_channel_group_t group)
function: add the specified channel to the PPI channel group
7) __STATIC_INLINE nrfx_err_t nrfx_ppi_channel_remove_from_group (nrf_ppi_channel_t channel
, nrf_ppi_channel_group_t group) Function: Removes the specified channel from the channel group PPI
8) nrfx_err_t nrfx_ppi_channel_enable (nrf_ppi_channel_t channel)
; Function: Enable PPI passage
9) nrfx_err_t nrfx_ppi_channel_disable (nrf_ppi_channel_t channel)
; Function: Disable PPI Channel
10) nrfx_err_t nrfx_ppi_group_enable (nrf_ppi_channel_group_t group);
function: enable PPI channel group
11) nrfx_err_t nrfx_ppi_group_disable (nrf_ppi_channel_group_t group);
function: disable PPI channel group

3. Code example

#include "boards.h"
#include "nrf_drv_gpiote.h"
#include "nrf_drv_ppi.h"

void gpiote_init(void)
{
	ret_code_t err_code;
	//初始化GPIOTE模块
	err_code = nrf_drv_gpiote_init();
	APP_ERROR_CHECK(err_code);
	//定义GPIOTE输出初始化结构体并赋值
	nrf_drv_gpiote_out_config_t out_config = NRFX_GPIOTE_CONFIG_OUT_TASK_TOGGLE(true);
	//初始化GPIOTE输出引脚
	err_code = nrfx_gpiote_out_init(LED_1,&out_config);
	APP_ERROR_CHECK(err_code);
	//使能任务模式
	nrf_drv_gpiote_out_task_enable(LED_1);
	//定义GPIOTE输入初始化结构体并赋值,配置下降沿产生事件
	nrf_drv_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
	in_config.pull = NRF_GPIO_PIN_PULLUP;
	//配置引脚为GPIOTE输入
	err_code = nrfx_gpiote_in_init(BUTTON_1,&in_config,NULL);
	APP_ERROR_CHECK(err_code);
	//使能事件模式
	nrf_drv_gpiote_in_event_enable(BUTTON_1,true);
}

//定义PPI通道
nrf_ppi_channel_t my_ppi_channel;
void ppi_config(void)
{
	ret_code_t err_code = NRF_SUCCESS;
	//初始化PPI模块
	err_code = nrf_drv_ppi_init();
	APP_ERROR_CHECK(err_code);
	//申请PPI通道
	err_code = nrfx_ppi_channel_alloc(&my_ppi_channel);
	APP_ERROR_CHECK(err_code);
	//设置PPI通道EEP和TEP端点地址	
	err_code = nrfx_ppi_channel_assign(my_ppi_channel,nrfx_gpiote_in_event_addr_get(BUTTON_1),nrfx_gpiote_out_task_addr_get(LED_1));
	APP_ERROR_CHECK(err_code);
	//使能PPI通道
	err_code = nrfx_ppi_channel_enable(my_ppi_channel);
	APP_ERROR_CHECK(err_code);
}

int main(void)
{
	gpiote_init();
	ppi_config();
	return 0;
}

 

Published 81 original articles · 21 praises · 30,000+ views

Guess you like

Origin blog.csdn.net/qq_33575901/article/details/90043139
PPI