2021-10-19 03:42 AM
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 trace
Apparently 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.
2021-10-19 04:21 AM
@RComa.1 - "in the C PORT i have a sensor thant send a specific value,"
You need to give more details on that - what kind of sensor? what is it sending? what kind of interface?
A schematic (aka "circuit diagram") would help.
" but it's wrong"
In what way(s), exactly, is it "wrong"? How are you observing this? What investigation/testing/debugging have you done to find what's going on?
Do you have an oscilloscope or logic analyser to see what's happening on the wires?
"when i reconfigure the ports"
So look at what happens when you change the ports - is the configuration for the sensor maintained correctly?
EDIT
Previous thread:
https://community.st.com/s/question/0D53W000019CsapSAC/how-to-use-a-same-uart-for-two-devices