2、DMA.c文件(涉及DMA结构初始化)RGB_Buff内存存储的缓存要发给PWM改变占空比的
#include "dma.h"
#define RGB_Size 25
//1码:0x06 0码:0x02
const uint16_t RGB_G_Buff[RGB_Size] = { 0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
0x00 };
const uint16_t RGB_R_Buff[RGB_Size] = { 0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
0x00 };
const uint16_t RGB_B_Buff[RGB_Size] = { 0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
0x00 };
const uint16_t RGB_0_Buff[RGB_Size] = { 0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
0x00 };
void Dma_Init(void)
{
DMA_InitTypeDef DMA_InitStruct;
TIM_DMA_APBxCLK(TIM_DMA_CLK ,ENABLE);
DMA_InitStruct.DMA_PeripheralBaseAddr = (uint32_t)&TIM2->CCR4;
DMA_InitStruct.DMA_MemoryBaseAddr = (uint32_t)RGB_B_Buff;
DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralDST;//从存储器读
DMA_InitStruct.DMA_BufferSize = RGB_Size;
DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;
DMA_InitStruct.DMA_Priority = DMA_Priority_High;
DMA_InitStruct.DMA_M2M = DMA_M2M_Disable;
DMA_Init(MTM_DMA_Channe, &DMA_InitStruct);
DMA_Cmd(MTM_DMA_Channe, ENABLE);
//DMA_ClearFlag(MTM_DMA_TCx);
} |