用stm32好多年,现在才知道TX,RX脚可以软件交换,罪过罪过

2019-12-12 18:19发布

最近有个PCB打板回来调程序一直没调通,最后发现 RX,TX 连线反了,正打算割铜皮时,一同事说RX,TX脚可以软件交换,查了资料,改了程序,果真可以,
以后电工再也不用担心 RX,TX接反了,爽!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
99条回答
xmcsl
1楼-- · 2019-12-15 12:29
stm32f030库里面的函数:

/**
  * @brief  Enables or disables the swap Tx/Rx pins.
  * @param  USARTx: where x can be 1 or 2 to select the USART peripheral.
  * @param  NewState: new state of the USARTx TX/RX pins pinout.
  *          This parameter can be:
  *            @arg ENABLE: The TX and RX pins functions are swapped.
  *            @arg DISABLE: TX/RX pins are used as defined in standard pinout
  * @note   This function has to be called before calling USART_Cmd() function.  
  * @retval None
  */
void USART_SWAPPinCmd(USART_TypeDef* USARTx, FunctionalState NewState)
{
  /* Check the parameters */
  assert_param(IS_USART_ALL_PERIPH(USARTx));
  assert_param(IS_FUNCTIONAL_STATE(NewState));

  if (NewState != DISABLE)
  {
    /* Enable the SWAP feature by setting the SWAP bit in the CR2 register */
    USARTx->CR2 |= USART_CR2_SWAP;
  }
  else
  {
    /* Disable the SWAP feature by clearing the SWAP bit in the CR2 register */
    USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_SWAP);
  }
}
EMC菜鸟
2楼-- · 2019-12-15 17:35
 精彩回答 2  元偷偷看……
lcl
3楼-- · 2019-12-15 22:53

我x
才知道
散装805
4楼-- · 2019-12-16 03:24
常用F1系列,可以映射到别的脚,交换就不行了
tangmintm8013TM
5楼-- · 2019-12-16 07:40
好消息,谢谢分享!
KongQuan
6楼-- · 2019-12-16 09:01
只有部分型号有这功能吧。

一周热门 更多>