Hola, escribí el controlador para el motor paso a paso. Estoy usando la transferencia DMA. Sin USART Config, mi código funciona, y puedo transferir períodos. Cuando inicio la configuración de usart, el motor no acelera (valor constante). ¿Puedes decirme qué puedo devolver? Pego mi código.
void USART2_Init(void) {
USART_InitTypeDef usart;
GPIO_InitTypeDef gpio;
NVIC_InitTypeDef nvic;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
gpio.GPIO_Pin = GPIO_Pin_2;
gpio.GPIO_Speed = GPIO_Speed_50MHz;
gpio.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &gpio);
gpio.GPIO_Pin = GPIO_Pin_3;
gpio.GPIO_Speed = GPIO_Speed_50MHz;
gpio.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &gpio);
nvic.NVIC_IRQChannel = USART2_IRQn;
nvic.NVIC_IRQChannelPreemptionPriority = 0;
nvic.NVIC_IRQChannelSubPriority = 0;
nvic.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvic);
usart.USART_BaudRate = 9600;
usart.USART_WordLength = USART_WordLength_8b;
usart.USART_StopBits = USART_StopBits_1;
usart.USART_Parity = USART_Parity_No;
usart.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
usart.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(USART2, &usart);
USART_Cmd(USART2, ENABLE);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
}
void TIM_Config(void) {
TIM_TimeBaseInitTypeDef TIMInit;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
TIMInit.TIM_Prescaler = 64000 - 1;
TIMInit.TIM_ClockDivision = TIM_CKD_DIV1;
TIMInit.TIM_CounterMode = TIM_CounterMode_Up;
TIMInit.TIM_RepetitionCounter = 0;
TIM_DMAConfig(TIM1, TIM_DMABase_ARR, TIM_DMABurstLength_3Transfers);
TIM_TimeBaseInit(TIM1, &TIMInit);
}
void PWM_Config(void) {
TIM_OCInitTypeDef PWMInit;
PWMInit.TIM_OCMode = TIM_OCMode_PWM1;
PWMInit.TIM_OutputState = TIM_OutputState_Enable;
PWMInit.TIM_Pulse = 30;
TIM_OC1Init(TIM1, &PWMInit);
TIM_DMACmd(TIM1, TIM_DMA_Update, ENABLE);
TIM_Cmd(TIM1, ENABLE);
TIM_CtrlPWMOutputs(TIM1, ENABLE);
}
void DMA_Config() {
DMA_InitTypeDef DMAInit;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
DMA_DeInit(DMA1_Channel5);
DMAInit.DMA_PeripheralBaseAddr = (u32)&TIM1 ->DMAR;
DMAInit.DMA_MemoryBaseAddr = (u32) bufor1;
DMAInit.DMA_DIR = DMA_DIR_PeripheralDST;
DMAInit.DMA_BufferSize = DMA_BUFF;
DMAInit.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMAInit.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMAInit.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMAInit.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMAInit.DMA_Mode = DMA_Mode_Circular;
DMAInit.DMA_Priority = DMA_Priority_High;
DMAInit.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel5, &DMAInit);
DMA_Cmd(DMA1_Channel5, ENABLE);
}
int main(void) { // wiTHOUT THIS DECLARATION STEPPER MOTOR WORKS
USART2_Init(); // WITH THIS DECLARATION MOTOR WITH THE SAME SPEED
GPIO_Config();
TIM_Config();
DMA_Config();
PWM_Config();
// DMA BUFFER WITH PERIODS IN X FUNCTION
bufor1[currentStep * 3] = round(period);
bufor1[currentStep * 3 + 1] = 0;
bufor1[currentStep * 3 + 2] = round(period / 2);
while (1) {
}
}