STM32F103ZE 串口4问题

2019-07-20 21:03发布

我的串口4 搞了半天还是一点输出都没有 。

初始化代码:

void UART4_Configuration(u32 m)
{
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef  USART_ClockInitStructure;

RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE );

USART_ClockInitStructure.USART_Clock = USART_Clock_Disable; // ?±????????????
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low; // ?±????????
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge; // ?±????????±???????????????
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable; // ×??ó???????????±??????????SCLK????
USART_ClockInit(UART4, &USART_ClockInitStructure); // ?±?????????????è??  
USART_InitStructure.USART_BaudRate = m;  // ?¨????????115200
USART_InitStructure.USART_WordLength = USART_WordLength_8b;  // 8??????
USART_InitStructure.USART_StopBits = USART_StopBits_1;  // ?????á??????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(UART4, &USART_InitStructure);    
USART_ClearFlag(UART4, USART_IT_RXNE); //???????????????????????ó?????ú?ú????
USART_ITConfig(UART4,USART_IT_RXNE, ENABLE); //????UART4??????
USART_Cmd(UART4, ENABLE); //UART4×??????????? 
}


端口初始化 :

/*UART4?®???????¨??*/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //TX
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //×???????????50MHz?????è??
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;// GPIO_Mode_AF_PP
  GPIO_Init(GPIOC, &GPIO_InitStructure);//????A????
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; //RX
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //×???????????50MHz?????è??
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;// ???????? ?????è??
  GPIO_Init(GPIOC, &GPIO_InitStructure);//????A????

int fputc(int ch, FILE *f)
{

   USART_SendData(UART4, (u8) ch);
 
   /* ???·???±???????á?? */
   while(USART_GetFlagStatus(UART4, USART_FLAG_TC) == RESET) //????
   {
   }
   return ch;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。