NRF528xx 芯片外设常用函数与事件速查(二)-----PPI /WDT/NVMC/

一、PPI 可编程外设互联(Programmable Peripheral Interconnect)
原理:简单来讲,不同外设模块的事件和任务的发生,都会由相关的事件寄存器和任务寄存器触发。而PPI的作用就是
将事件和任务的寄存器地址分别放入PPI通道的两端,事件产生时不用经过CPU直接触发对应任务

  1. ret_code_t nrf_drv_ppi_init(void)
    作用:初始化PPI模块
    示例:nrf_drv_ppi_init();

  2. nrfx_err_t nrfx_ppi_channel_alloc(nrf_ppi_channel_t * p_channel)
    作用:申请PPI通道,可用20个通道(0-19)
    示例:nrf_ppi_channel_t ppi_channel1;
    --------nrfx_ppi_channel_alloc(&ppi_channel1);

  3. nrfx_err_t nrfx_ppi_channel_assign(nrf_ppi_channel_t -----channel,
    ------------------------------------------uint32_t --------------eep,
    ------------------------------------------uint32_t --------------tep)
    作用:绑定PPI通道的事件端地址和任务端地址
    示例:nrfx_ppi_channel_assign(ppi_channel1,
    --------------------------------nrfx_gpiote_in_event_addr_get(NRF_GPIO_PIN_MAP(0,13)),
    --------------------------------nrfx_gpiote_out_task_addr_get(NRF_GPIO_PIN_MAP(0,3)));

  4. nrfx_err_t nrfx_ppi_channel_fork_assign(nrf_ppi_channel_t channel, uint32_t fork_tep)
    作用:绑定PPI通道的次级任务端地址
    示例:nrfx_ppi_channel_assign(ppi_channel1,nrfx_gpiote_out_task_addr_get(NRF_GPIO_PIN_MAP(0,3)));

  5. nrfx_err_t nrfx_ppi_group_alloc(nrf_ppi_channel_group_t * p_group)
    作用:申请分配PPI组别,共6个组别
    示例:nrf_ppi_channel_group_t ppi_group;
    ---------nrfx_ppi_group_alloc(&ppi_group);

  6. nrfx_err_t nrfx_ppi_channel_include_in_group(nrf_ppi_channel_t channel,
    -----------------------------------------------------nrf_ppi_channel_group_t group)
    作用:添加PPI通道到PPI组别
    示例:nrfx_ppi_channel_include_in_group(ppi_channel1,ppi_group);

  7. nrfx_err_t nrfx_ppi_channel_remove_from_group(nrf_ppi_channel_t channel,
    -----------------------------------------------------nrf_ppi_channel_group_t group)
    作用:删除PPI通道从PPI组别
    示例:nrfx_ppi_channel_remove_from_group(ppi_channel1,ppi_group);

  8. nrfx_err_t nrfx_ppi_group_enable(nrf_ppi_channel_group_t group)
    作用:使能PPI组
    示例:nrfx_ppi_group_enable(ppi_group);

  9. nrfx_err_t nrfx_ppi_group_disable(nrf_ppi_channel_group_t group)
    作用:禁止PPI组
    示例:nrfx_ppi_group_disable(ppi_group);

二、WDT看门狗

  1. ret_code_t nrfx_wdt_init(nrfx_wdt_config_t const * p_config,
    ----------------------------------nrfx_wdt_event_handler_t wdt_event_handler)
    作用:初始化WDT
    示例://使用外部晶振,配置32.768KHz低频时钟,如果不配置,WDT会强制使用内部低频RC时钟
    ---------err_code = nrf_drv_clock_init();
    ---------APP_ERROR_CHECK(err_code);
    ---------nrf_drv_clock_lfclk_request(NULL);
    ---------//定义WDT结构体并配置
    ---------nrfx_wdt_config_t config = NRFX_WDT_DEAFULT_CONFIG;
    ---------//初始化WDT
    ---------nrfx_wdt_init(&config, wdt_event_handler);
    ---------void wdt_event_handler(void){...}
    ---------//宏配置NRFX_WDT_DEAFULT_CONFIG

  2. nrfx_err_t nrfx_wdt_channel_alloc(nrfx_wdt_channel_id * p_channel_id)
    作用:申请喂狗通道
    示例:nrfx_wdt_channel_id wdt_channel_id;
    ----------nrfx_wdt_channel_alloc(&wdt_channel_id);

  3. void nrfx_wdt_enable(void)
    作用:使能喂狗
    示例:nrfx_wdt_enable();

  4. void nrfx_wdt_channel_feed(nrfx_wdt_channel_id channel_id)
    作用:喂狗
    示例:nrfx_wdt_channel_feed(wdt_channel_id);

三、片内flash--NVMC
Flash一共256个页面,每个页面4k byte,一共1MB大小
Flash 地址范围是:0x0000 0000~0x0010 0000,共 1M 字节

  1. void nrf_nvmc_page_erase(uint32_t address)
    作用:填入第N页的起始地址,擦除整页数据
    示例:擦除第127页(第127页的起始地址是:127 * 4 * 1024 = 0x0007F000)
    -------nrf_nvmc_page_erase(0x0007F000);

  2. void wait_for_flash_ready(void)
    作用:等待flash就绪

  3. void nrf_nvmc_write_bytes(uint32_t address, const uint8_t * src, uint32_t num_bytes)
    作用:向flash指定地址写入一串数据
    示例:uint8_t data[5] = {...};
    nrf_nvmc_write_bytes(0x0007F000,data,5);

posted @ 2025-05-09 16:32  感兴趣就学  阅读(97)  评论(0)    收藏  举报