打算用081的开发板中定时器3的通道1输出一个pwm控制WS2812但是最后发现DMA能进中断,但是数据搬运没有成功,且用官方的DMA_RX例程 也读不到外设寄存器内的值,请大佬们帮忙看看
我的初始化代码 如下
void Hardware_init(void)
{
__disable_irq(); /* 关闭中断 中断总开关 */
SYS_WR_PROTECT = 0x7a83; /* 使能系统寄存器写操作*/
FLASH_CFG |= 0x00080000; /* enable prefetch ,FLASH预取加速使能*/
GPIO_init(); /* GPIO初始化 */
UTimer_init(); /* UTimer初始化 */
SoftDelay(100); /* 等待硬件初始化完毕*/
DMA_init();
SoftDelay(100); /* DMA初始化 */
NVIC_EnableIRQ(DMA_IRQn);
NVIC_SetPriority(DMA_IRQn,0);
SYS_WR_PROTECT = 0x0; /*关闭系统寄存器写操作*/
__enable_irq(); /* 开启中断 */
}
void GPIO_init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_StructInit(&GPIO_InitStruct); //初始化结构体
//配置LED1:P0.6 LED2:P0.7 LED3: P0.3
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; //GPIO输出模式
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_3;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIO0, &GPIO_InitStruct);
/* 配置UTimer3 TIM3_CH0: P2.8 */
GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8;
GPIO_Init(GPIO2, &GPIO_InitStruct);
GPIO_PinAFConfig(GPIO2,GPIO_PinSource_8,AF8_TIMER23); //P0.15复用为timer0的输出模式
/* 配置UTimer3 TIM3_CH0: P2.8 */
GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;
GPIO_Init(GPIO3, &GPIO_InitStruct);
GPIO_PinAFConfig(GPIO3,GPIO_PinSource_9,AF8_TIMER23); //P0.15复用为timer0的输出模式
}
void UTimer_init(void)
{
TIM_TimerInitTypeDef TIM_InitStruct;
TIM_TimerStrutInit(&TIM_InitStruct); // Timer结构体初始化
TIM_InitStruct.EN = ENABLE; // 定时器模块使能
TIM_InitStruct.Timer_ClockDiv = TIM_Clk_Div1; // 设置Timer模块时钟1分频系数
TIM_InitStruct.Timer_CH0_WorkMode = TIMER_OPMode_CMP; // 设置Timer CH0 为比较模式
TIM_InitStruct.Timer_CH0Output = 0; // 计数器回零时,比较模式输出极性控制
TIM_InitStruct.Timer_CH1_WorkMode = TIMER_OPMode_CMP; // 设置Timer CH1 为比较模式
TIM_InitStruct.Timer_CH1Output = 0; // 计数器回零时,比较模式输出极性控制
TIM_InitStruct.Timer_TH = 48000000; // 定时器计数门限初始值500us
TIM_InitStruct.Timer_CMP0 = 24000000; // 设置比较模式的CH0比较初始值25%转空比
TIM_InitStruct.Timer_CMP1 = 0; // 设置比较模式的CH1比较初始值24000//
TIM_InitStruct.Timer_IRQEna = Timer_IRQEna_CH1; // 开启Timer模块比较中断
TIM_TimerInit(TIMER3, &TIM_InitStruct);
UTIMER_RE =BIT11;
TIM_TimerCmd(TIMER3, ENABLE); /* Timer0 模块使能 */
}
u32 buff[4]={0x002dc260,0x002dc280,0x002dc240,0x002dc220};
u32 buff1[4]={0};
void DMA_init(void)
{
DMA_InitTypeDef DMA_InitStruct;
DMA_StructInit(&DMA_InitStruct);
DMA_InitStruct.DMA_IRQ_EN = DMA_TCIE ; // DMA 传输完成中断使能
DMA_InitStruct.DMA_DIR = MEMORY2PERI; // 内存至外设
DMA_InitStruct.DMA_CIRC = DISABLE; // 关闭循环传输模式
DMA_InitStruct.DMA_PINC = DISABLE; // 外设地址每轮内是否递增,高有效
DMA_InitStruct.DMA_MINC = ENABLE; // 内存地址第二轮是否在第一轮地址的基础上递增(轮内地址一定递增),高有效
DMA_InitStruct.DMA_PBTW = DMA_WORD_TRANS; // 外设访问位宽, 0:byte, 1:half-word, 2:word
DMA_InitStruct.DMA_MBTW = DMA_WORD_TRANS; // 内存访问位宽, 0:byte, 1:half-word, 2:word
DMA_InitStruct.DMA_REQ_EN = DMA_CH2_TIMER3_REQ_EN; // CAN DMA请求使能,高有效
DMA_InitStruct.DMA_TIMES = 1; // DMA 通道 x 每轮数据搬运次数 1~511
DMA_InitStruct.DMA_ROUND = 4; // DMA 通道 x 采样轮数 1~255
DMA_InitStruct.DMA_CPAR = (u32) & UTIMER_UNT0_CMP1; // DMA 通道 x 外设地址
DMA_InitStruct.DMA_CMAR = (u32) buff; // DMA 通道 x 内存地址
DMA_Init(DMA_CH2, &DMA_InitStruct);
DMA_CHx_EN(DMA_CH2,ENABLE);
} |