#include"stdio.h"
#include"gd32f30x.h"
#include"keydiver.h"
unsigned char data0[10]={1,2,3,4,5,6,7,8,9,0};
unsigned char data1[10]={0};
dma_parameter_struct dmacfg;
unsigned char* pdata=0;
unsigned char data2[10]={0};
void DMA0_Channel0_IRQHandler()
{
if(dma_interrupt_flag_get(DMA0,DMA_CH0,DMA_INT_FLAG_FTF)){
dma_interrupt_flag_clear(DMA0,DMA_CH0,DMA_INT_FLAG_FTF);}
//dmacfg.number++ //cannot corect devise
// dma_channel_disable(DMA0,DMA_CH0);
// dmacfg.memory_addr=(uint32_t)pdata;
// dmacfg.memory_width = DMA_MEMORY_WIDTH_8BIT;
//dma_init(DMA0,DMA_CH0,&dmacfg);
// dma_channel_enable(DMA0,DMA_CH0);
data0[0]++;
}
int main()
{
pdata=data2;
rcu_periph_clock_enable(RCU_DMA0);
dma_deinit(DMA0,DMA_CH0);
dma_memory_to_memory_enable(DMA0,DMA_CH0);
dma_struct_para_init(&dmacfg);
dmacfg.periph_addr =(uint32_t) data0;//shift addrss (uint32_t)
dmacfg.periph_width = DMA_PERIPHERAL_WIDTH_8BIT;
dmacfg.periph_inc = DMA_PERIPH_INCREASE_ENABLE;
dmacfg.memory_addr = (uint32_t)data1;
dmacfg.memory_width = DMA_MEMORY_WIDTH_8BIT;
dmacfg.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dmacfg.number = 10U;
dmacfg.direction = DMA_PERIPHERAL_TO_MEMORY;
dmacfg.priority = DMA_PRIORITY_LOW;
dma_init(DMA0,DMA_CH0,&dmacfg);
dma_interrupt_enable(DMA0,DMA_CH0,DMA_INT_FLAG_FTF);
nvic_irq_enable(DMA0_Channel0_IRQn,2,2);
dma_circulation_enable(DMA0,DMA_CH0);
dma_channel_enable(DMA0,DMA_CH0);
while(!dma_flag_get(DMA0,DMA_CH0,DMA_FLAG_FTF));
while(1){}
}
首先配置DMA,将data0作为外设地址,外设和内存都设置8个字长,外设地址自增,内存地址自增,传输10次,方向是外设到内存,配置循环模式,传输优先级为低,打开dma的中断,先等待dma发送完成,此时data1已经被赋值,然后进入中断,先失能dma通道,不然直接修改不起作用,然后可以将内存地址改为pdata,这样就向pdata赋值,然后初始化,使能通道就可以成功的向pdata赋值啦