1
\$\begingroup\$

I am trying to configure STM32F4 USART peripheral. I thought that USART Receiver pin(RX) must be programmed as Alternate function to USART works correctly and then the data is present on the I/O pin can moves into the USART Receiver Shift register.

I mean that according to the following pictures taken from the STM32F4 Reference manual, when we do configure a pin as Alternate function it gives a way for the data to moves into the Alternate function input(here it is Receiver shift register) but when that pin is configured as Floating input (second picture) the data on that pin is just sampled into the input data register.

enter image description here

enter image description here

So logically i think that USART can't do it's job correctly when Receiver pin is configured as Floating input. but incredibly it does work in a correct way and i dont know why?!

The same Problem has been discussed here : Why is the USART receiver pin configured as “input floating”?

But i couldn't find my answer there.

Edited:

Ambiguous point is that however in Floating input mode the data will also be sent to the connected Alternate functions But it's important to specify which peripheral this data will be sent to.

When the microcontroller starts up from Reset mode, Reset values of almost all Registers is 0 so for instance pin 7 by default is connected to AF0 which that isn't for USART periph. So if we select Floating input mode for that pin and don't determine which alternate function we want to send the data, then the data might be sent to the wrong peripheral instead of USART receiver shift register.

But incredibly without determining the peripheral which we want to select as our Alternate function, USART does the work correctly. Actually my question is WHY does USART work correctly in this way (without determining The actual Alternate function)?

\$\endgroup\$
1
\$\begingroup\$

Well, I'd say the basic structure picture tells you why this might work:

Basic structure of a five volt tolerant I/O port bit

There is no block which would allow the selection of the digital input only going to the input data register or the alternate function input. So a pin configured as digital input will also send the data to the connected alternate functions.

The only option there is to have the schmitt trigger on or off, but that turns off the whole digital and alternate input then.

I'd still use the alternate function setting, because that is the intended way to use it and as long as no official source tells us otherwise I'd stick to what the manufacturer says (well except it doesn't work and you work out a workaround).

\$\endgroup\$
  • \$\begingroup\$ But one thing will be remain ambiguous. In Floating input mode,Yes data will also be sent to the connected Alternate functions. But it's important to specify which peripheral this data will be sent to. When MCU starts up from Reset mode, Reset values of almost all Registers is 0 then for instance pin 7 by defualt is connected to AF0 which that isn't for USART periph . So if we select Floating input mode for a pin and don't determine which alternate function we want to use, i think also that couldn't works correctly. So please illustrate also this point too. thanks man. \$\endgroup\$ – Amin Nov 9 '18 at 17:20
  • \$\begingroup\$ @Amin I can't find any hint on how that works internally. I guess for a receiver it just gets the data - the peripheral can have more control over a pin. For example if you use a pin as DAC output, the settings of the GPIO registers are mostly ignored, so there are mechanisms at work which are not documented in detail. \$\endgroup\$ – Arsenal Nov 9 '18 at 20:07
  • \$\begingroup\$ So I feel i'm going to be really confused about this subject :(( \$\endgroup\$ – Amin Nov 9 '18 at 20:19
  • \$\begingroup\$ @Amin why? Just use the alternate function as documented and you are good to go. Do not rely on undocumented functionality. \$\endgroup\$ – Arsenal Nov 9 '18 at 20:44
  • \$\begingroup\$ Jeez! But USART works correctly in that unsure way! \$\endgroup\$ – Amin Nov 9 '18 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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