[SOLVED] Change the uart pins and afterwards, i get wrong value...why?
Hi folk, how's tricks?
i need some help from you happens following:
I have a UART3, but this UART work's on PORTB and PORTC pins, so i need to use this uart some times on PORTC and other times on PORTC, so i reconfigure the ports in runtime to get this, however i get a wrong value form PORTC when i try to change the UART port from B PORT to C PORT..., in the C PORT i have a sensor thant send a specific value, but it's wrong when i reconfigure the ports...i don't know why...this is my code:
GPIO_InitTypeDef def,def2,def3,def4;
HAL_GPIO_DeInit(GPIOB,GPIO_PIN_11);
HAL_GPIO_DeInit(GPIOB,GPIO_PIN_10);
/*RECONFIGURE THIS PORTB (uart) TO TURN IT INTO AN OUTPUT PORT
def3.Pull = GPIO_PULLDOWN;
def3.Mode = GPIO_MODE_OUTPUT_PP;
def3.Pin = GPIO_PIN_11;
def3.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOB,&def3);
def4.Pull = GPIO_PULLDOWN;
def4.Mode = GPIO_MODE_OUTPUT_PP;
def4.Pin = GPIO_PIN_10;
def4.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOB,&def4);
/*RECONFIGURE THIS PORTC (reset state) TO TURN IT INTO A UART3 PORT FROM NOW ON...
RCC->APB2ENR |= (1<<4); //Enable PORTC's clock
def.Alternate = GPIO_AF7_USART3;
def.Pull = GPIO_NOPULL;
def.Mode = GPIO_MODE_AF_OD;
def.Pin = GPIO_PIN_11;
def.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOC,&def);
HAL_Delay(100);
def2.Alternate = GPIO_AF7_USART3;
def2.Pull = GPIO_NOPULL;
def2.Mode = GPIO_MODE_AF_OD;
def2.Pin = GPIO_PIN_10;
def2.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOC,&def2);
HAL_UART_Receive_IT(&huart3, inputBufferUARTPM, 10); //Get the first traceApparently it'work...becaus ei get data from the C port, but it's wrong data...
Thanks in advance
Regards.
SOLUTION:
Just put __HAL_UART_DISABLE(&huart); before reconfigure ports and afterwards, just put __HAL_UART_ENABLE(&huart3);
Thanks!
Regards.
