你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

哪位大侠用过F103ZE的UART4或者5啊,总是调不通

[复制链接]
nuqililove 提问时间:2014-4-13 17:28 /
代码如下,用的串口5
上电后自己先发一个0x55出去,以后收到数据回一个0xAA
void GPIO_Configuration(void)
{
          RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO, ENABLE);        
          RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5,ENABLE);       
        //TX
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
         GPIO_Init(GPIOC, &GPIO_InitStructure);
 
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2; //管脚位置定义
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; //浮空输入 IN_FLOATING 
        GPIO_Init(GPIOD,&GPIO_InitStructure); //C组GPIO初始化
}
 
void NVIC_Configuration(void)
{
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);//1 也试过了
        NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn; //通道设置为串口1中断
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //中断响应优先级
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //打开中断
        NVIC_Init(&NVIC_InitStructure); //初始化
}
 
void UART5_Init(void)
{
        USART_InitStructure.USART_BaudRate = 9600; //波特率9600
        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; //打开Rx接收和Tx发送功能
        USART_Init(UART5, &USART_InitStructure); //初始化
 
        USART_ClearFlag(UART5, USART_FLAG_RXNE); // 清标志       
        USART_ITConfig(UART5, USART_IT_RXNE, ENABLE); // 若接收数据寄存器满,则产生中断
        // USART_ITConfig(UART5, USART_IT_TXE, ENABLE);
 
        USART_Cmd(UART5, ENABLE); //启动串口       
       
}
 
 
 
void UART5_IRQHandler(void)
{
  if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET)
  {       
           while (!(UART5->SR & USART_FLAG_RXNE));
       UART5->DR = (0XAA & (uint16_t)0x01FF); 
 
    USART_ITConfig(UART5, USART_IT_TXE, DISABLE);       
       

  }
  
  if(USART_GetITStatus(UART5, USART_IT_TXE) != RESET)
  {   
           while (!(UART5->SR & USART_FLAG_TXE));
       UART5->DR = (0X55 & (uint16_t)0x01FF); 
 
    USART_ITConfig(UART5, USART_IT_TXE, DISABLE);       
       
  }       
}

main函数就比较简单了
        GPIO_Configuration();
        NVIC_Configuration();
        UART5_Init();
 
        USART_ITConfig(UART5, USART_IT_TXE, ENABLE);
        while(1);
收藏 评论16 发布时间:2014-4-13 17:28

举报

16个回答
nuqililove 回答时间:2014-4-13 17:29:52

回复:哪位大侠用过F103ZE的UART4或者5啊,总是调不通

RCC_APB2Periph_AFIO开不开都不行
那片清茶 回答时间:2014-4-14 08:20:26

RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通

中断会不会进来?
dzc2001 回答时间:2014-4-14 08:39:14

RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通

有没有从网上找个现成的代码试试
buxinshan 回答时间:2014-4-14 09:00:26

RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通

你先实现普通模式的串口发送和接收,先别使用中断。
我这有UART4和UART5的
//==========  我是分隔符  =========
#include "stm32f10x.h"

/*******************************************************************************
* Function Name  : USART_Configuration
* Description    : Configure UART4
* Input          : None
* Output         : None
* Return         : None
* Attention                 : None
*******************************************************************************/
void UART4_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  USART_InitTypeDef USART_InitStructure;
  RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC ,ENABLE);
        RCC_APB1PeriphClockCmd( RCC_APB1Periph_UART4 ,ENABLE);
       
  /*
  *  UART4_TX -> PC10 , UART4_RX ->        PC11
  */                               
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;                
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOC, &GPIO_InitStructure);                  
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;                
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;  
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  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(UART4, &USART_InitStructure);
  USART_ClearFlag(UART4,USART_FLAG_TC);
  //USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
  USART_Cmd(UART4, ENABLE);
}
/*----------------------------------------------------------------------------
*       sendchar:  Write a character to Serial Port
*---------------------------------------------------------------------------*/
int sendchar (int ch) {
  if (ch == '\n')  {
    while (!(UART4->SR & 0x0080));
    UART4->DR = 0x0D;
  }
  while (!(UART4->SR & 0x0080));
  UART4->DR = (ch & 0xFF);
  return (ch);
}
/*----------------------------------------------------------------------------
*       getkey:  Read a character from Serial Port
*---------------------------------------------------------------------------*/
int getkey (void) {
  while (!(UART4->SR & 0x0020));
  return (UART4->DR);
}

//==========  我是分隔符  =========
/*******************************************************************************
* Function Name  : USART_Configuration
* Description    : Configure UART5
* Input          : None
* Output         : None
* Return         : None
* Attention                 : None
*******************************************************************************/
void UART5_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  USART_InitTypeDef USART_InitStructure;
  RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD ,ENABLE);
        RCC_APB1PeriphClockCmd( RCC_APB1Periph_UART5 ,ENABLE);
       
  /*
  *  UART5_TX -> PC12 , UART5_RX ->        PD2
  */                               
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;                
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOC, &GPIO_InitStructure);                  
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;                
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;  
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOD, &GPIO_InitStructure);
  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(UART5, &USART_InitStructure);
  USART_ClearFlag(UART5,USART_FLAG_TC);
  //USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
  USART_Cmd(UART5, ENABLE);
}
有缘于你 回答时间:2014-4-14 10:45:02

RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通

void UART5_IRQHandler(void)
{
  if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET)
  {       
           while (!(UART5->SR & USART_FLAG_RXNE));
       UART5->DR = (0XAA & (uint16_t)0x01FF);

    USART_ITConfig(UART5, USART_IT_TXE, DISABLE);      
       
  }
  
  if(USART_GetITStatus(UART5, USART_IT_TXE) != RESET)
  {   
           while (!(UART5->SR & USART_FLAG_TXE));
       UART5->DR = (0X55 & (uint16_t)0x01FF);

    USART_ITConfig(UART5, USART_IT_TXE, DISABLE);      
       
  }       
}
USART_ITConfig(UART5, USART_IT_TXE, DISABLE); 禁用了中断...而且没有清除接收中断标志吧
Eagleson 回答时间:2014-4-14 14:01:13

RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通

http://www.openedv.com/posts/list/0/526.htm?fromAll=0
原子哥的例子
nuqililove 回答时间:2014-4-14 21:58:58

回复:哪位大侠用过F103ZE的UART4或者5啊,总是调不通

回复第 3 楼 于2014-04-14 08:20:26发表:
中断会不会进来?
 
可以进发送中断,但是UART5->DR(寄存器0x4000 5004)的数据没有 变化
 
nuqililove 回答时间:2014-4-14 22:00:40

回复:哪位大侠用过F103ZE的UART4或者5啊,总是调不通

回复第 5 楼 于2014-04-14 09:00:26发表:
你先实现普通模式的串口发送和接收,先别使用中断。
我这有UART4和UART5的
//==========  我是分隔符  =========
#include "stm32f10x.h"

/*******************************************************************************
* Function Name  : USART_Configuration
* Description    : Configure UART4
* Input          : None
* Output         : None
* Return         : None
* Attention                 : None
*******************************************************************************/
void UART4_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC ,ENABLE);
RCC_APB1PeriphClockCmd( RCC_APB1Periph_UART4 ,ENABLE);

/*
*  UART4_TX -> PC10 , UART4_RX ->        PC11
*/                               
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;                
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);                  
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;                
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;  
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
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(UART4, &USART_InitStructure);
USART_ClearFlag(UART4,USART_FLAG_TC);
//USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
USART_Cmd(UART4, ENABLE);
}
/*----------------------------------------------------------------------------
*       sendchar:  Write a character to Serial Port
*---------------------------------------------------------------------------*/
int sendchar (int ch) {
if (ch == '\n')  {
while (!(UART4->SR & 0x0080));
UART4->DR = 0x0D;
}
while (!(UART4->SR & 0x0080));
UART4->DR = (ch & 0xFF);
return (ch);
}
/*----------------------------------------------------------------------------
*       getkey:  Read a character from Serial Port
*---------------------------------------------------------------------------*/
int getkey (void) {
while (!(UART4->SR & 0x0020));
return (UART4->DR);
}

//==========  我是分隔符  =========
/*******************************************************************************
* Function Name  : USART_Configuration
* Description    : Configure UART5
* Input          : None
* Output         : None
* Return         : None
* Attention                 : None
*******************************************************************************/
void UART5_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD ,ENABLE);
RCC_APB1PeriphClockCmd( RCC_APB1Periph_UART5 ,ENABLE);

/*
*  UART5_TX -> PC12 , UART5_RX ->        PD2
*/                               
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;                
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);                  
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;                
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;  
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
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(UART5, &USART_InitStructure);
USART_ClearFlag(UART5,USART_FLAG_TC);
//USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
USART_Cmd(UART5, ENABLE);
}
 
 
用你的试了,直接不停发数据,电脑的串口助手 也没有数据啊
 
nuqililove 回答时间:2014-4-14 23:40:40

回复:哪位大侠用过F103ZE的UART4或者5啊,总是调不通

 附上电路图
未命名.JPG
nuqililove 回答时间:2014-4-17 21:41:33

RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通

对上帝说不 回答时间:2014-4-18 08:56:19

回复:哪位大侠用过F103ZE的UART4或者5啊,总是调不通

还没有调通吗?反正我用F103RC串口1~5是全通的
dlyt03 回答时间:2014-4-18 09:45:48

RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通

换个例程调试看看
zergl 回答时间:2014-4-18 10:35:57

RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通

这是我目前使用的,5个口都用到,请参考.

/****************************************
* ÎļþÃû  £ºusart.c
        | PA9  - USART1(Tx)   |
        | PA10 - USART1(Rx)   |
       
        | PA2  - USART2(Tx)   |
        | PA3  - USART2(Rx)   |
       
        | PB10  - USART3(Tx)   |
        | PB11  - USART3(Rx)   |
       
        | PC10  - USART4(Tx)   |
        | PC11  - USART4(Rx)   |
       
        | PC12  - USART5(Tx)   |
        | PD2   - USART5(Rx)   |
**********************************************************************************/
#include "usart.h"
#include "plc.h"
#include
#include
USART_InitTypeDef USART_InitStructure;
void GPIO_Tx_Usart1_Config(GPIOMode_TypeDef GPIOMode)
{
          GPIO_InitTypeDef  GPIO_InitStructure;
          /* Configure USART1 Tx (PA.09) as alternate function push-pull */
          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
          GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
          GPIO_InitStructure.GPIO_Mode = GPIOMode;
          GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void GPIO_Tx_Usart2_Config(GPIOMode_TypeDef GPIOMode)
{
          GPIO_InitTypeDef  GPIO_InitStructure;
  
                /* Configure USART2 Tx (PA.02) as alternate function push-pull */
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
                GPIO_InitStructure.GPIO_Mode = GPIOMode;
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
                GPIO_Init(GPIOA, &GPIO_InitStructure);  
}
void GPIO_Tx_Usart3_Config(GPIOMode_TypeDef GPIOMode)
{
          GPIO_InitTypeDef  GPIO_InitStructure;
          /* Configure USART4 Tx (PB.10) as alternate function push-pull */
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
                GPIO_InitStructure.GPIO_Mode = GPIOMode;
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
                GPIO_Init(GPIOB, &GPIO_InitStructure);
  
}
void GPIO_Tx_Usart4_Config(GPIOMode_TypeDef GPIOMode)
{
          GPIO_InitTypeDef  GPIO_InitStructure;
          /* Configure USART4 Tx (PC.10) as alternate function push-pull */
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
                GPIO_InitStructure.GPIO_Mode = GPIOMode;
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
                GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void GPIO_Tx_Usart5_Config(GPIOMode_TypeDef GPIOMode)
{
          GPIO_InitTypeDef  GPIO_InitStructure;
          /* Configure USART5 Tx (PC.12) as alternate function push-pull */
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
                GPIO_InitStructure.GPIO_Mode = GPIOMode;
                GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
                GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void USART_Config(void)
{
                /* USART mode config */
                USART_InitStructure.USART_BaudRate = 250000;                 //ÅäÖÃUSART1µÄ²¨ÌØÂÊ
                USART_InitStructure.USART_WordLength = USART_WordLength_8b;                         //USART½ÓÊÕ»òÕß´«Êä8λÊý¾Ý
                USART_InitStructure.USART_StopBits = USART_StopBits_1;                                 //USART·¢Ë͵ÄֹͣλΪ1λ
                USART_InitStructure.USART_Parity = USART_Parity_No ;                                 //¶¨ÒåUSARTµÄÆæÅ¼Ð£ÑéλΪÎÞ
                USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;          //¶¨ÒåUSARTµÄÓ²¼þÁ÷¿ØÄ£Ê½µÄRTSºÍCTSʹÄÜ
                USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;                                          //ʹÄÜ·¢ËͺͽÓÊÕģʽ
}
/*
* º¯ÊýÃû£ºUART_NVIC_Configuration
* ÃèÊö  £ºUARTÖжÏÓÅÏȼ¶ÅäÖÃ
*/
void Uart_NVIC_Configuration(USART_TypeDef* USARTx)
{
                NVIC_InitTypeDef NVIC_InitStructure;
                NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);                  //ÉèÖÃÓÅÏȼ¶·Ö×é                                                                                       
   
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;                //ÇÀÕ¼ÓÅÏȼ¶Îª×î¸ß0   
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;                                //ÏìÓ¦ÓÅÏȼ¶Îª×î¸ß0
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;                                    //ͨµÀʹÄÜ
                switch (*(uint32_t*)&USARTx)
                        {
                                case USART1_BASE:
                                                NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;          
                                                NVIC_Init(&NVIC_InitStructure);
                                                break;
                                case USART2_BASE:
                                                NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;       
                                                NVIC_Init(&NVIC_InitStructure);
                                                break;
                                case USART3_BASE:
                                                NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;       
                                                NVIC_Init(&NVIC_InitStructure);
                                                break;
                                case UART4_BASE:
                                                NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
                                                NVIC_Init(&NVIC_InitStructure);
                                                break;
                                case UART5_BASE:
                                                NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn;
                                                NVIC_Init(&NVIC_InitStructure);
                                                break;            
                                default:
                                                break;
                        }   
}
/*
* º¯ÊýÃû£ºUSART1_Config
* ÃèÊö  £ºUSART1 GPIO ÅäÖÃ,¹¤×÷ģʽÅäÖÃ
| PA9  - USART1(Tx)   |
| PA10 - USART1(Rx)   |
*/
void USART1_Config(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
       
        /* config USART1 clock */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
       
        /* Configure USART1 Tx (PA.09) as alternate function push-pull */
        GPIO_Tx_Usart1_Config(GPIO_Mode_AF_PP);
            
        /* Configure USART1 Rx (PA.10) as input floating */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
        USART_Config();
        USART_Init(USART1, &USART_InitStructure);
        USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
        USART_Cmd(USART1, ENABLE);
        Uart_NVIC_Configuration(USART1);
}

/*
* º¯ÊýÃû£ºUSART2_Config
* ÃèÊö  £ºUSART2 GPIO ÅäÖÃ,¹¤×÷ģʽÅäÖÃ
| PA2  - USART2(Tx)   |
| PA3  - USART2(Rx)   |
*/
void USART2_Config(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
       
        /* config USART2 clock */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
       
        /* Configure USART2 Tx (PA.02) as alternate function push-pull */
        GPIO_Tx_Usart2_Config(GPIO_Mode_AF_PP);
            
        /* Configure USART2 Rx (PA.03) as input floating */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
          
        USART_Config();
       
        USART_Init(USART2, &USART_InitStructure);
        USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
        USART_Cmd(USART2, ENABLE);
        Uart_NVIC_Configuration(USART2);
}
/*
* º¯ÊýÃû£ºUSART3_Config
* ÃèÊö  £ºUSART3 GPIO ÅäÖÃ,¹¤×÷ģʽÅäÖÃ
        | PB10  - USART3(Tx)   |
        | PB11  - USART3(Rx)   |
*/
void USART3_Config(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
       
        /* config USART3 clock */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
       
        /* Configure USART2 Tx (PB.10) as alternate function push-pull */
        GPIO_Tx_Usart3_Config(GPIO_Mode_AF_PP);
            
        /* Configure USART2 Rx (PB.11) as input floating */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
          
        USART_Config();
       
        USART_Init(USART3, &USART_InitStructure);
        USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
        USART_Cmd(USART3, ENABLE);
        Uart_NVIC_Configuration(USART3);
}
/*
* º¯ÊýÃû£ºUSART4_Config
* ÃèÊö  £ºUSART4 GPIO ÅäÖÃ,¹¤×÷ģʽÅäÖÃ
        | PC10  - USART4(Tx)   |
        | PC11  - USART4(Rx)   |
*/
void USART4_Config(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
       
        /* config USART4 clock */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
       
        /* Configure USART4 Tx (PC.10) as alternate function push-pull */
        GPIO_Tx_Usart4_Config(GPIO_Mode_AF_PP);
            
        /* Configure USART2 Rx (PC.11) as input floating */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOC, &GPIO_InitStructure);
          
        USART_Config();
       
        USART_Init(UART4, &USART_InitStructure);
        USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
        USART_Cmd(UART4, ENABLE);
        Uart_NVIC_Configuration(UART4);
}
/*
* º¯ÊýÃû£ºUSART5_Config
* ÃèÊö  £ºUSART5 GPIO ÅäÖÃ,¹¤×÷ģʽÅäÖÃ
| PC12  - USART5(Tx)   |
| PD2   - USART5(Rx)   |
*/
void USART5_Config(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
       
        /* config USART3 clock */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
       
        /* Configure USART5 Tx (PC.12) as alternate function push-pull */
        GPIO_Tx_Usart5_Config(GPIO_Mode_AF_PP);
            
        /* Configure USART5 Rx (PD.02) as input floating */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOD, &GPIO_InitStructure);
          
        USART_Config();
       
        USART_Init(UART5, &USART_InitStructure);
        USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
        USART_Cmd(UART5, ENABLE);
        Uart_NVIC_Configuration(UART5);
}
wkuang 回答时间:2014-4-18 23:03:07

RE:哪位大侠用过F103ZE的UART4或者5啊,总是调不通

建议直接配寄存器,用查询的方式,把需要配置的管教映射,时钟什么的通通重新配置一次。
中断的话等查询方式调试通过了再试试
12下一页

所属标签

相似问题

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版