OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 5624|回复: 1

USART3 发送不出去,接受的时候也不进中断

[复制链接]

10

主题

40

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
346
金钱
346
注册时间
2013-12-20
在线时间
94 小时
发表于 2014-7-10 09:35:07 | 显示全部楼层 |阅读模式
5金钱
在USART3上面实验个自发自收的程序,都不通,有什么地方配置不对吗
//********************************************************************************  
void uart_init(void)
{
GPIO_InitTypeDef   GPIO_InitStructure;
USART_InitTypeDef  UART_InitStructure;
NVIC_InitTypeDef   NVIC_InitStructure;

// activate UART3
USART_DeInit(USART3);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

// activate GPIOB (UART3-Pins)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

// assign UART3-Pins (PB10 and PB11)
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_10;
GPIO_Init(GPIOB, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_11;
GPIO_Init(GPIOB, &GPIO_InitStructure);

// configure UART3
UART_InitStructure.USART_BaudRate            = 9600;
UART_InitStructure.USART_WordLength          = USART_WordLength_8b;
UART_InitStructure.USART_StopBits            = USART_StopBits_1;
UART_InitStructure.USART_Parity              = USART_Parity_No ;
    UART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
UART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;  
USART_Init(USART3, &UART_InitStructure);

// activate s32errupt for UART3
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);

USART_Cmd(USART3, ENABLE);

USART_SendData(USART3, 0x12) ;        //test
}

//********************************************************************************  
void USART3_IRQHandler(void)
{
u8 Res;
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET) 
{
Res =USART_ReceiveData(USART3);
USART_SendData(USART3, Res);
}
}

最佳答案

查看完整内容[请看2#楼]

我的 UART3 用到PORTC PIN-10 PIN-11 , 若你是用到 PORTB ? 可能要更改腳位切換的功能 我是使用 F207 不過都大同小異 void debug_port_init(void){       USART_InitTypeDef USART_InitStructure;     GPIO_InitTypeDef GPIO_InitStructure;     /* USARTx configured as follow:         - BaudRate = 115200 baud   &nbs ...
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

19

主题

234

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
362
金钱
362
注册时间
2014-7-8
在线时间
10 小时
发表于 2014-7-10 09:35:08 | 显示全部楼层
我的 UART3 用到PORTC PIN-10 PIN-11 , 若你是用到 PORTB ? 可能要更改腳位切換的功能

我是使用 F207 不過都大同小異

void debug_port_init(void){
      USART_InitTypeDef USART_InitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;
    /* USARTx configured as follow:
        - BaudRate = 115200 baud  
        - Word Length = 8 Bits
        - One Stop Bit
        - No parity
        - Hardware flow control disabled (RTS and CTS signals)
        - Receive and transmit enabled
      */
    //
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
      /* Connect PXx to USARTx_Tx*/
      GPIO_PinAFConfig(GPIOC, GPIO_PinSource10,GPIO_AF_USART3);
      /* Connect PXx to USARTx_Rx*/
      GPIO_PinAFConfig(GPIOC, GPIO_PinSource11,GPIO_AF_USART3);    
      /* Configure USART Tx as alternate function  */
      GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
      GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
      GPIO_Init(GPIOC, &GPIO_InitStructure);

      /* Configure USART Rx as alternate function  */
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
      GPIO_Init(GPIOC, &GPIO_InitStructure);

      USART_InitStructure.USART_BaudRate = 19200;
      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 configuration */
     USART_Init(USART3, &USART_InitStructure);
    
      /* Enable USART */
      USART_Cmd(USART3, ENABLE);    
    debug("\r\n\r\n");
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-7-6 07:33

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表