stm32飞07 的usart3 和usart1,2怎么不一样

2019-03-23 18:49发布

usart1,2都试过了没问题,但是试了usart3 怎么都不行,我先把usart1的程序贴出来,哪位大侠能帮忙贴下usart3的么,想对比学习下,谢谢。
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */ void Rcc_Configuration(void)
{
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE);
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
} void UsartGPIO_Configuration(void)
{
 GPIO_InitTypeDef GPIO_InitStructure;
 
 GPIO_PinRemapConfig(GPIO_Remap_USART1, ENABLE);
 
 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);
} void usart_Configuration(void)
{
 USART_InitTypeDef USART_InitStructure;  Rcc_Configuration();
 
 UsartGPIO_Configuration();  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(USART1, &USART_InitStructure);
 USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
 USART_Cmd(USART1, ENABLE);
} void UsartGPIO_CTRT_Configuration(void)
{
   GPIO_InitTypeDef GPIO_InitStruct;  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
 GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
 GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_Init(GPIOB, &GPIO_InitStruct);  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12;
 GPIO_Init(GPIOA, &GPIO_InitStruct);  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
 GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;
 GPIO_Init(GPIOB, &GPIO_InitStruct);
 
 GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11;
 GPIO_Init(GPIOA, &GPIO_InitStruct);
}
void USART_CTRT_Configuartion(void)
{
 USART_InitTypeDef USART_InitStruct;  Rcc_Configuration();  USART_InitStruct.USART_BaudRate = 115200;
 USART_InitStruct.USART_StopBits = USART_StopBits_1;
 USART_InitStruct.USART_WordLength = USART_WordLength_8b;
 USART_InitStruct.USART_Parity = USART_Parity_No;
 USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_RTS_CTS;
 USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
 
 USART_Init(USART1, &USART_InitStruct);  USART_Cmd(USART1, ENABLE);  UsartGPIO_CTRT_Configuration();
} //不使用半主机模式
#if 1 //如果没有这段,则需要在target选项中选择使用USE microLIB
#pragma import(__use_no_semihosting)
struct __FILE 

 int handle; 
}; 
FILE __stdout;  _sys_exit(int x) 

 x = x; 
}
#endif PUTCHAR_PROTOTYPE
{
 /* Place your implementation of fputc here */
 /* e.g. write a character to the USART */
 USART_SendData(USART1,(u8)ch);  /* Loop until the end of transmission */
 while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);  return ch;
}
#include <stm32f10x.h>
#include "usart.h"
//#define CTRT
uint8_t TxBuffer[] = " USART Hyperterminal Hardware Flow Control Example: USART -
Hyperterminal communication using hardware flow control "; #ifndef CTRT
//配置矢量中断,矢量的意思就是有顺序,有先后的意思。
void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure; //定义数据结构体
 
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0000);//将中断矢量放到Flash的0地址   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//设置优先级配置的模式,详情请阅读原材料中的文章   //使能串口中断,并设置优先级
  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 
  NVIC_Init(&NVIC_InitStructure); //将结构体丢到配置函数,即写入到对应寄存器中
}
#endif int main(void)
{
 u32 i=0xffffff;
 SystemInit(); #ifdef CTRT    /*使用CTS RTS硬件流模式*/
 USART_CTRT_Configuartion();
 while(NbrOfDataToTransfer--)
   {
      USART_SendData(USART1, TxBuffer[TxCounter++]);
      while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);         
   }
 
   /*Receive a string (Max RxBufferSize bytes) from the Hyperterminal ended by ' ' (Enter key) */
   while(1)
   {  
      if(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) != RESET)
      {
         USART_SendData(USART1,USART_ReceiveData(USART1));
      }  
   }
#else  /*普通串口模式*/
 usart_Configuration(); 
 NVIC_Configuration();
   while(1)
 {
  printf("Waveshare 上海_2! ");
  while(--i);
  i=0xffffff;
 }
#endif
}   上面的程序是usart1的,没问题,如果要改usart2的话 只需将usart1改成usart2,并且将时钟改成apb1和复用的gpio端口改下就也可以了,但是我在调试usart3的时候按照同样的方法修改却不行,是不是复用端口不对啊,还发现个问题 GPIO_PinRemapConfig(GPIO_Remap_USART1, ENABLE);GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);这样改都没问题,但偏偏在改成GPIO_PinRemapConfig(GPIO_Remap_USART3, ENABLE)就编译不过,请大侠指教,初学者研究了好久还是不行,呵呵 见笑

[ 本帖最后由 chairmanisme 于 2012-6-30 17:46 编辑 ] 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。