stm32f103RCT6 串口4,串口5 不能正常使用

2019-10-14 23:20发布

原子大哥,借贵地 一用,我的串口4,串口5 初始化如下
void uart4_init(u32 pclk1,u32 bound) //PC10---tx,PC11--rx

{   
 float temp;
 u16 mantissa;
 u16 fraction;   
 temp=(float)(pclk1*1000000)/(bound*16);//
 mantissa=temp;     
 fraction=(temp-mantissa)*16; //??????????·? 
  mantissa<<=4;
 mantissa+=fraction;
 
 //RCC->APB2ENR|=1<<5;    //????PORTd?±??
 RCC->APB2ENR|=1<<4;    //????PORTc?±??  RCC->APB1ENR|=1<<19;  //????????4?±??    19??  UART4EN??UART4?±?????? (UART 4 clock enable)
 GPIOC->CRH&=0XFFFF00FF; //??????
  GPIOC->CRH|=0X00008B00; //PC11?????????ì????,PC10??????????
    
 RCC->APB1RSTR|=1<<19;   //????????5
 RCC->APB1RSTR&=~(1<<19);//????????
        
 //?¨?????è??
  UART4->BRR=mantissa; // ?¨?????è?? 
 UART4->CR1|=0X200C;  //1??????,?????é??.
 UART4->CR1|=1<<8;    //PE???????
 UART4->CR1|=1<<5;    //??????????·???????????    
 
 MY_NVIC_Init(3,3,UART4_IRQChannel,2);//????????????3 ?ì??????????3 ×é2??×????????? } void uart5_init(u32 pclk1,u32 bound) //PC12--tx,PD2---rx
//???? 2??3??4??5 ??pclk1 36m  ?÷??????uart_init5 (36,9600);    //9600?¨????pclk1 =36m
{   
 float temp;
 u16 mantissa;
 u16 fraction;   
 temp=(float)(pclk1*1000000)/(bound*16);//????USARTDIV
 mantissa=temp;     //??????????·?
 fraction=(temp-mantissa)*16; //??????????·? 
    mantissa<<=4;
 mantissa+=fraction;  RCC->APB2ENR|=1<<5;    //????PORTd?±??
 RCC->APB2ENR|=1<<4;    //????PORTc?±??  RCC->APB1ENR|=1<<20;  //????????5?±??    20??  UART5EN??UART5?±?????? (UART 5 clock enable)
 
 GPIOC->CRH&=0XFFF0FFFF; //??????//PC12--tx,PD2---rx
 GPIOD->CRL&=0XFFFFF0FF;
 
  GPIOC->CRH|=0X00080000; //PB11?????????ì????,PB10??????????
 GPIOD->CRL|=0x00000B00;  
 RCC->APB1RSTR|=1<<20;   //????????5
 RCC->APB1RSTR&=~(1<<20);//????????
        
 //?¨?????è??
  UART5->BRR=mantissa; // ?¨?????è?? 
 UART5->CR1|=0X200C;  //1??????,?????é??.
 UART5->CR1|=1<<8;    //PE????????
 UART5->CR1|=1<<5;    //??????????·???????????      
 MY_NVIC_Init(3,3,UART5_IRQChannel,1);//????????????3 ?ì??????????3 ×é2??×????????? }
打印函数如下:
void UART4_SendByte(unsigned char data)
{
  UART4->SR;
 UART4->DR=data;
 while((UART4->SR&0X40)==0);//????·????á?? } void UART4_SendStr(unsigned char const *str)
{
   while(1)
   {
  if( *str == '' ) break;
      UART4_SendByte(*str++);        //·???????
   } } void UART5_SendByte(unsigned char data)
{
  UART5->SR;
 UART5->DR=data;
 while((UART5->SR&0X40)==0);//????·????á?? } void UART5_SendStr(unsigned char const *str)
{
   while(1)
   {
  if( *str == '' ) break;
      UART4_SendByte(*str++);        //·???????
   } }
就是没出来 打印,串口1,2,3都有的。是不是 跟 那个映射有关的?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。