初级会员
- 积分
- 56
- 金钱
- 56
- 注册时间
- 2016-3-1
- 在线时间
- 11 小时
|
2金钱
求教大家,我用TIM4 定时器通过DMA来修改GPIOE的值,却修改不了;调试中发现DMA也启动了,因通过寄存器发现为修改TIM4 CCR1的值是能修改了,
但GPIOE->ODR或GPIOE->BSRR却没有变化,请问是什么原因?用的STM32F407,下面是我的代码:
#define TIM4_CCR1_ADDRESS ((uint32)0x40000834) /* TIM4 CCR1 address */
#define GPIOE_ODR_ADDRESS ((uint32)0x40021014) /* address */
uint16 a_SRC_Buffer[4] = {0x0023, 0x0045, 0x00d3, 0x004a};
/*
**********************************************************************************************
函 数 名: TIM_GPIO_Init TIM4
功 能:定时器输出通道GPIO初始化
参 数: 无
返 回: 无
**********************************************************************************************
*/
void TIM_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
/* TIM4 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_TIM4, ENABLE);
/* GPIOA clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1PERIPH_GPIOD | RCC_AHB1PERIPH_GPIOE, ENABLE);
/* DMA1 clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1PERIPH_DMA1, ENABLE);
/* GPIOA Configuration: PD12(TIM4 CH1) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_12;
GPIO_InitStructure.e_GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.e_GPIO_Speed = GPIO_SPEED_100MHZ;
GPIO_InitStructure.e_GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.e_GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* Connect TIM pins to AF1 */
GPIO_PinAFConfig(GPIOD, GPIO_PIN_SOURCE12, GPIO_AF_TIM4);
/* DeInitialize the DMA1 Stream6 */
DMA_DeInit(DMA1_Stream6);
DMA_InitStructure.DMA_Channel = DMA_Channel_2;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32)(&(GPIOE->ODR)); //&(GPIOE->BSRRL) 值没有变化
//DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32)(TIM4_CCR1_ADDRESS); /* 可以正常修改它的值 */
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32)a_SRC_Buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
DMA_InitStructure.DMA_BufferSize = 4;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA1_Stream6, &DMA_InitStructure);
}
/*
**********************************************************************************************
函 数 名: TIM_DMA_Output_Init
功 能:定时器DMA方式输出通道初始化
参 数: 无
返 回: 无
**********************************************************************************************
*/
void TIM_DMA_Output_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_TimeBaseStructure.TIM_Period = 1000;
TIM_TimeBaseStructure.TIM_Prescaler = 42 - 1;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_COUNTERMODE_UP;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
/* TIM Configuration in PWM Mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = a_SRC_Buffer[0];//0xFFF;
TIM_OC1Init(TIM4, &TIM_OCInitStructure);
/* TIM4 DMA Update enable */
TIM_DMACmd(TIM4, TIM_DMA_Update, ENABLE);
TIM_SelectOutputTrigger(TIM4, TIM_TRGOSource_Update);
/* TIM4 enable */
TIM_Cmd(TIM4, ENABLE);
/* TIM4 PWM Outputs Enable */
// TIM_CtrlPWMOutputs(TIM4, ENABLE);
/* Enable DMA2 Stream5 */
DMA_Cmd(DMA1_Stream6, ENABLE);
// /* Wait until DMA1 Stream6 end of Transfer */
// while (!DMA_GetFlagStatus(DMA1_Stream6, DMA_FLAG_TCIF6))
// {
// }
}
void TLC7524_GPIO_Init(void)
{
GPIO_InitTypeDef s_GPIO_InitStructure;
/* Enable GPIOs clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1PERIPH_GPIOD | RCC_AHB1PERIPH_GPIOE, ENABLE);
/* GPIOI configuration */
s_GPIO_InitStructure.GPIO_Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7;
s_GPIO_InitStructure.e_GPIO_Mode = GPIO_Mode_OUT;
s_GPIO_InitStructure.e_GPIO_OType = GPIO_OType_PP;
s_GPIO_InitStructure.e_GPIO_Speed = GPIO_SPEED_100MHZ;
s_GPIO_InitStructure.e_GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOE, &s_GPIO_InitStructure);
}
|
|