2
\$\begingroup\$

My MCU is STM32L432KC, it has two serial ports 1 and 2. But I’m wondering if I can use the same serial port1 only to communicate with two modules (not on the same Tx & Rx pins but 4 different pins ?

Is there anyway I can in the software communicate with one module then disable the communication and communicate with the other?

I tried connecting both but one of them never works unless I remove the Serial definition of the other.

I attached a pic of my MCU with pins functions described enter image description here

\$\endgroup\$
1
  • 1
    \$\begingroup\$ they are switchable, so you need to turn one set of ports off to enable the other. the details are probably in the datasheet for that microcontroller somewhere. \$\endgroup\$ Mar 11, 2019 at 8:08

1 Answer 1

4
\$\begingroup\$

Yes you can.

Detail for GPIO alternate functions are in https://www.st.com/resource/en/datasheet/stm32l432kc.pdf, chapter: Pinouts and pin description (page 55-56). All you have to do is change alternate function of gpio pins after initialization if serial port have same configuration. If configuration isnt same for both modules you also have to change it before you want to communicate to other module. You can find how to change alternate function of GPIO here: https://www.st.com/resource/en/reference_manual/dm00151940.pdf, chapter: General-purpose I/Os (page 271).

Depending on used IDE it might be easier to De-init and Re-init used serial peripheral instead of changing registers yourself (initialization routines will change exactly same registers).

\$\endgroup\$
4
  • \$\begingroup\$ Thanks for answering. I wanted to suggest that you provide the names of chapters or sections in the manuals rather than page numbers because the manufacturer often revises the manual and the page numbers can change significantly. Even better would have been if you included more details about the relevant registers and their settings. On the other hand, it looks like the OP is using some simplified IDE so they probably don't want to manipulate registers directly. \$\endgroup\$ Mar 11, 2019 at 10:53
  • \$\begingroup\$ @Rokta thank you so much that solved it so simply and perfectly! \$\endgroup\$
    – sadhna
    Mar 11, 2019 at 12:30
  • \$\begingroup\$ @sadhna, which part was more usefull, to change AF registers or to reinitilize peripheral?, ps dont forget to mark solution. \$\endgroup\$
    – Rokta
    Mar 11, 2019 at 13:31
  • \$\begingroup\$ Re-initialize peripheral. What I did was define the both UARTs before main method then using the first UART device in the code then changing its definition to a DigitalIn and communicating with the second UART device with no problems like before. \$\endgroup\$
    – sadhna
    Mar 18, 2019 at 6:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.