欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: stm32f103vet6單片機將PD5,PD6配置為USART2 [打印本頁]

作者: 834597084    時間: 2020-3-21 20:20
標題: stm32f103vet6單片機將PD5,PD6配置為USART2
本帖最后由 834597084 于 2020-3-21 20:21 編輯

之前我們做的一個程序是使用PA2和PA3接口作為usart2來通信,現在接到的板子用的是PD5,PD6,想問問各位大佬這兩種方式有什么區別嗎?應該如何改動代碼呢?
原代碼:
void Usart2_Init(void)//連接端口
{
  GPIO_InitTypeDef GPIO_InitStructure;
  USART_InitTypeDef USART_InitStructure;  

  /* 配置 USART2 Tx (PA.02) 為復用推挽輸出 */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* 配置 USART2 Rx (PA.03) 為上拉輸入。否則不接串口程序允許到串口就司機 */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  USART_InitStructure.USART_BaudRate = 115200;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

   /* 按結構體配置某個串口 */
  USART_Init(USART2, &USART_InitStructure);

   /*允許接收中斷 */
  USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
  USART_ITConfig(USART2, USART_IT_TXE, DISABLE);

   /*串口1使能*/
  USART_Cmd(USART2, ENABLE);
}


作者: csmyldl    時間: 2020-3-21 20:57
改以下三個地方(實際4個地方)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_Init(GPIOD, &GPIO_InitStructure);   //這一句有2個地方
作者: 834597084    時間: 2020-3-21 22:31
好像需要remap...
作者: 834597084    時間: 2020-3-21 23:04
csmyldl 發表于 2020-3-21 20:57
改以下三個地方(實際4個地方)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Pi ...

請問還需要運用remap函數對USART2進行重新映射嗎?之前沒改過的話,USART2默認映射的端口是PA2和PA3嗎?之前學校實驗用的板子都是用的默認端口,現在給我了一個跟默認的引出腳不同的板子。。。
作者: 834597084    時間: 2020-3-21 23:06
csmyldl 發表于 2020-3-21 20:57
改以下三個地方(實際4個地方)
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Pi ...

但也沒在庫里找到remap這個函數。。。




歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1