How to use a same uart for two devices
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-18 4:46 AM
Hello every one , i'm using a STM32L100RX, i am using PC11 and PC10 ports as USART3, so far everything it's okay, but i need to use the same usart (USART3) on the PB11 and PB10 pins...i need configure these pins in runtime because i have another device on it! something like multiplexor, so what i do?¿
this is my code:
GPIO_InitTypeDef def,def2;
HAL_GPIO_DeInit(GPIOB,GPIO_PIN_11); //Deinit port 11 and 10 of B PORT
HAL_GPIO_DeInit(GPIOB,GPIO_PIN_10);
def.Alternate = GPIO_AF7_USART3;
def.Pull = GPIO_NOPULL;
def.Mode = GPIO_MODE_AF_PP;
def.Pin = GPIO_PIN_11;
def.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOC,&def);
def2.Alternate = GPIO_AF7_USART3;
def2.Pull = GPIO_NOPULL;
def2.Mode = GPIO_MODE_AF_PP;
def2.Pin = GPIO_PIN_10;
def2.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOC,&def2); //Set now the usart 3 to the desired PORT
but it doesn't work...any idea?¿
Regards!
Solved! Go to Solution.
- Labels:
-
STM32L1 Series
-
UART-USART
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-18 5:15 AM
You must have only one set of pins wired to the uart. Dynamically deselect as input with pull up the unused ones first. Would be clean to reset usart when switching the pins in case transmission on going. This is a dynamic hw reconfiguration which is fine. CubeMX mostly covers the static ones and require coder override...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-18 5:15 AM
You must have only one set of pins wired to the uart. Dynamically deselect as input with pull up the unused ones first. Would be clean to reset usart when switching the pins in case transmission on going. This is a dynamic hw reconfiguration which is fine. CubeMX mostly covers the static ones and require coder override...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-18 6:06 AM
> but it doesn't work
Why do you think so? Have you looked at the signal on the lines?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-18 6:14 AM
Shure, i have no see any signal in the osciloscope...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-18 6:15 AM
Dynamically deselect as input with pull up the unused ones first.
how i do that?¿ i thought HAL_GPIO_Init does...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-18 6:45 AM
What you're doing should work. Verify the pins are actually connected by initializing as GPIO output and toggling them and monitoring on a scope.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-18 7:02 AM
With STLink in debug mode, put a breakpoint and even manually inpect and play with uart and gpio registers until you are satisfied. You can make a transmission loop, break, change gpios until things start to work...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-18 7:57 AM
HI guys, it seems work finally, however i just found out another issue...,when i use the portc with the usart to measure my sensor, measures affected by the other sensor on the other port (port b)...maybe it's because of @S.Ma​ said a about to set pull up on that port...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-18 8:37 AM
@RComa.1​ - "HI guys, it seems work finally"
So how about posting the working code for the benefit of others who might come along looking for answers to the same question?
And mark the solution:
A complex system designed from scratch never works and cannot be patched up to make it work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-10-18 8:38 AM
@RComa.1​ - " i just found out another issue...,when i use the portc with the usart to measure my sensor, measures affected by the other sensor on the other port (port b)..."
That sounds like a separate question - so start a separate thread.
You can always give a link back to here for reference. And a link from here to the new thread.
You will need to give more details, though - there's not enough to go on as it stands.
A complex system designed from scratch never works and cannot be patched up to make it work.
