2020-04-27 06:09 AM
I am using STM32CubeIDE to configure an stm32f107vc on a custom board. I selected half duplex on uart1, with a pin remap, and received the following setup code:
/**USART1 GPIO Configuration
PB6 ------> USART1_TX
*/
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
__HAL_AFIO_REMAP_USART1_ENABLE();
Measuring with a scope on the output pin shows it is always 0V even during transmit. I have found that it start seeing data if I change OD to PP, like this:
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
Is this an issue with the code generator, or is there something I don't understand here about how UARTs and the setup of them here works?
2020-04-27 06:28 AM
Hi,
when configuring USART as half-duplex, the driven pin must be OD (open drain). Because You are connecting two pins and both of them can be input as well as output. In case these devices will start to transmit at the same time with OD it is OK, but if one of these pins will be defined as PP (push pull) then there is relatively high risk of shorting VCC to GND, which will result in damage on pin or microcontroller itself.
When I look in the code You posted, the only problem I see is that there is no pull-up defined. Try to enable pull-up on that pin and it should work.
I hope this will help. Have a nice day.
2020-04-27 07:03 AM
Thank you for the answer. Do you mean that I should set a pullup like this?
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
When I configure it like that and test with a scope I see no signal. Is there another way to setup a pullup in this case?
(When configured as in my original post I see a signal. The only lines changed are the above. I am assumin that transmitting and testion with a scope on the pin is an ok to test that this works. I can also mention that the project is completely clean out of the device configruation tool, just add Tx, and as configured I see no signal.)
2020-04-27 10:51 AM
Hi,
I am sorry for previous post, I did not noticed, that it is F1 family device. It has different GPIO design and pull resistors cannot be activated with AF mode there. You will need to add external pull-up (value from 1k to 10k, depends on load capacitance).
Have a nice day.
2020-04-27 12:28 PM
@Tomas SIRUCEK, open drain is not the only option in half-duplex mode, and not even the best one. One can put a series 1k resistor at MCU pin for safety and still use push-pull mode. That way transmission line will be more robust and faster. If external pull-up resistor is required, one can still use that also, but must choose reasonable resistor ratio.
2020-04-27 06:25 PM
Thank you for your answers!
I have 200 ohms in series now. I will bump that to 1k and hope that the push pull is fine with it :)
2020-04-28 01:37 AM
Don't forget that you still need some significantly higher (few tens of kOhm) resistance pull-up for reception!