|
【问题】:现在测试是Timer每次通过PPI触发SPI写,SPI写完调用回调函数,回调函数中测试 NRF_SPIM2->TXD.PTR 的每次都是正常递增变化的,但是DAC就是没有实际的输出;
PS:1、要写的源数据测试是正确的;
2、为了不频繁占用CPU资料,用的PPI,用上后 timer+PPI+SPI(DMA) 写DAC 一直没调通,不加PPI的timer+SPI 写DAC 是OK的;
【源码】:
//定义定时器配置结构体,并使用默认配置参数初始化结构体
nrf_drv_timer_config_t timer_cfg =NRF_DRV_TIMER_DEFAULT_CONFIG;
//初始化定时器,初始化时会注册timer_led_event_handler事件回调函数
err_code = nrf_drv_timer_init(&TIMER_DAC, &timer_cfg, timer_DAC_event_handler);
APP_ERROR_CHECK(err_code);
//定时时间(单位us)转换为ticks
time_ticks = nrf_drv_timer_us_to_ticks(&TIMER_DAC, time_us);
printf("time_us= %d,time_ticks= %d \r\n",time_us,time_ticks);
//设置定时器捕获/比较通道及该通道的比较值,使能通道的比较中断
nrf_drv_timer_extended_compare(
&TIMER_DAC, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, false);
/* 初始化SPI2 */
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
spi_config.mosi_pin = DAC_SPI_MOSI;
spi_config.sck_pin = DAC_SPI_SCK;
spi_config.ss_pin = DAC_SPI_SS;
nrf_gpio_cfg_output(DAC_SPI_SS);
spi_config.frequency= NRF_SPI_FREQ_8M;
APP_ERROR_CHECK(nrf_drv_spi_init(&DAC_spi, &spi_config, spi_event_handler));
DAC_SPIDMA_Init();
printf("DAC_SPI_Init OK \r\n");
nrf_delay_ms(500);
//关联SPI DMA缓存
NRF_SPIM2->TXD.MAXCNT = 2;
// NRF_SPIM2->RXD.MAXCNT = 2;
NRF_SPIM2->TXD.LIST=1;
NRF_SPIM2->TXD.PTR=(uint32_t)&SPI2ArrayList; //SPI2ArrayList;
//初始化PPI程序模块
uint32_t err_code = NRF_SUCCESS;
err_code = nrf_drv_ppi_init();
APP_ERROR_CHECK(err_code);
//分配PPI通道,注意PPI通道的分配是由驱动函数完成的,分配的通道号保存到my_ppi_channel
err_code = nrf_drv_ppi_channel_alloc(&timer2DAC_ppi_channel);
APP_ERROR_CHECK(err_code);
//分配PPI通道的EEP和TEP
err_code = nrf_drv_ppi_channel_assign(timer2DAC_ppi_channel,
nrf_drv_timer_compare_event_address_get(&TIMER_DAC,NRF_TIMER_CC_CHANNEL0),
nrf_drv_spi_start_task_get(&DAC_spi));
// nrf_drv_gpiote_out_task_addr_get(LED_2)
APP_ERROR_CHECK(err_code);
//使能PPI通道
err_code = nrf_drv_ppi_channel_enable(timer2DAC_ppi_channel);
APP_ERROR_CHECK(err_code);
printf("PPI enable OK \r\n");
nrf_drv_timer_enable(&TIMER_DAC);
printf("nrf_drv_timer_enable OK \r\n");
void spi_event_handler(nrf_drv_spi_evt_t const * p_event)
{
uint8_t i=0;
DAC_COUNT++;
if(DAC_COUNT==DAC_NUMBER)
{
DAC_COUNT=0;
NRF_SPIM2->TXD.PTR=(uint32_t)&SPI2ArrayList;
}
printf("NRF_SPIM2->TXD.AMCOUNT= %d \r\n",NRF_SPIM2->TXD.AMOUNT);
printf("NRF_SPIM2->TXD.PTR = %x \r\n", NRF_SPIM2->TXD.PTR);
}
|
|