<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > STM32 UART 重映射

          STM32 UART 重映射

          作者: 時間:2016-11-10 來源:網(wǎng)絡 收藏
          在進行原理圖設計的時候發(fā)現(xiàn)管腳的分配之間有沖突,需要對管腳進行重映射,在手冊中了解到STM32 上有很多I/O口,也有很多的內(nèi)置外設像:I2C,ADC,ISP,USART等 ,為了節(jié)省引出管腳,這些內(nèi)置外設基本上是與I/O口共用管腳的,也就是I/O管腳的復用功能。但是STM32還有一特別之處就是:很多復用內(nèi)置的外設的 I/O引腳可以通過重映射功能,從不同的I/O管腳引出,即復用功能的引腳是可通過程序改變的。

          第一次這么干感覺心里沒底,所以針對USART1在STM32F103RBT6的板子上實現(xiàn)了一把,以下是相關的測試代碼:

          本文引用地址:http://www.ex-cimer.com/article/201611/317500.htm

          /*****************************************************************************

          //函數(shù)名:void Uart1_Init(void)

          //功能:串口(USART1)重映射初始化配置函數(shù),由TX PA9~PB6 RX PA10~~PB7

          *****************************************************************************/

          void Uart1_Init(void)

          {

          RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE);//開啟端口B和復用功能時鐘

          GPIO_PinRemapConfig(GPIO_Remap_USART1,ENABLE);//使能端口重映射

          GPIO_InitTypeDef GPIO_InitStructure;

          //uart 的GPIO重映射管腳初始化 PB6 usart1_TX PB7 USART_RX

          GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6;

          GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;//推挽輸出

          GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;

          GPIO_Init(GPIOB,&GPIO_InitStructure);

          GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7;

          GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;//懸空輸入

          GPIO_Init(GPIOB,&GPIO_InitStructure);

          RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);

          USART_InitTypeDef USART_InitStructure;

          //串口參數(shù)配置:9600,8,1,無奇偶校驗,無硬流量控制 ,使能發(fā)送和接收

          USART_InitStructure.USART_BaudRate = 9600;

          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(USART1, &USART_InitStructure);

          USART_ITConfig(USART1, USART_IT_RXNE,ENABLE);//串口接收中斷

          USART_Cmd(USART1, ENABLE);

          }

          簡要分析重映射步驟為:

          1.打開重映射時鐘和USART重映射后的I/O口引腳時鐘,

          RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB |RC C_APB2Periph_AFIO,ENABLE);

          2.I/O口重映射開啟.

          GPIO_PinRemapConfig(GPIO_Remap_USART1,ENABLE);

          3.配制重映射引腳, 這里只需配置重映射后的I/O,原來的不需要去配置.

          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

          GPIO_Init(GPIOB, &GPIO_InitStructure);

          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;

          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

          GPIO_Init(GPIOB, &GPIO_InitStructure);

          只需要簡單的以上三步就能輕松搞定。



          關鍵詞: STM32UART重映

          評論


          技術專區(qū)

          關閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();