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

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > STM32學(xué)習(xí)筆記之串口重映射

          STM32學(xué)習(xí)筆記之串口重映射

          作者: 時(shí)間:2016-11-24 來(lái)源:網(wǎng)絡(luò) 收藏

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

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

          第一次這么干感覺(jué)心里沒(méi)底,所以針對(duì)USART1在STM32F103RBT6的板子上實(shí)現(xiàn)了一把,以下是相關(guān)的測(cè)試代碼:

          void Uart1_Init(void)

          {

          RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE);//開(kāi)啟端口B和復(fù)用功能時(shí)鐘

          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,無(wú)奇偶校驗(yàn),無(wú)硬流量控制 ,使能發(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);

          }

          簡(jiǎn)要分析重映射步驟為:

          1.打開(kāi)重映射時(shí)鐘和USART重映射后的I/O口引腳時(shí)鐘,

          RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB |RC C_APB2Periph_AFIO,ENABLE);

          2.I/O口重映射開(kāi)啟.

          GPIO_PinRemapConfig(GPIO_Remap_USART1,ENABLE);

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

          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);

          只需要簡(jiǎn)單的以上三步就能輕松搞定,完整的例程見(jiàn)附件內(nèi)容。

          例程中實(shí)現(xiàn)了重映射之后的串口收發(fā)功能。



          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁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); })();